Configuring interfaces

What is the purpose of this window

This 'network configuration' window allows you to define the hardware that connects your railway to your computer (Windows PC, Mac or Unix workstation), and how that hardware is connected.

The layout is normally connected through RS232 ports on the computer. These connect to various hardware modules, and these connect to various input or output lines. Each RS232 port communicates with its attached hardware using some kind of message protocol. All of these aspects are defined in the network configuration window.

Alternatively devices may be connected over ethernet, though at present there are no stack header modules available that use ethernet, but of course you are free to design your own. The ethernet support at this stage primarily allows you to write your own software. That software can pretend to be part of a layout, indirectly interface to currently unsupported hardware, or act as some kind of user interface not presently supported by Tcc.

This window is organised as a tree, similar to the display that Windows Explorer or the Macintosh Finder sometimes uses to show the tree of nested files and folders in a Disk. Each 'folder' icon has a small icon to its left. Clicking on this expand icon will open (expand) or close (collapse) the folder.

The left-most icon, at the top of the window is the root of the tree and can be likened to the 'My Computer' icon in windows. Inside this folder is another folder for each interface connecting to your layout, and a folder for each stack of hardware modules on your layout.

Most of the items in the network configuration tree are popup menus. Pressing or clicking on one gives a list of options. For example the top-left-most item (labelled 'New interface') gives a popup allowing you to define a new serial interface, ethernet interface, merg stack or CTI stack.

To open the network configuration window use Menu:Configure->Networks...

Glossary of terms

"Module"
A module is a block of circuitry mounted on a PCB or stripboard or similar that connects to the layout to drive layout objects (turnouts, lamps etc), or to sense the state of layout objects (track circuits, turnout position etc). Modules join together in some manner to form a stack.
"Stack"
A stack is a collection of hardware interface modules connected to one another. The term originated from RPC modules where these physically plug into one-another to make a physical stack. I am also using the term to include groups of RPC modules separated by RSE (remote stack extender) modules and CTI modules connected in their RS232 ring-main. A "stack" requires some kind of "stack-header" module to connect to an "interface".
"Stack-header"
A stack-header is something that allows a stack of layout-interface modules to connect directly to the controlling computer. For MERG RPC modules the most common stack header is the RPIC (or the older version called the RPI). This basically converts the shift-register connections of the stack into RS232, RS485 or USB depending upon the version of RPIC you use. A less common RPC stack header is the RPIZ which I use - it is much cheaper than an RPIC and works in full duplex, and so twice as fast!
The stack header doesn't have to be a separate module - for example the QTU has an RS232/RS485 stack header built-in to the module. CTI modules don't require an active stack header - they simply have a special connector between the ring of modules and the computer.
"Protocol"
The protocol is the way the data has to be formatted for sending over the wire. Typically the protocol depends upon which family of modules are being used (CTI or RPC) and the type of stack header (RPIC, RPIZ, QTU). In concept each stack has one stack-header and uses one protocol.
"Interface"
An interface is the connection to the controlling computer. For serial ports it can be regarded as the physical socket on the computer. For ethernet ports it is a 'logical socket' and one ethernet port can be shared by many 'logical sockets' just as ethernet allows a computer to connect to many devices on a network at once.

Why are interfaces and stacks separated

Earlier versions of Tcc used to only list (serial) interfaces under the root of the tree, with stacks being inside each interface. These are now separated for the following reasons:

Defining a serial interface port

Pressing the New interface box (point at the box and hold down the mouse) brings up a popup menu listing the supported interface types. Select "Serial" from this menu creates an interface folder for a new serial interface.

In the same way that the New Interface box brought up a menu of options, each interface and stack does likewise. Its menu allows you to start and stop the stack or interface, and also to rename or delete it.

Using the rename option you can set the name of a stack or interface can be anything you wish and is just as a reminder of which is which.

The delete option removes the interface (or stack). There is no undo cabability in Tcc, so take care.

