Model Railroad System
2.2.2
|
Main NCE Cab Bus interface class. More...
Public Member Functions | |
NCE (name, port="/dev/ttyS0",...) | |
Constructor. More... | |
~NCE () | |
The destructor restores the serial port's state and closes it. More... | |
NOP () | |
NOP, dummy instruction. More... | |
AssignLoco (locoaddress, cabnumber) | |
Assign loco to cab. More... | |
ReturnClock () | |
Returns the fast clock to the RS232 port in binary mode. More... | |
StopClock () | |
Stops the scale time clock. More... | |
StartClock () | |
Starts the scale time clock. More... | |
SetClock (hours, minutes) | |
Set the scale time clock. More... | |
SetClockFormat (format) | |
Set clock 12/24 hours. More... | |
SetClockRatio (ratio) | |
Set clock speed (ratio). More... | |
DequeuePacket (locoaddress) | |
Dequeue packet by loco addr. More... | |
EnableMain () | |
Enable main trk, kill prog. More... | |
ReturnAuxilaryInputUnit (cabnumber) | |
Returns status of Auxilary Input Unit. More... | |
DisableMain () | |
Kill main track, enable program track. More... | |
Dummy () | |
Dummy instruction returns "!" followed by CR/LF. More... | |
SetLocoSpeedMode (locoaddress, mode) | |
Sets the speed mode of loco. More... | |
WriteToRAM (address,...) | |
Writes bytes to a command station RAM address. More... | |
ReadFromRAM (address) | |
Returns 16 bytes from a RAM address. More... | |
WriteLCDLine3 (cabnumber, textline) | |
Sends a message to LCD line 3 of a cab. More... | |
WriteLCDLine4 (cabnumber, textline) | |
Sends a message to LCD line 4 of a cab. More... | |
WriteLCDRightLine2 (cabnumber, textline) | |
Sends a message to the right side of LCD line 2 of a cab. More... | |
WriteRAWPacket (sendtimes,...) | |
Reads a raw packet to put in TEMP_Q. More... | |
WriteOneByteToRAM (address, byte) | |
Writes 1 byte to a command station RAM address. More... | |
WriteTwoBytesToRAM (address, byte1, byte2) | |
Writes 2 bytes to a command station RAM address. More... | |
Write4BytesToRAM (address, byte1, byte2, byte3, byte4) | |
Writes 4 bytes to a command station RAM address. More... | |
Write8BytesToRAM (address,...) | |
Writes 4 bytes to a command station RAM address. More... | |
ReturnAuxilaryInputUnitShortForm (cabnumber) | |
Returns status of Auxilary Input Unit, short form. More... | |
ExecuteMacro (macroNumber) | |
Executes a previously defined macro for route control. More... | |
ReadOneByteFromRAM (address) | |
Reads 1 byte from a command station RAM address. More... | |
ProgramMode () | |
Enters Program track mode. More... | |
NormalMode () | |
Returns from Program track mode. More... | |
WriteCVInPagedMode (address, data) | |
Writes a CV in paged mode. More... | |
ReadCVInPagedMode (address) | |
Reads a CV in paged mode. More... | |
SetLocomotiveSpeedAndDirection (locoaddress, ssm, dir, speed) | |
Set locomotive speed and direction. More... | |
SetLocomotiveFunctionsGroup1 (locoaddress, f0, f1, f2, f3, f4) | |
Set locomotive functions, group 1. More... | |
SetLocomotiveFunctionsGroup2 (locoaddress, f5, f6, f7, f8) | |
Set locomotive functions, group 2. More... | |
SetLocomotiveFunctionsGroup3 (locoaddress, f9, f10, f11, f12) | |
Set locomotive functions, group 3. More... | |
AddLocomotiveToMultiUnit (locoaddress, mtr, samedirection) | |
Add locomotive to Multi-Unit. More... | |
RemoveLocomotiveFromMultiUnit (locoaddress, mtr) | |
Remove locomotive to Multi-Unit. More... | |
AddLeadLocomotiveToMultiUnit (locoaddress, mtr, samedirection) | |
Add lead locomotive to Multi-Unit. More... | |
AddRearLocomotiveToMultiUnit (locoaddress, mtr, samedirection) | |
Add rear locomotive to Multi-Unit. More... | |
ChangeMomentumLevel (locoaddress, newlevel) | |
Change momentum level for loco or consist. More... | |
WriteRAWTrackPacket (...) | |
Reads a raw packet to put in TRK_Q. More... | |
WriteRegister (register, data) | |
Writes a register. More... | |
ReadRegister (register) | |
Read a register. More... | |
WriteCVInDirectMode (address, data) | |
Writes a CV in direct mode. More... | |
ReadCVInDirectMode (address) | |
Reads a CV in direct mode. More... | |
SoftwareVersion () | |
Read software version number. More... | |
SoftReset () | |
Soft reset of command station. More... | |
HardReset () | |
Hard reset of command station. More... | |
MacroCommand (address, macronumber) | |
Assign address to macro. More... | |
AccessoryDecoderOperation (address, activateOutput) | |
Accessory decoder operation request. More... | |
SetSignalAspect (address, aspectBits) | |
Set signal aspect. More... | |
OperatingModeProgrammingByteModeWrite (locoaddress, cv, data) | |
Operating mode programming byte mode write. More... | |
OperatingModeAccessoryProgrammingByteModeWrite (address, cv, data) | |
Operating mode accessory programming byte mode write. More... | |
SetCabBusAddressOfUSBBoard (cabaddress) | |
Set the cab bus address of the USB board. More... | |
SetBinaryCommandEchoMode (mode) | |
Set binary command echo mode. More... | |
Public Attributes | |
ttyfd | |
Terminal file descriptor. More... | |
Static Public Attributes | |
static | NumberOfBytesReturned |
Array containing the number of bytes expected for each command. More... | |
Private Member Functions | |
_transmit (themessage) | |
Transmit a message. More... | |
_readevent () | |
Read event handler, toggle timeout flag. More... | |
_timeoutevent () | |
Timeout event handler, toggle timeout flag. More... | |
_readbyte (thebytevar, timeout=5) | |
Read next available byte or return false. More... | |
_readresponse (bufferVar, expectnumberofbytes) | |
Read a response message. More... | |
_sendMessageAndReturnResponse (message) | |
Send a message and return a response. More... | |
_explodechars (text) | |
Explode text into ASCII character codes. More... | |
Private Attributes | |
_timeout | |
Timeout or data available flag. More... | |
Main NCE Cab Bus interface class.
This class implements the interface logic to connect to the NCE Cab Bus.
port | Name of the serial port connected to the NCE Cab Bus. |
... | Options:
|
nce::NCE::NCE | ( | name | , |
port | = "/dev/ttyS0" , |
||
... | |||
) |
Constructor.
port | Name of the serial port connected to the NCE Cab Bus. |
... | Options:
|
nce::NCE::~NCE | ( | ) |
The destructor restores the serial port's state and closes it.
|
private |
Explode text into ASCII character codes.
|
private |
Read next available byte or return false.
thebytevar | Name of a variable to receive the byte. |
timeout | Timeout in seconds. |
If there is a defined external read event handler, the timeout parameter is ignored and false is returned if there are no bytes available. The presumption is that the read is being called from event handler and that means that there is data available.
|
private |
Read event handler, toggle timeout flag.
|
private |
Read a response message.
|
private |
Send a message and return a response.
|
private |
Timeout event handler, toggle timeout flag.
|
private |
Transmit a message.
nce::NCE::AccessoryDecoderOperation | ( | address | , |
activateOutput | |||
) |
Accessory decoder operation request.
address | Accessory address (not in DCC format). |
activateOutput | Output on or off. |
nce::NCE::AddLeadLocomotiveToMultiUnit | ( | locoaddress | , |
mtr | , | ||
samedirection | |||
) |
Add lead locomotive to Multi-Unit.
locoaddress | Locomotive address. |
mtr | Multi-Unit address. |
samedirection | The locomotive direction is the same as the consist direction. |
nce::NCE::AddLocomotiveToMultiUnit | ( | locoaddress | , |
mtr | , | ||
samedirection | |||
) |
Add locomotive to Multi-Unit.
locoaddress | Locomotive address. |
mtr | Multi-Unit address. |
samedirection | The locomotive direction is the same as the consist direction. |
nce::NCE::AddRearLocomotiveToMultiUnit | ( | locoaddress | , |
mtr | , | ||
samedirection | |||
) |
Add rear locomotive to Multi-Unit.
locoaddress | Locomotive address. |
mtr | Multi-Unit address. |
samedirection | The locomotive direction is the same as the consist direction. |
nce::NCE::AssignLoco | ( | locoaddress | , |
cabnumber | |||
) |
Assign loco to cab.
From Bincmds.pdf: Loco address for this command is always 2 bytes. The first byte is zero in the case of a short address. If the address is long then bits 6,7 of first byte must be set to 1
locoaddress | Loco address (0-9999). |
cabnumber | Cab number (0-63) |
nce::NCE::ChangeMomentumLevel | ( | locoaddress | , |
newlevel | |||
) |
Change momentum level for loco or consist.
locoaddress | Locomotive or consist address. |
newlevel | New momentum level (0-9). |
nce::NCE::DequeuePacket | ( | locoaddress | ) |
Dequeue packet by loco addr.
Reads loco address from BIN_BUFF, finds the corresponding entry in TRK_Q and deletes the packet from the TRK_Q.
locoaddress | Loco address (0-9999). |
nce::NCE::DisableMain | ( | ) |
Kill main track, enable program track.
nce::NCE::Dummy | ( | ) |
Dummy instruction returns "!" followed by CR/LF.
nce::NCE::EnableMain | ( | ) |
Enable main trk, kill prog.
nce::NCE::ExecuteMacro | ( | macroNumber | ) |
Executes a previously defined macro for route control.
macroNumber | The macro number. |
nce::NCE::HardReset | ( | ) |
Hard reset of command station.
Clears all RAM and resets command station to original fac defaults. All stored information is destroyed Note: the baud rate will be set to 9600
nce::NCE::MacroCommand | ( | address | , |
macronumber | |||
) |
Assign address to macro.
address | Accessory address (not in DCC format). |
macronumber | NCE macro number (0-255). |
nce::NCE::NOP | ( | ) |
NOP, dummy instruction.
nce::NCE::NormalMode | ( | ) |
Returns from Program track mode.
Power is restored to mainline and removed from program track. The queues are reinitialized for normal operation.
nce::NCE::OperatingModeAccessoryProgrammingByteModeWrite | ( | address | , |
cv | , | ||
data | |||
) |
Operating mode accessory programming byte mode write.
address | Accessory address. |
cv | CV to set. |
data | Data to set. |
nce::NCE::OperatingModeProgrammingByteModeWrite | ( | locoaddress | , |
cv | , | ||
data | |||
) |
Operating mode programming byte mode write.
locoaddress | Locomotive address. |
cv | CV to set. |
data | Data to set. |
nce::NCE::ProgramMode | ( | ) |
Enters Program track mode.
Power is removed from mainline and applied to program track. The queues are formatted to send reset packets.
nce::NCE::ReadCVInDirectMode | ( | address | ) |
Reads a CV in direct mode.
address | CV address. |
nce::NCE::ReadCVInPagedMode | ( | address | ) |
Reads a CV in paged mode.
address | CV address. |
nce::NCE::ReadFromRAM | ( | address | ) |
Returns 16 bytes from a RAM address.
address | Address to start reading from. |
nce::NCE::ReadOneByteFromRAM | ( | address | ) |
Reads 1 byte from a command station RAM address.
address | RAM address. |
nce::NCE::ReadRegister | ( | register | ) |
Read a register.
register | The register to read from. |
nce::NCE::RemoveLocomotiveFromMultiUnit | ( | locoaddress | , |
mtr | |||
) |
Remove locomotive to Multi-Unit.
locoaddress | Locomotive address. |
mtr | Multi-Unit address (not used). |
nce::NCE::ReturnAuxilaryInputUnit | ( | cabnumber | ) |
Returns status of Auxilary Input Unit.
Returns four bytes. The first 2 bytes are a bit map of the 14 AIU inputs. The last 2 bytes are a bit map of any changes since this command was last given. If the cab is greater than 63 it will be "forced" to 0. The first time this command is given for a cab after the command station is powered up or reset the change bytes will be 0x3fff.
cabnumber | Cab number (0-63) |
nce::NCE::ReturnAuxilaryInputUnitShortForm | ( | cabnumber | ) |
Returns status of Auxilary Input Unit, short form.
This is a short form of CMD 0x8A. It returns only the first 2 bytes of command 0x8A. The 2 bytes are a bit map of the 14 AIU inputs. If the cab is greater than 63 it will be "forced" to 0.
cabnumber | Cab number (0-63) |
nce::NCE::ReturnClock | ( | ) |
Returns the fast clock to the RS232 port in binary mode.
nce::NCE::SetBinaryCommandEchoMode | ( | mode | ) |
Set binary command echo mode.
mode | Mode to set: 0 = no echo, 1 = echo 1st byte of command, or 2 = echo entire command. |
nce::NCE::SetCabBusAddressOfUSBBoard | ( | cabaddress | ) |
Set the cab bus address of the USB board.
cabaddress | Cab address. |
nce::NCE::SetClock | ( | hours | , |
minutes | |||
) |
Set the scale time clock.
hours | Hours (0-23). |
minutes | Minutes (0-59). |
nce::NCE::SetClockFormat | ( | format | ) |
Set clock 12/24 hours.
format | Clock format flag: true for 24 hour format, false for 12 hour format. |
nce::NCE::SetClockRatio | ( | ratio | ) |
Set clock speed (ratio).
ratio | Scale clock ratio, 1-25. |
nce::NCE::SetLocomotiveFunctionsGroup1 | ( | locoaddress | , |
f0 | , | ||
f1 | , | ||
f2 | , | ||
f3 | , | ||
f4 | |||
) |
Set locomotive functions, group 1.
address | Locomotive address. |
f0 | Function 0. |
f1 | Function 1. |
f2 | Function 2. |
f3 | Function 3. |
f4 | Function 4. |
nce::NCE::SetLocomotiveFunctionsGroup2 | ( | locoaddress | , |
f5 | , | ||
f6 | , | ||
f7 | , | ||
f8 | |||
) |
Set locomotive functions, group 2.
address | Locomotive address. |
f5 | Function 5. |
f6 | Function 6. |
f7 | Function 7. |
f8 | Function 7. |
nce::NCE::SetLocomotiveFunctionsGroup3 | ( | locoaddress | , |
f9 | , | ||
f10 | , | ||
f11 | , | ||
f12 | |||
) |
Set locomotive functions, group 3.
address | Locomotive address. |
f9 | Function 9. |
f10 | Function 10. |
f11 | Function 11. |
f12 | Function 12. |
nce::NCE::SetLocomotiveSpeedAndDirection | ( | locoaddress | , |
ssm | , | ||
dir | , | ||
speed | |||
) |
Set locomotive speed and direction.
locoaddress | Locomotive address. |
ssm | Speed mode (either S28 or S128). |
dir | Direction (either Forward or Reverse). |
speed | Locomotive speed (0-28, 0-128, or 255 (means emergency stop)). |
nce::NCE::SetLocoSpeedMode | ( | locoaddress | , |
mode | |||
) |
Sets the speed mode of loco.
locoaddress | Loco address (0-9999). |
mode | Speed step mode, one of S14, S28, or S128. |
nce::NCE::SetSignalAspect | ( | address | , |
aspectBits | |||
) |
Set signal aspect.
address | Accessory address (not in DCC format). |
aspectBits | Signal aspect bit mask. |
nce::NCE::SoftReset | ( | ) |
Soft reset of command station.
Sets command Station to power up condition.
nce::NCE::SoftwareVersion | ( | ) |
Read software version number.
nce::NCE::StartClock | ( | ) |
Starts the scale time clock.
nce::NCE::StopClock | ( | ) |
Stops the scale time clock.
nce::NCE::Write4BytesToRAM | ( | address | , |
byte1 | , | ||
byte2 | , | ||
byte3 | , | ||
byte4 | |||
) |
Writes 4 bytes to a command station RAM address.
address | RAM address. |
byte1 | First byte to write. |
byte2 | Second byte to write. |
nce::NCE::Write8BytesToRAM | ( | address | , |
... | |||
) |
Writes 4 bytes to a command station RAM address.
address | RAM address. |
byte1 | First byte to write. |
byte2 | Second byte to write. |
nce::NCE::WriteCVInDirectMode | ( | address | , |
data | |||
) |
Writes a CV in direct mode.
address | CV address. |
data | Data to write. |
nce::NCE::WriteCVInPagedMode | ( | address | , |
data | |||
) |
Writes a CV in paged mode.
address | CV address. |
data | Data to write. |
nce::NCE::WriteLCDLine3 | ( | cabnumber | , |
textline | |||
) |
Sends a message to LCD line 3 of a cab.
cabnumber | Cab Number (0-63). |
textline | A string of 16 printable characters. |
nce::NCE::WriteLCDLine4 | ( | cabnumber | , |
textline | |||
) |
Sends a message to LCD line 4 of a cab.
cabnumber | Cab Number (0-63). |
textline | A string of 16 printable characters. |
nce::NCE::WriteLCDRightLine2 | ( | cabnumber | , |
textline | |||
) |
Sends a message to the right side of LCD line 2 of a cab.
cabnumber | Cab Number (0-63). |
textline | A string of 8 printable characters. |
nce::NCE::WriteOneByteToRAM | ( | address | , |
byte | |||
) |
Writes 1 byte to a command station RAM address.
address | RAM address. |
byte | Byte to write. |
nce::NCE::WriteRAWPacket | ( | sendtimes | , |
... | |||
) |
Reads a raw packet to put in TEMP_Q.
sendtimes | Number of times to send packet, 0 means don't send it. 255 is the same as 254 (system limitation). |
... | Packet bytes to send, 3 to 6 bytes. |
nce::NCE::WriteRAWTrackPacket | ( | ... | ) |
Reads a raw packet to put in TRK_Q.
... | Packet bytes to send, 3 to 5 bytes. |
nce::NCE::WriteRegister | ( | register | , |
data | |||
) |
Writes a register.
register | The register to write to. |
data | The data to write. |
nce::NCE::WriteToRAM | ( | address | , |
... | |||
) |
Writes bytes to a command station RAM address.
address | Address to start writing to. |
... | Bytes to write (upto 16). |
nce::NCE::WriteTwoBytesToRAM | ( | address | , |
byte1 | , | ||
byte2 | |||
) |
Writes 2 bytes to a command station RAM address.
address | RAM address. |
byte1 | First byte to write. |
byte2 | Second byte to write. |
|
private |
Timeout or data available flag.
|
static |
Array containing the number of bytes expected for each command.
nce::NCE::ttyfd |
Terminal file descriptor.