-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Configurable serial #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,46 @@ | ||
import serial | ||
import time | ||
import usb | ||
try: import usb | ||
except: pass | ||
|
||
from alphasign.interfaces import base | ||
|
||
|
||
class Serial(base.BaseInterface): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please readd blank line. |
||
"""Connect to a sign through a local serial device. | ||
|
||
This class uses `pySerial <http://pyserial.sourceforge.net/>`_. | ||
""" | ||
def __init__(self, device="/dev/ttyS0"): | ||
def __init__(self, device="/dev/ttyS0", baudrate=4800, | ||
bytesize=8, parity='E', stopbits=2, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert these to their proper constant names ( See: http://pyserial.sourceforge.net/pyserial_api.html#constants |
||
xonxoff=False, rtscts=False, timeout=1, | ||
debug=True): | ||
""" | ||
:param device: character device (default: /dev/ttyS0) | ||
:type device: string | ||
:param debug: loudly show bytes going across the wire | ||
:type device: boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
All other parameters are as per serial.Serial() They are passed | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put a period after |
||
through as much as possible while leaving the defaults set as they | ||
are to avoid breaking existing code using the library. | ||
|
||
Unfortunately, the defaults as they stand won't work with some | ||
devices. | ||
|
||
Changing the hardware flow control isn't a good idea as many | ||
of the alphasign devices don't have pins for it on RS232 port. | ||
""" | ||
self.device = device | ||
self.debug = True | ||
self._conn = None | ||
|
||
self.device = device | ||
self.debug = debug | ||
self.serialargs = dict(port=device, baudrate=baudrate, bytesize=bytesize, | ||
parity=parity, stopbits=stopbits, xonxoff=xonxoff, | ||
rtscts=rtscts, timeout=timeout) | ||
|
||
def connect(self): | ||
"""Establish connection to the device. | ||
""" | ||
# TODO(ms): these settings can probably be tweaked and still support most of | ||
# the devices. | ||
self._conn = serial.Serial(port=self.device, | ||
baudrate=4800, | ||
parity=serial.PARITY_EVEN, | ||
stopbits=serial.STOPBITS_TWO, | ||
timeout=1, | ||
xonxoff=0, | ||
rtscts=0) | ||
self._conn = serial.Serial(**self.serialargs) | ||
|
||
def disconnect(self): | ||
"""Disconnect from the device. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rewrite as: