Permalink
Browse files

driver/serialdriver: support for remote serial ports over raw-tcp.

Signed-off-by: Johannes Nau <johannes.nau@jumo.net>
[r.czerwinki@pengutronix.de: squashed fix commit, fixed commit message]
Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
  • Loading branch information...
jonau authored and Emantor committed Sep 14, 2017
1 parent 7538263 commit 6bd18695465f5ce7b1fc80414e959e8c178fc2bc
Showing with 21 additions and 7 deletions.
  1. +3 −2 doc/configuration.rst
  2. +12 −2 labgrid/driver/serialdriver.py
  3. +6 −3 labgrid/resource/serialport.py
View
@@ -44,7 +44,7 @@ Used by:
NetworkSerialPort
+++++++++++++++++
A NetworkSerialPort describes a serial port which is exported over the network,
usually using RFC2217.
usually using RFC2217 or raw tcp.
.. code-block:: yaml
@@ -54,11 +54,12 @@ usually using RFC2217.
speed: 115200
The example would access the serial port on computer remote.example.computer via
port 53867 and use a baud rate of 115200.
port 53867 and use a baud rate of 115200 with the RFC2217 protocol.
- host (str): hostname of the remote host
- port (str): TCP port on the remote host to connect to
- speed (int): baud rate of the serial port
- protocol (str): prtocol used for connection: raw or rfc2217
Used by:
- `SerialDriver`_
@@ -33,15 +33,25 @@ def __attrs_post_init__(self):
if isinstance(self.port, SerialPort):
self.serial = serial.Serial()
else:
self.serial = serial.rfc2217.Serial()
if self.port.protocol == "rfc2217":
self.serial = serial.rfc2217.Serial()
elif self.port.protocol == "raw":
self.serial = serial.serial_for_url("socket://", do_not_open=True)
else:
raise Exception("SerialDriver: unknown protocol")
self.status = 0
def on_activate(self):
if isinstance(self.port, SerialPort):
self.serial.port = self.port.port
self.serial.baudrate = self.port.speed
else:
self.serial.port = "rfc2217://{}:{}/".format(self.port.host, self.port.port)
if self.port.protocol == "rfc2217":
self.serial.port = "rfc2217://{}:{}/".format(self.port.host, self.port.port)
elif self.port.protocol == "raw":
self.serial.port = "socket://{}:{}/".format(self.port.host, self.port.port)
else:
raise Exception("SerialDriver: unknown protocol")
self.serial.baudrate = self.port.speed
self.open()
@@ -19,10 +19,13 @@ def __attrs_post_init__(self):
@attr.s(cmp=False)
class NetworkSerialPort(NetworkResource):
"""A NetworkSerialPort is a remotely accessable serialport, usually
accessed via rfc2217.
accessed via rfc2217 or tcp raw.
Args:
port (str): connection string to the port e.g. 'rfc2217://<host>:<port>'
speed (int): speed of the port e.g. 9800"""
port (str): socket port to connect to
speed (int): speed of the port e.g. 9800
protocol (str): connection protocol: "raw" or "rfc2217"
"""
port = attr.ib(validator=attr.validators.optional(attr.validators.instance_of(int)))
speed = attr.ib(default=115200, validator=attr.validators.instance_of(int))
protocol = attr.ib(default="rfc2217", validator=attr.validators.instance_of(str))

0 comments on commit 6bd1869

Please sign in to comment.