If you click on the expand icon (the small icon to the left of the interface box, the appearance is system dependant), then you can see the settings associated with the serial interface you have just ceated.

Firstly you need to define which physical port you are connecting to, so the "Interface" button allows you to select from the available serial ports (if you have any!).

All serial interfaces need a baud rate, number of data bits (normally 8) and number of stop bits. The choices available will depend upon which protocols have been associated with this interface. More of this when we create a stack.

A serial interface works by sending a message to a connected stack, then waiting for a response to be received. The interface can only be waiting for the response to one message at a time. If a message is corrupted or lost (perhaps the stack has lost power) then a mechanism is required to allow the interface to recover.

This means that a serial interface needs a timeout parameter. This limits the time that Tcc will wait for a response. If no response is received after the timeout period has passed then Tcc will give up and send another message.

The timeout parameter is measured in milliseconds.

What timeout should a serial port use

There are two main factors here:

The message turn around time is simple:

Number of bytes * 10 / baudrate
is the time it takes for your message to be sent. Note that the number of bytes should include headers and checksums, so just add 5 to the larger of the number of output bytes or input bytes (CTI stacks are different - normally one byte per module).

For half duplex stack headers like the RPI-C double this time and add a bit for processing. Full duplex headers do not need any extra.

The operating system delay time is much more unpredictable. Operating systems execute several programs at once by sharing CPU time using some kind of scheduling algorithm. If another program (such as a virus checker, or disk defragmenter) needs to run it can stop Tcc for some period of time (from a few milliseconds to a few seconds). Also if there isn't enough memory for that other program to run in, then part of Tcc will be pushed to disk, the other program takes its share and then Tcc is restored from disk.

If Tcc needs to load an image (the script executes the $Load Image command) it hasn't used before then the disk access might interrupt serial comms.

All these delays are very operating system dependant. From experience (and theory) these can be listed from 'best' (lowest expected delays) to 'worst' as:


If you use Windows98 then you need to set timeout quite high - perhaps a second or two. A UNIX system will probably be all right on message turn-around time plus 10ms. A real-time OS would work on turn-around time plus 1ms!

Defining a stack

Using the "New interface" button (top-left box in the window) allows you to create either a Merg stack, or a CTI stack. These are only different in the choices of modules and stack headers used.

Again the stacks own menu allows strat, stop, rename and delete, just the same as for interfaces. You can rename your stack to perhaps reflect its location on the layout.

Each stack consists of a bunch of modules (of the appropriate kind). These are added with the "New Module" button.

The first module listed in a stack is the one closest to the stack header (or computer port for CTI). You can drag them around to resequence them if necessary.

Each Merg stack is connected to the interface via a stack header. This is selected by the "Protocol" button - this tells Tcc how to format the data in a manner that the stack header will understand.

In order to use a stack it needs to be associated with an interface. the "Interface" button allows you to select between the currently listed interfaces (Serial and Ethernet). You need to create the interface before you can connect a stack to it.

Several stacks can be connected to one interface at once. You can use several RS485 RPICs on one interface, or several QTUs. No check is made that the combination is viable however. Connecting an RPIC and a CTI to one serial port won't work (nor can you do it electrically!). Other combinations may or may not work.

Each stack has a "Preferred rate" parameter. This is the number of messages per second it wants to send. Naturally if you set it too high so that the interface cannot support the data rate then it won't go as fast as you say.

The preferred rate can be used to slow down a stack, or to make one stack on an interface run faster than another.

For manually driven layouts a rate of 2 or 3 messages per second might be enough (but also consider input filtering).

For a layout with computer driven trains you might want 10 messages per second.

The final entry in the stack menu is Trace Messages. This causes the next few messages sent and received to be displayed in the Log window.

The format in this log of messages transmitted is the word "Send" followed by a number, and then the message bytes listed in hexadecimal. The message listing includes normal prefixes and suffixes (but not the long string of zeroes associated with CTI messages). The number after the word "Send" is either the message number (incremented each time a message is transmitted), or a plus sign ('+') followed by the number of milliseconds since the previous message. The message number is shown if the previous message logged was NOT immediately prior to the new one.

