Node Communication

exception openlcb.communication.CommunicationException

Raised if an error occurs while communicating with a node

class openlcb.communication.EthernetConnection(hostname, port)

Class for communicating with nodes via Eth2CAN

Parameters:
  • hostname (str) – Host name or IP address of the Eth2CAN device
  • port (int) – TCP port of the Eth2CAN device
close()

Close the TCP/IP communication socket

connect()

Connect to the Eth2CAN device over TCP/IP

receive_multi(timeout=None)

Retreive multiple responses from the OpenLCB bus

send(message)

Send an OpenLCB message over TCP/IP

class openlcb.communication.OpenLCBConnection

Base class for OpenLCB communication mechanisms

Subclasses should define the following methods for communicating with an OpenLCB bus over a given transport:

Instances are also context managers. This facilitates opening and closing of connections using the with statement:

conn = EthernetConnection(hostname)
with conn:
    conn.send(message)

The above example will automatically open and close the connection upon entering and leaving the context.

close()

Close the connection to the OpenLCB bus

connect()

Connect to the OpenLCB bus

receive()

Retreive a response from the OpenLCB bus

Returns str:A string containing the CAN frame received from the bus, suitable for creating a new instance of a CANMessage subclass

Deprecated since version 0.1: This method is ambiguous; use receive_one() instead.

receive_multi()

Retreive multiple responses from the OpenLCB bus

Returns list:A list of strings containing CAN frames, suitable for creating new instances of a subclass of CANMessage. If no response was returned within the timeout period, an empty list (i.e. []) is returned.
receive_one()

Retreive a single response message from the node

Returns str:A string containing the first message received, suitable for creating a new instance of a CANMessage subclass. If no response was received within the timeout period, None is returned.

Note

Calling this method will actually empty the buffer, meaning that if more than one message was received, any subsequent messages will be discarded. If multiple response messages are expected, use receive_multi() instead.

send(message)

Send a message to the OpenLCB bus

Parameters:message (str) – The CAN frame to send

Any object that can be converted to a string can be passed as the message parameter, such as openlcb.can.CANMessage subclasses.

class openlcb.communication.SerialConnection(com_port, speed)

Class for communicating with nodes via Serial Connection

Parameters:
  • com_port (str) – Serial port device name or port number
  • speed (int) – Serial port Baud rate (defaults to 500000)
close()

Close the serial port and terminate the OpenLCB connection

connect()

Open the serial port and set RTS

receive_multi(timeout=None)

Retreive multiple responses from the OpenLCB bus

send(frame)

Send an OpenLCB message through the serial port

Previous topic

OpenLCB Message Representations

This Page