Model Railroad System  2.2.2
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
cmri::CMri Class Reference

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...
 

Detailed Description

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.

Parameters
portName of the serial port connected to the Chubb RS485 bus.
...Options:
  • -baud Data rate, readonly, defaults to 9600, can be one of 9600, 19200, 28800, 57600, or 115200.
  • -maxtries The maximum number of tries when reading the bus. It is readonly and defaults to 10000. Must be an integer between 1000 and 100000.
Author
Robert Heller <heller@deepsoft.com>

Constructor & Destructor Documentation

◆ CMri()

cmri::CMri::CMri ( name  ,
port  ,
  ... 
)

Constructor.

Parameters
portName of the serial port connected to the Chubb RS485 bus.
...Options:
  • -baud Data rate, readonly, defaults to 9600, can be one of 9600, 19200, 28800, 57600, or 115200.
  • -maxtries The maximum number of tries when reading the bus. It is readonly and defaults to 10000. Must be an integer between 1000 and 100000.

◆ ~CMri()

cmri::CMri::~CMri ( )

The destructor restores the serial port's state and closes it.

Member Function Documentation

◆ _readbyte()

cmri::CMri::_readbyte ( thebytevar  )
private

Read a single byte from the serial interface.

Used by the Inputs() function. Returns false on error and true on success.

Parameters
thebytevarA name of a variable to put the byte read.
Undefined if there was an error.

References gettext::_(), and i.

◆ _readevent()

cmri::CMri::_readevent ( )
private

Read event method.

◆ _transmit()

cmri::CMri::_transmit ( ua  ,
mt  ,
ob   
)
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.

Parameters
uaThe card address.
mtThe message type.
obThe data buffer (not used for Poll messages).

◆ InitBoard()

cmri::CMri::InitBoard ( CT  ,
ni  ,
no  ,
ns  ,
ua  ,
card  ,
dl   
)

The InitBoard() function initializes a given USIC, SUSIC, or SMINI card.

Parameters
CTThe 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.

Parameters
niThe total number of input ports (must be 3 for SMINI).
noThe total number of output ports (must be 6 or SMINI).
nsThe 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.
uaThe card address.
cardThe card type.
dlThe delay value to use.

◆ Inputs()

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.

Parameters
niThe number of input ports to be read. Must equal the number of ports on the specified card.
uaThe card address.

◆ Outputs()

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.

Parameters
portsThe list of port values. Should have as many elements as there are output ports.
uaThe card address.

Member Data Documentation

◆ _timeout

cmri::CMri::_timeout
private

Timeout flag.

◆ AddressCode

cmri::CMri::AddressCode
staticprivate

Address code.

◆ CardType_Byte

cmri::CMri::CardType_Byte
staticprivate

Array of CardType code bytes.

◆ DLE

cmri::CMri::DLE
staticprivate

Data Link Escape.

Used to escape special codes.

◆ ETX

cmri::CMri::ETX
staticprivate

End of text.

Used at the end of message blocks.

◆ Init

cmri::CMri::Init
staticprivate

Initialize message.

Initialize a serial interface board.

◆ Poll

cmri::CMri::Poll
staticprivate

Poll message.

Request the board to read its input ports.

◆ Read

cmri::CMri::Read
staticprivate

Read message.

Generated by a board in response to a Poll message.

◆ STX

cmri::CMri::STX
staticprivate

Start of Text.

Used at the start of message blocks.

◆ Transmit

cmri::CMri::Transmit
staticprivate

Transmit message.

Send data to output ports.

◆ ttyfd

cmri::CMri::ttyfd
private

Terminal file descriptor.