Model Railroad System
2.2.1
|
Main C/MRI interface class. More...
Public Member Functions | |
CMri (name, port,...) | |
Constructor. More... | |
~CMri () | |
The destructor restores the serial port's state and closes it. More... | |
Inputs (ni, ua=0) | |
The Inputs() function polls the interface and collects the input port values returned by the serial card. More... | |
Outputs (ports, ua=0) | |
The Outputs() function sends bytes to the output ports managed by the specified card. More... | |
InitBoard (CT, ni, no, ns, ua, card, dl) | |
The InitBoard() function initializes a given USIC, SUSIC, or SMINI card. More... | |
Private Member Functions | |
_transmit (ua, mt, ob) | |
Data transmitter. More... | |
_readevent () | |
Read event method. More... | |
_readbyte (thebytevar) | |
Read a single byte from the serial interface. More... | |
Private Attributes | |
ttyfd | |
Terminal file descriptor. More... | |
_timeout | |
Timeout flag. More... | |
Static Private Attributes | |
static | CardType_Byte |
Array of CardType code bytes. More... | |
static | STX |
Start of Text. More... | |
static | ETX |
End of text. More... | |
static | DLE |
Data Link Escape. More... | |
static | AddressCode |
Address code. More... | |
static | Init |
Initialize message. More... | |
static | Transmit |
Transmit message. More... | |
static | Poll |
Poll message. More... | |
static | Read |
Read message. More... | |
Main C/MRI interface class.
This class implements the interface logic for all of the boards on a given serial bus, attached to a given serial (COM) port. This class effectively implements in Tcl what the QBasic serial I/O subroutines implemented by Bruce Chubb implement under MS-Windows.
The constructor opens the serial port and does low-level serial I/O setup (BAUD rate, etc.). This is the first part of the INIT subroutine.
The InitBoard() member function initializes a selected board (the second part of the INIT subroutine) and the Inputs() and Output() member functions correspond to the INPUTS and OUTPUTS subroutines.
The private members, _transmit() and _readbyte() correspond to the TXPACK and RXBYTE subroutines.
port | Name of the serial port connected to the Chubb RS485 bus. |
... | Options:
|
cmri::CMri::CMri | ( | name | , |
port | , | ||
... | |||
) |
Constructor.
port | Name of the serial port connected to the Chubb RS485 bus. |
... | Options:
|
cmri::CMri::~CMri | ( | ) |
The destructor restores the serial port's state and closes it.
|
private |
Read a single byte from the serial interface.
Used by the Inputs() function. Returns false on error and true on success.
thebytevar | A name of a variable to put the byte read. Undefined if there was an error. |
|
private |
Read event method.
|
private |
Data transmitter.
The data is built into a proper message and sent out the serial port to the selected card. Returns false on error and true on success.
ua | The card address. |
mt | The message type. |
ob | The data buffer (not used for Poll messages). |
cmri::CMri::InitBoard | ( | CT | , |
ni | , | ||
no | , | ||
ns | , | ||
ua | , | ||
card | , | ||
dl | |||
) |
The InitBoard() function initializes a given USIC, SUSIC, or SMINI card.
CT | The card type / yellow bi-color LED map. For USIC and SUSIC cards this is the card type map. For the SMINI card this is a 6 element list containing the port pairs for any simulated yellow bi-color LEDs. |
The card type map for USIC and SUSIC is a packed array of 2-bit values, packed 4 per element (byte) from low to high. Each 2-bit value is one of 0 (for no card), 1 (for an input card), or 2 (for an output card). The cards must be "packed" with no open slots except at the end of the bus.
For the simulated yellow LEDs (SMINI card) the paired bits must be adjacent red/green bits and cannot span ports.
ni | The total number of input ports (must be 3 for SMINI). |
no | The total number of output ports (must be 6 or SMINI). |
ns | The number of yellow bi-color LED signals. Only used for SMINI cards. For USIC and SUSIC cards the Length() member function of the CT parameter is used. |
ua | The card address. |
card | The card type. |
dl | The delay value to use. |
cmri::CMri::Inputs | ( | ni | , |
ua | = 0 |
||
) |
The Inputs() function polls the interface and collects the input port values returned by the serial card.
The result is a freshly allocated List object. The calling program should free this memory with delete(). Inputs() returns a NULL pointer if there was an error.
ni | The number of input ports to be read. Must equal the number of ports on the specified card. |
ua | The card address. |
cmri::CMri::Outputs | ( | ports | , |
ua | = 0 |
||
) |
The Outputs() function sends bytes to the output ports managed by the specified card.
Since each element is written to one 8-bit output port, each element is presumed to be a integer in the range of 0 to 255.
ports | The list of port values. Should have as many elements as there are output ports. |
ua | The card address. |
|
private |
Timeout flag.
|
staticprivate |
Address code.
|
staticprivate |
Array of CardType code bytes.
|
staticprivate |
Data Link Escape.
Used to escape special codes.
|
staticprivate |
End of text.
Used at the end of message blocks.
|
staticprivate |
Initialize message.
Initialize a serial interface board.
|
staticprivate |
Poll message.
Request the board to read its input ports.
|
staticprivate |
Read message.
Generated by a board in response to a Poll message.
|
staticprivate |
Start of Text.
Used at the start of message blocks.
|
staticprivate |
Transmit message.
Send data to output ports.
|
private |
Terminal file descriptor.