Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python-mqtt-gpio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Alexander Wellbrock
python-mqtt-gpio
Commits
fa75c3f2
Commit
fa75c3f2
authored
5 years ago
by
ChrisEAlfred
Browse files
Options
Downloads
Patches
Plain Diff
Added bytesize,parity,stopbits parameters
parent
696ea3bd
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+3
-0
3 additions, 0 deletions
README.md
pi_mqtt_gpio/modules/streamserial.py
+38
-1
38 additions, 1 deletion
pi_mqtt_gpio/modules/streamserial.py
with
41 additions
and
1 deletion
README.md
+
3
−
0
View file @
fa75c3f2
...
...
@@ -189,6 +189,9 @@ stream_modules:
module
:
streamserial
device
:
/dev/ttyS0
baud
:
115200
bytesize
:
8
# Number of data bits in word. Can be: 5,6,7,8
parity
:
none
# Parity can be one of none,odd,even,mark,space
stopbits
:
1
# Number of stop bits. Can be: 1,1.5,2
cleanup
:
no
# This optional boolean value sets whether the module's `cleanup()` function will be called when the software exits.
stream_reads
:
...
...
This diff is collapsed.
Click to expand it.
pi_mqtt_gpio/modules/streamserial.py
+
38
−
1
View file @
fa75c3f2
from
__future__
import
print_function
from
pi_mqtt_gpio.modules
import
GenericStream
import
serial
from
serial
import
Serial
REQUIREMENTS
=
(
"
serial
"
,)
CONFIG_SCHEMA
=
{
"
device
"
:
{
"
type
"
:
"
string
"
,
"
required
"
:
True
,
"
empty
"
:
False
},
"
baud
"
:
{
"
type
"
:
"
integer
"
,
"
required
"
:
True
,
"
empty
"
:
False
},
"
bytesize
"
:
{
"
type
"
:
"
integer
"
,
"
required
"
:
True
,
"
empty
"
:
False
},
"
parity
"
:
{
"
type
"
:
"
string
"
,
"
required
"
:
True
,
"
empty
"
:
False
},
"
stopbits
"
:
{
"
type
"
:
"
float
"
,
"
required
"
:
True
,
"
empty
"
:
False
},
}
PORTS_USED
=
{}
BYTESIZE
=
{
5
:
serial
.
FIVEBITS
,
6
:
serial
.
SIXBITS
,
7
:
serial
.
SEVENBITS
,
8
:
serial
.
EIGHTBITS
}
PARITY
=
{
"
none
"
:
serial
.
PARITY_NONE
,
"
odd
"
:
serial
.
PARITY_ODD
,
"
even
"
:
serial
.
PARITY_EVEN
,
"
mark
"
:
serial
.
PARITY_MARK
,
"
space
"
:
serial
.
PARITY_SPACE
}
STOPBITS
=
{
1
:
serial
.
STOPBITS_ONE
,
1.5
:
serial
.
STOPBITS_ONE_POINT_FIVE
,
2
:
serial
.
STOPBITS_TWO
}
class
Stream
(
GenericStream
):
"""
Implementation of stream class for outputting to STDIO.
...
...
@@ -20,7 +45,19 @@ class Stream(GenericStream):
global
PORTS_USED
#print("__init__(config=%r)" % config)
if
not
config
[
'
device
'
]
in
PORTS_USED
:
self
.
ser
=
Serial
(
config
[
'
device
'
],
config
[
'
baud
'
],
timeout
=
20
)
if
not
config
[
'
bytesize
'
]
in
BYTESIZE
.
keys
():
raise
Exception
(
"
bytesize not one of:
"
+
str
(
BYTESIZE
.
keys
()))
if
not
config
[
'
parity
'
]
in
PARITY
.
keys
():
raise
Exception
(
"
parity not one of:
"
+
str
(
PARITY
.
keys
()))
if
not
config
[
'
stopbits
'
]
in
STOPBITS
.
keys
():
raise
Exception
(
"
stopbits not one of:
"
+
str
(
STOPBITS
.
keys
()))
bytesize
=
BYTESIZE
[
config
[
'
bytesize
'
]]
parity
=
PARITY
[
config
[
'
parity
'
]]
stopbits
=
STOPBITS
[
config
[
'
stopbits
'
]]
self
.
ser
=
Serial
(
port
=
config
[
'
device
'
],
baudrate
=
config
[
'
baud
'
],
bytesize
=
bytesize
,
parity
=
parity
,
stopbits
=
stopbits
,
timeout
=
20
)
self
.
ser
.
flushInput
()
PORTS_USED
[
config
[
'
device
'
]]
=
self
.
ser
else
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment