Microtron Ltd - IT Solutions - NZ

Lincolnshire model railway program

 

Download developmental program (mono based interpreter using .NET and WinForms and C++ for Arduino)  

 

This model railway program is named after a place in England because the name has a nice ring to it. The program is designed for a Raspberry Pi or linux/windows laptop to communicate with an Arduino Mega via USB. The Arduino in turn is connected to 32 isolated relays (4 banks of 8 relays). There are 12 track controls and 8 auxiliary controls, where track (forward, stop & reverse) uses two relays and auxiliary uses one relay.

 

The Lincolnshire Railway Program runs under Mono and sample code is shown below. There is also code for the Arduino. Because of the nature of the .NET SerialPort, commands are executed within half a second or so, however more investigation into improving command response times is ongoing (Flushing the basestream does not seem to result in an immediate serial send/write and so it waits to time out before sending, furthermore the timeout provided “WriteTimeout” is the time after which the write operation will not be completed rather than after which the message will be sent).  Digital and analogue sensor readings are updated every second or so at present.

 

The new LincolnCode language is based on four words per line, however the fourth word can contain several tokens or subwords separated by dashes. The basic idea is that the program is a chronological sequence where the first word is the time from start that the command executes. The second word is the command name e.g. track, followed by the ID and then the value e.g. “00:00:05 track 5 reverse”.

 

There is a section at the beginning of the program where call-backs are set up. These are triggered every second where some are triggered based on a sensor reading and they may be turned off by code. There are also instructions to occur less often or for a set number of calls. These values may be altered at any point in the code.

 

Instructions can be executed conditionally base on track state, auxiliary state, sensor state, analog input state and whether a callback has counted down to zero and stopped.

 

There are

  • 12 track IDs
  • 8 aux IDs
  • 24 non-conditional callbacks
  • 12 positive sense callbacks
  • 12 negative sense callbacks
  • 12 digital inputs or sensors
  • 16 analog inputs
  • 6 analog or pwm outputs

 

The mono exe file for LincolnCode will be available for evaluation soon. This Lincolnshire railway program and the C code for the Arduino mega will be completely functional as no registration is required. If however you use the program for a project or on an ongoing basis then some remuneration would be fair.

 

Sample LincolnCode program (designed to show syntax available)

00:00:00 callbackif 4 once-3   // check sensor 4, trigger once

//00:00:00 callbackifgap 4 3

00:00:00 track 0 stop

00:00:00 aux 0 off

00:00:00 program 0 stop

00:00:00 callbackif 4 end

 

00:00:00 callbackifnot 3 once-3  // check sensor 3 off,

//00:00:00 callbackifnotgap 3 2

//00:00:00 track 2 forward

00:00:00 sense 2 if 

00:00:00 track 1 forward

00:00:00 sense 2 else

00:00:00 track 2 reverse

00:00:00 sense 2 end

00:00:00 callbackifnot 3 end

 

00:00:00 callbackif 9 repeat  // check sensor 9, trigger continuously

00:00:00 callbackif 9 ignore

00:00:00 track 1 stop

00:00:00 callbackif 9 end

 

00:00:00 callback 20 repeat  // trigger continuously

00:00:00 callback 20 ignore

00:00:00 track 1 stop

00:00:00 callback 20 end

 

 

00:00:05 track 3 forward

00:00:05 track 5 reverse

00:00:05 callbackifnotgap 3 1

00:00:15 track 7 stop   

00:00:15 callbackifnotcount 3 repeat // reset counter

00:00:15 callbackgap 20 3

00:00:17 track 0 stop    //stop all tracks

00:00:18 aux 0 off       //turn all auxiliaries off

00:00:18 callback 20 ignore

 

00:00:19 pwm 0 0

00:00:19 pwm 3 125

00:00:19 callback 0 ignore   // disable only and all non conditional callbacks

00:00:19 sense 3 if 

00:00:19 track 2 forward

//00:00:19 callbackifnotgap 3 1

00:00:19 sense 3 ignore 

00:00:19 trackstaterev 6 if 

00:00:19 track 2 stop    

00:00:19 trackstaterev 6 end 

00:00:19 sense 3 else

00:00:19 track 2 reverse 

00:00:19 aux 2 stop

00:00:19 sense 3 end 

00:00:19 callbackcount 20 once-2

//00:00:21 callbackcount 21 once-2

 

00:00:20 analogread 15 if-200-300

00:00:20 track 2 stop  

00:00:20 analogread 15 end

00:00:20 analogread 14 if->-300

00:00:20 track 2 stop  

00:00:20 analogread 14 end

 

00:00:21 sense 4 ifnot 

00:00:21 track 2 stop  

00:00:21 callbackifnotexp 3 if

00:00:21 track 5 reverse

00:00:21 callbackifnotexp 3 else

00:00:21 track 5 forward

00:00:21 callbackifnotexp 3 end

00:00:21 sense 4 end 

00:00:21 callbackif 3 restore

00:00:21 callback 20 restore

00:00:21 callbackexp 20 ifnot

//00:00:21 callbackexp 20 ifnot

00:00:21 track 2 forward  

00:00:21 callbackexp 20 end

 

00:00:22 callbackifnot 0 restore

00:00:22 sense 4 ignore 

 

00:00:23 sense 4 if 

00:00:23 track 2 stop    

00:00:23 sense 4 end 

 

00:00:23 trackstate 6 if 

00:00:23 track 2 stop    

00:00:23 trackstate 6 end 

 

00:00:23 auxstate 5 if 

00:00:23 track 3 stop    

00:00:23 auxstate 5 end 

 

00:00:24 sense 4 restore  

   

The LincolnCode language is claimed by Copyright © 2022

 

 

Websites, Facebook advertising, Arduino robots, Raspberry Pi and phone applications, Music notation and MIDI, Tutoring, Automatic back-up, Networking, Simple web invoicing using secure HTML, Standard Gcode Programs for lathes, Automated G-code, Linux, Windows and Mac administration, Auto-mated Documentation including Jobsheets and invoicing, Database applications, Everyday computer and device problems.