The format of received messages is the word "Rcvd:" followed by the hexadacimal listing of the received message. If the message doesn't decode correctly then the word "Rcvd" is replaced by "RxBad". If no message is received on a serial port then the word "Timeout" is shown (with no hexadecimal listing of course!).

Defining an ethernet interface port

Press the New interface box and select ethernet from the popup menu.

All ethernet ports use whatever ethernet socket on your computer that they need to use, so we don't have to worry about that, so even if your computer has several ethernet sockets (which is unlikely) you don't need to choose one.

Our ethernet interface configuration starts with defining which machine we are talking to. This remote machine name can be a name (if you have some kind of name service setup with a name given to your target machine, then you can enter the name), or just a plain IP address (of the form nn.nn.nn.nn where each nn is a decimal number between 0 and 255). We consider that all the stacks 'attached' to this interface are on this defined machine. If you want to communicate with some other software on the same machine then leave the box blank, enter "localhost" or the address 127.0.0.1

The model railway interface software at the far end is a 'service', in the same way that ftp (file transfer protocol) and telnet (a remote login capability) are services. Each service has a port number. The transmit port number should be the number of the UDP port that the remote software is listening to (and therefore what Tcc should send to).

The receiving port tells Tcc which port it should listen to, for receiving responses.

If the two ends of the connection are on different computers both numbers can be the same, but if you want Tcc to talk to some other software on the same computer then they each need to listen to different ports. This is only the same as saying if you wanted to connect two pieces of software on the same machine over a serial cable (a null-modem cable) then the two serial ports must obviously be different, perhaps COM1 and COM2. If you were connecting two computers this way they could (but don't have to) be COM1.

Attach stacks to an ethernet interface in the same way you would attach stacks to a serial interface (described above).

Note that the stack addresses at each end must be the same for data to be transferred successfully. If using two copies of Tcc you could define several stacks at each end that attach to the same ethernet interface, and the output data from stack 1 at one end would be transferred to the input data of stack 1 at the other end, and vise-versa. Ditto with stack 2, stack 3 etc.

Why would you want to attach several stacks to one interface? Well if the other end were actually interfacing to real stacks by some other means then it makes good sense.

Why is there no timeout parameter for ethernet interfaces?

A serial interface can only carry one message at a time, and if we try to send a message at the same time that a response was arriving then things are likely to go wrong. So for those protocols that are half duplex (primarily the RPIC protocol) we sit and wait for a response before sending another message.

Ethernet on the other hand is so fast that it would be possible to send messages to half a dozen stacks really quickly, and then wait for the responses to come back. The collision detect and retry mechanism in ethernet makes this a quite normal thing to do.

In fact Tcc handles ethernet interfaces quite differently. It sends packets for each stack, at the preferred rate for each stack. This is totally independant of any replies. Replies that are received are routed to the stack they are for (by looking at the address field of the ethernet prefix). This means that you can have output data running at a different repeat rate to input data.

If the other end of the ethernet link is some software that puts the data onto a serial link, then that software should implement timeouts to protect the serial link itself. It can pass back replies whenever it has one, and ignore output data that it cannot handle (if it gets too much).

Starting and stopping interfaces and stacks

In general the Start and Stop start and stop communications.

Starting a stack means that Tcc starts sending messages to that one stack. If its interface is not already started then it is started, for just the one stack.

Stopping a stack stops messages to that one stack, also stopping its interface if no other stack is using it.

If instead of stopping a stack, you stop an interface then naturally all the stacks using that interface must stop receiving messages. The stacks only change state to stopped if all the stacks on the interface were running. This allows you to control an interface without switching all of its stacks if you just want to use some of them.

Starting a stack that has no stacks already marked as running will cause all its stacks to become started.

Starting a stack which has some stacks already marked as started will resume operation on that set, and leave the others stopped.

The main menu items Configure->Start Network and Configure->Stop Network are the same as selecting Start or Stop for each interface in turn. This means that starting Tcc and then selecting Start Network will cause all stacks on all interfaces to start operating.

There is one way is which the menus Configure->Start Network differ from selecting Start: If (and only if) the network is started using the Configure menu and Tcc is shut down with the network running, then next time Tcc is started (with the same script) the network will automatically restart. The reason it differs in the Network Configuratin window is that those controls are more normally used for debugging, rather than simply starting an operating session.

Supported protocols

CTI modules supported

TrainBrain.
Basic I/O module with 4 inputs and 4 SPDT relay outputs. Inputs are CMOS/TTL style with pluggable pull-ups which are useful when your inputs have different impedances such as LDRs (Light-Dependant-Resistors).
Watchman.
8 inputs as per TrainBrain. I do not have any of these personally but have not received any complaints yet.
Dash-8
8 4A relay outputs as per TrainBrain. I do not have any of these personally but have not received any complaints yet.
Signalman
16 outputs for driving lights and LEDs. Available in 3 types: common-anode LED, common-cathode LED, filament lamp. Tcc doesn't really support signals as a separate entity so these may not work properly.
SmartCab
A single computer-controlled throttle with built-in inertia, brake and reversing relay. Tcc makes all types of throttles appear to be like SmartCabs from the script perspective.

RPC kits supported

DPR (Dual Pole Relay)
Eight DPDT 1A relays. Solder tag connections to the relay pins.
SRO4 (Shift Register Output 4-byte)
32 open-collector outputs capable of driving 500mA each (though not all at once!). Good for LEDs, filament lamps, relays, tortoise motors and all sorts.
FTC (Floating Track Circuit.)
Eight track current detectors. Drops three diode-Vf (about 2.5V). Requires three additional power feeds over the basic stack 5V. If you use these on any track sections you need to use them (or similar volt droppers) on all sections or else your trains will speed up and slow down dramatically as they change section!
SRI4 (Shift Register Input 4-byte).
32 CMOS inputs with fixed 100K resistors. Can connect directly to reed relays, switches, IRDOT or Hector sensors. Use extra pull-ups (to lower resistance) for use with LDRs.
TB G16/51 throttle, or similar 7-bit throttle
Uses one byte of an SRO4 to drive a throttle with 128 speed settings (7-bit), with bit-7 used as direction (reverse when high). Inertia and brake are simulated by Tcc.
Other home-brew 8-bit throttle with separate direction.
Uses one byte of output (DPR, SRO4, or home-brew) to drive an 8-bit throttle. Direction control can be taken from a single output pin elsewhere. Inertia and brake are simulated by Tcc.
RPI-C (Remote Panel Interface - PIC based)
This is the standard stack header for RPC. Alternatives include a home-brew device that supports the same protocol or the simplified RPI-Z protocol, or a QTU module.
MUX (Byte multiplexor) This isn't a standard RPC module but is a software function that multiplexes several values onto a single byte. See below for details.
QTU (Quad Throttle Unit)
This intelligent board contains:

MUX module

If your stack (as defined in the Network Config window) includes an RPC MUX module then values are multiplexed onto one or more bytes. Typically this is used with a home-brew semi smart module, perhaps based upon an AVR or PIC microcontroller.

You might decide that the top few bits define which 'page' of data is being sent and the hardware module will save the bottom bits according to the value of the top bits. The top bits must be assigned by your TCL script - all the MUX module does is send each value in turn repeatedly.

To define how many values are being sent include that number of entries in the Controls: section and define them to be zero bits wide (put :0 after the name). They are zero bits wide because individually they consume no stack space at all. Despite being declared as zero bits wide (meaning send no bits of that data to the stack) these control values can still store the normal 32 bits of data value each.

To define how many bytes of stack receive the multiplexed values open the MUX module in the Network Config window and select byte count from 1, 2, 3 or 4 bytes (TCL variables are 32 bits wide so you cannot send values bigger than that).

To make some value transmit more frequently than others simply store them multiple times in your list of values, spaced out in the list.

If your hardware wants some fixed and some multiplexed data you can intermingle DPR (1 byte) or SRO4 (4 byte) modules with MUX modules in your Network Config.

Message formats

In case you want to make your own stack header or write your own software to interface to Tcc over ethernet or serial port, here are the messages that Tcc sends, and expects to receive.
General format
All messages to and from the hardware are of the following general format.
PrefixProtocol and interface dependant fields
HeaderProtocol dependant
DataModule dependant data
SuffixProtocol dependant checksum
Prefixes
The prefix is, on serial ports, just some 'wake-up' bytes that mark the start of a message. This is so that the hardware can easily discover the start of a message if it gets out of step with the computer.

RPIC prefix over Serial
Prefix sent to hardware
byte 10xAA
byte 20x55
Prefix received from hardware
There is no prefix received from the RPIC module.

RPIZ prefix over Serial
The RPIZ protocol uses no prefix bytes in either direction.

QTU prefix over Serial
Prefix sent to hardware
byte 10x55
Message received from hardware
There is no prefix received from the QTU module.

CTI prefix over Serial
Prefix sent to hardware
byte 10x41
Prefix received from hardware
We receive zeroes from the hardware until the outgoing prefix (0x41, letter 'A') has shifted all the way around the loop.
bytes 1..nzeroes
byte n+10x41

Prefix for all protocols over ethernet
Prefix sent to hardware and received from hardware
byte 1AddressStack address
byte 2CommandAlways 0 at present
byte 3FSNForward sequence number
increments with each message
byte 4BSNBackward sequence number: same as
FSN of previously received message

Header field
After the prefix (which we can see if protocol-dependant and direction-dependant on serial links, and different on ethernet), we have the header of the message. This is interface-independant (same on serial and ethernet), but protocol dependant.

RPIC header
RPIC header sent to hardware, and received from hardware
byte 1add+typestack address (4 bits)
and message type (4 '0' bits)
byte 2lengthlength of data+2

RPIZ header
RPIZ header sent to hardware, and received from hardware
byte 1addressstack address

QTU header
RPIZ header sent to hardware, and received from hardware
byte 1addressstack address
byte 2lengthlength of data+2

CTI Header
CTI header sent to hardware
byte 10x00index to data
CTI header received from hardware
byte 1lengthlength of data

Data carried in message
The meaning of the data is dependant upon the modules in the stack. The byte ordering is protocol-dependant:
RPIC byte ordering
The RPIC receives a whole message, and then shift it out in reverse to the stack, so...
  • The first data byte transmitted (just after the header) is destined for the (output) module nearest the stack header.
  • The first byte received comes from the (input) module nearest to the stack header.
RPIZ byte ordering
The RPIZ stack header simply shifts the received data to the stack, so...
  • The first byte transmitted is destined for the (output) module most distant from the stack header.
  • The first byte received comes from the (input) module nearest to the stack header.
QTU byte ordering
The QTU stack header simply shifts the received data to the stack, so...
  • The first byte transmitted is destined for the (output) module most distant from the stack header.
  • The first byte received comes from the (input) module nearest to the stack header.
CTI byte ordering
Bytes are shifted around the CTI loop, so...
  • The first byte transmitted is destined for the (output) module furthest around the ring of modules.
  • The first byte received comes from the (input) module furthest around the ring of modules.

The message suffix
Some protocols add a checksum suffix to the data:
RPIC suffix

RPIC suffix sent to hardware, and received from hardware
byte 1checksum

RPIZ suffix
The RPIZ stack header uses no suffix in either direction.

QTU suffix

QTU suffix sent to hardware, and received from hardware
byte 1checksum

CTI suffix

CTI suffix sent to the hardware.
The CTI protocol appends as many zero bytes as there are data bytes. These bytes then become the received prefix next time around.
CTI suffix received from the hardware
There is no suffix in this direction.

Last updated 23/04/11

© Howard Amos. 2005-2011