Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions alphasign/interfaces/local.py
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

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewrite as:

try:
  import usb
except:
  pass

from alphasign.interfaces import base


class Serial(base.BaseInterface):
Copy link
Owner

Choose a reason for hiding this comment

The 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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert these to their proper constant names (serial.EIGHTBITS, serial.PARITY_EVEN, serial.STOPBITS_TWO).

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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:type debug:


All other parameters are as per serial.Serial() They are passed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a period after serial.Serial().

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.
Expand Down