Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Printrun
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
machinery
Printrun
Commits
3eee6f47
Commit
3eee6f47
authored
Feb 11, 2017
by
Stefy Lanza (nextime / spora )
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SerialWrapper
parent
90de73bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
serialWrapper.py
printrun/serialWrapper.py
+49
-0
No files found.
printrun/serialWrapper.py
0 → 100644
View file @
3eee6f47
# Serial wrapper around pyserial that adds support for custom baudrates (250000)
# on linux, when pyserial is < 2.7
# This code was copied from the pyserial 2.7 base code.
# Therefore, it follows the license used by pyserial which is the '3-clause BSD license'
from
serial
import
*
import
sys
if
sys
.
platform
.
startswith
(
'linux'
):
import
serial.serialposix
try
:
import
pkg_resources
old_version
=
float
(
pkg_resources
.
get_distribution
(
"pyserial"
)
.
version
)
<
2.7
except
:
old_version
=
True
if
old_version
and
not
hasattr
(
serial
.
serialposix
,
"TCGETS2"
)
and
\
hasattr
(
serial
.
serialposix
,
"set_special_baudrate"
):
# Detected pyserial < 2.7 which doesn't support custom baudrates
# Replacing set_special_baudrate with updated function from pyserial 2.7
TCGETS2
=
0x802C542A
TCSETS2
=
0x402C542B
BOTHER
=
0o010000
def
set_special_baudrate
(
port
,
baudrate
):
# right size is 44 on x86_64, allow for some growth
import
array
buf
=
array
.
array
(
'i'
,
[
0
]
*
64
)
try
:
# get serial_struct
FCNTL
.
ioctl
(
port
.
fd
,
TCGETS2
,
buf
)
# set custom speed
buf
[
2
]
&=
~
TERMIOS
.
CBAUD
buf
[
2
]
|=
BOTHER
buf
[
9
]
=
buf
[
10
]
=
baudrate
# set serial_struct
res
=
FCNTL
.
ioctl
(
port
.
fd
,
TCSETS2
,
buf
)
except
IOError
,
e
:
raise
ValueError
(
'Failed to set custom baud rate (
%
s):
%
s'
%
(
baudrate
,
e
))
# We need to change the function inside the serialposix module otherwise, it won't
# be called by the code within that module
serial
.
serialposix
.
set_special_baudrate
=
set_special_baudrate
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment