| |
- RepRapSerialComm
- SimplePacket
class RepRapSerialComm |
|
Communication class which handles packetize two-way communication over serial port.
The packet structure is:
Byte 0: Start byte
Byte 1: Length byte
Byte 2..n: Content
Byte n+1: CRC |
|
Methods defined here:
- __del__(self)
- __init__(self, port='/dev/ttyUSB0', baudrate=38400)
- Connect to the device through the specific port and at the specific baudrate.
- close(self)
- Shutdown the connection
- process(self)
- This should be called to receive new packet.
This should be used if the other end could send data actively.
(Normally the microcontroller only responses to command, but never send data on its own)
Returns a SimplePacket if a packet (valid or invalid) is read. Returns None otherwise.
Timeout mechanism will not be force triggered, but a packet with RC_NO_RESPONSE could still be returned if transmission stopped in the middle.
- readback(self)
- This should be called whenever packet is expected. This should be used when response is expected from the other end.
Returns a SimplePacket if a packet (valid or invalid) is read. Returns None otherwise.
A packet with rc == RC_NO_RESPONSE will be returned eventually if response is not completed within timeout 100ms.
- reset(self)
- Reset the state of the bus to a clean state by pumping invalid packets
- send(self, packet)
|
class SimplePacket |
|
Packet structure used in communication.
Numbers are stored in little endianness.
Functions are provided to serialize and deserialize the numbers,
as well as calculating the CRC.
CRC is stored in self.crc, and is updated dynamically when data are appended. |
|
Methods defined here:
- __init__(self)
- Create a new packet
- add_16(self, d)
- Append a 16-bits integer to the end of the packet
- add_32(self, d)
- Append a 32-bits integer to the end of the packet
- add_8(self, d)
- Append a 8-bits integer to the end of the packet
- get_16(self, idx)
- Returns a 16-bits integer from the specific location of packet.
Returns 0 if idx is larger than the length.
- get_32(self, idx)
- Returns a 32-bits integer from the specific location of packet.
Returns 0 if idx is larger than the length.
- get_8(self, idx)
- Returns a 8-bits integer from the specific location of packet.
Returns 0 if idx is larger than the length.
Data and other attributes defined here:
- RC_BUFFER_OVERFLOW = 2
- RC_CMD_UNSUPPORTED = 5
- RC_CRC_MISMATCH = 3
- RC_GENERIC_ERROR = 0
- RC_NO_RESPONSE = 10000
- RC_OK = 1
- RC_PACKET_TOO_BIG = 4
- START_BYTE = 213
| |