All ConnectWare data link layer frames transmitted over any of the three serial interfaces by either the CWM or OKE will be in the following format:
Field | SOF | CMD | TID | LEN | PAYLOAD | CRC16 |
Byte Size | 1 | 1 | 1 | 1 | LEN | 2 |
Value | 0x01 | 0-255 | 0-255 | 0-240 | Variable | 0-65535 |
All multibyte integer values are in Big Endian network byte order (most significant byte first).
SOF
The Start Of Frame field, SOF, shall start every valid frame. It shall have a value of 0x01 and is 1 byte in size.
CMD
The CoMmanD field, CMD, shall follow the SOF field. It may have a value from 0 to 255 and is 1 byte in size.
The following are the currently defined CMD values:
Name | Value | Description |
Unacknowledged Commands (0x00-0x0F) | ||
ACK | 0x00 | Acknowledges successful frame reception and that payload will be processed. Does not indicate if the payload was processed successfully or not. |
NACK | 0x01 | Indicates successful frame reception, however the payload was not processed. |
Acknowledged Commands | ||
BUS | 0x10 | Indicates the master is allowing the slave to transmit on the RS-485 bus. The PAYLOAD is empty. |
DATA_REQ | 0x11 | Indicates the PAYLOAD is data for the receiver to process. |
TID
The Transaction ID field, TID, shall follow the CMD field. It may have a value from 0 to 255 and is 1 byte in size.
LEN
The LENgth field, LEN, shall follow the TID field. It may have a value from 0 to 240 and is 1 byte in size.
PAYLOAD
The payload field, PAYLOAD, shall follow the LEN field. It will be LEN bytes in size.
CRC16
The CRC16 field shall follow the PAYLOAD field and is 2 bytes in size. It is a CRC16-CCITT where the polynomial is 0x1021 and the initial value is 0xFFFF. The CRC16 of the 9-byte string "123456789" is 0x29b1. The reference implementation is part of the CWL.
Data Link Layer Handshaking
ACK & NACK
The receiver must send an ACK, NACK, or no response to a received frame based on the following rules:
When an Acknowledged Command is received it shall be responded to with either an ACK or a NACK.
When an Unacknowledged Command is received it shall never be ACKed or NACKed.
When a valid frame is received that contains an Acknowledged CMD field whose value is unsupported then the receiver shall send a NACK frame in response and shall not process the payload.
TID
The transmitter and receiver must manage TIDs based on the following rules:
A transmitter will increment its transaction ID after it is assigned to the TID field of any outgoing Acknowledged CMD.
A receiver will use the TID of the incoming frame as the value of TID in the corresponding ACK or NACK response to an Acknowledged Command.
Each transmitter may only have one outstanding command request pending at any time.
If the TID of a received ACK or NACK does not match the outstanding Acknowledged Command, then the receiver must wait for a 5 second timeout before sending its next command.
If a TID is 255 when it increments, then it wraps back to 0.
Timeouts
Except during a discovery sequence, the transmitter of an Acknowledged Command frame shall wait up to 5 seconds for a corresponding ACK or NACK of that frame.
Retries
The data link layer will not retransmit frames when a timeout occurs.
Buffering
Both receive and transmit shall be software buffered to decouple hardware peripheral and physical layer activity from data and frame processing. This ensures buffers will not get overrun under normal circumstances even when receive processing is delayed or when data is output faster than can be transmitted on the wire.
ConnectWare devices must be able to receive and buffer up to 255 bytes of frame data at line rate.
ConnectWare devices must be able to buffer and transmit up to 255 bytes of frame data. Initial transmission and intercharacter delays are permitted so long as the overall frame timeout period, 5 seconds, is not exceeded.
Both the receive and transmit buffers must be organized as a FIFO queue.
RS-485 Bus Management
For half-duplex RS-485 the CWM is the master and the OKE is the slave. If both the master and slave attempt to transmit on the bus at the same time a collision will occur and corrupt the data. To avoid this problem a simple handshaking protocol is implemented to transfer bus ownership between the master and slave. A device may only transmit while it owns the bus.
By default, the master owns the bus.
There are two cases when the master temporarily releases the bus to the slave.
The master sends an Acknowledged Command to the slave. The slave owns the bus until it ACKs or NACKs the master’s command or the master’s 5 second timeout expires. The slave may send its own outgoing frame on the bus before ACKing or NAKing the master’s original command.
The master will periodically send BUS commands that give the slave bus ownership. The slave owns the bus until it ACKs the BUS command or the master’s 5 second timeout expires. A slave may send its own outgoing frame on the bus before the BUS ACK is sent.
When bus ownership is transferred, the new owner will hold off on transmitting data for a guard period to ensure the bus has been released by their peer. The master will be designed so that it will release the bus to the slave within 1ms after finishing a transmission. This means the slave must wait 1ms after receiving a request from the master before transmitting any frames. The slave should release the bus within 10ms of finishing its transmission. This means the master must wait 10ms before transmitting a frame on the bus again.
The bus ownership handshake protocol allows the serial driver a straightforward means of knowing when to enable for transmit on the RS-485 bus and when to disable transmit and enter receive mode.
The Data Link Layer puts data into the transmit buffer. Before the serial driver begins transmitting the buffered data on the wire it will enable transmit mode. The serial driver will disable transmit mode when the transmit buffer is empty and the last data byte has completely been put on the wire.
Discovery
When the CWM has not yet established communication with its OKE then the CWM shall enter a discovery mode where it will attempt to determine which physical interface and what communication settings must be used between it and the OKE.
The discovery sequence is:
Use no parity, 8 data bits, and 1 stop bit for all discovery attempts.
On TTL RS-232 port send an OKM PING and look for a matching OKM PING using 9600, 19200, 38400, 57600, 115200, and 230400 baud rates.
On RS-485 port send an OKM PING and look for a matching OKM PING using 9600, 19200, 38400, 57600, 115200, and 230400 baud rates.
On USB port determine if device is connected using the CDC device class and send an OKM PING and look for a matching OKM PING.
When a matching OKM PING is received on any interface the discovery procedure will stop immediately.
If the discovery sequence fails to find the ConnectWare equipment, then the module will idle for 10 seconds, and retry the discovery sequence.
When the module finds the equipment port and settings it will save these settings to non-volatile memory and will not initiate discovery again, unless its configuration is reset, or it is commanded to do so explicitly.
The OKE will not initiate discovery or use any means to probe for a CWM.