LAN

Introduction

The Local Area Network library sends RCP commands over TCP/IP connections.
The Loco or Decoder must provide a WiFi server socket to which this library can connect.
The commands are sent as XML strings using the Rocrail Client Protocol without the XML-Header.
The Loco or Decoder may also send events back in the same format.

This library makes it possible to use any kind of computer to act as a decoder.


Features

  • Loco and Function commands
  • Sensor support (Reported by a Loco or Decoder)
  • RFID sensor off support
  • Connection recovery
  • Decoder support
    • Switches
    • Signals
    • Outputs
    • Sensors


LAN Setup


Interface ID

Unique ID which should be set on the Interface Tab of the WiFi Loco/Decoder.

Port

The default TCP/IP port used to connect to the WiFi Loco/Decoder.

Connect retry

Number of connection retries before give up.
If set to zero the retries will continue endlessly.

Retry sleep

Number of seconds between the connection retries.

Sensor off delay

The off delay timer in ms for reported RFID's by the WiFi Loco/Decoder.

Options

Decoders

The LAN library becomes at startup the decoder list to initialise connections.
This option is mandatory for Switch, Output and/or Signal objects.


Loco Setup


Code

The TCP/IP address, or hostname, must be set in the Code field.


Decoder Setup


Code

The TCP/IP address, or hostname, must be set in the Code field.


Switch/Output/Signal Setup

The Decoder ID must be set.


Code Format

The Code format may contain a port number in the usual format:

192.168.100.127:4712

If no port is set the default Port, which has been set in the LAN-Setup, will be used.


Test sources

Python

#!/usr/bin/python
import time
from socket import *
myHost = ''
myPort = 4711
s = socket(AF_INET, SOCK_STREAM)     # create a TCP socket
s.bind((myHost, myPort))             # bind it to the server
s.listen(5)                          # allow 5 simultaneously
                                     # pending connections
 
while 1:
  # wait for next client to connect
  connection, address = s.accept()
  while 1:
    data = connection.recv(1024) # receive up to 1K byte
    if data:
      print data
      connection.send('<fb id="102.567.22.46" state="true" fbtype="5"/>\n') # send RFID sensor event which was just read
      time.sleep(5)
 
connection.close()               # close socket

Java

Links


Personal Tools