Wednesday, August 14, 2019

Portable freight management program


Whilst clearing out the cupboard under the stairs, I came across an old laptop bag I had used about twenty years ago. Tucked into one of the pockets was my old and trusty Psion 3a palmtop computer. I took out the leaky AA batteries and inserted a couple of new ones, only to find it worked perfectly.

The backup battery had long-since run out and so there was no evidence of my past life in the computer's memory but I remembered what a joy the Psion had been to use and how it included a reasonably powerful and highly accessible programming language (OPL) for creating your own apps. I decided to investigate whether I could program it with a version of my freight handling program. (see My Freight Handling Computer Program). Well, after dusting off my old OPL programming skills I'm pleased to report I now have a fully functioning portable freight management device which saves me having to fire up the laptop and print out hard copies of goods traffic manifests for each running session.

For those unfamiliar with Psion Series 3 computers, they were clamshell devices developed in the early 1990s with a small LCD screen and a rubberised keyboard. In addition to the programming language; a database, word processor, spreadsheet, calculator, agenda and alarm clock were included as standard. For the time, their onboard memory capacities (eg 128k, 1Mb, 2Mb) were reasonably substantial with expansion slots for memory cards and additional software packs.

My Psion 3a has 1Mb of memory capacity which is more than adequate to run the freight handling program. I also have a couple of 512k memory cards which means I can back-up the database and program - just in case!

The wagons database

I like to keep things simple and so the database for the wagons has only the following fields:
  • Number - The number of the record, rather than the number of the wagon
  • Description - A description of the wagon (max 40 characters)
  • Wagon ID - A unique identifier for the wagon (eg OP8 = Open wagon #8)
  • Type - The type of wagon. This ise used to determine the possible destinations it might have.
  • Location - The present location of the wagon on the railway
Here we can see the entry for Open Wagon No. 9 - which is presently located at Bickerton station (BN)

 And here we have the entry for wagon number 43, a flat wagon with tractor load, presently located at Peckforton Station (PK).

It's very easy to set up a database on the Psion and to search for and amend entries. Accessing and updating database records is also relatively easily accomplished within the programming environment.

The structure of the main program

I decided on three main components for the structure of the main freight handling program; a menu, a procedure for generating the freight traffic and a procedure for managing wagons at each station on my railway.

The Main Menu

The top half of the menu provides access to four utility procedures (see below), while the lower half invites me to create either a Pickup Goods or a Mixed train. Pressing either P or M on the keyboard takes me to the Freight Train Generator procedure.

The Freight Train Generator

This procedure uses a simple set of parameters to decide which wagons need to be moved where on the system.

There are five stations on my railway, plus the Copper Mine, to and from which wagons can be sent. Beeston Market is the main station on the railway - the interchange with the main line railway and hence the rest of the world. All wagons travel to and from this station at some point. Coal wagons are loaded up at Beeston Market before being despatched to any of the four other stations. A livestock market is also located at Beeston Market and so cattle wagons, sheep wagons and any other agricultural-related wagon loads will need to travel to and from the station.

There is a brewery at Beeston Castle station and so wagon loads of barrels, together with malt and hops are sent to this station, while barrels of beer are delivered from Beeston Castle to any other station on the system - all the communities served by the railway have pubs.

At Peckforton, there is a sawmill and also a flour mill.

Local fruit farms use Bulkeley station and so a regular supply of closed vans is needed to transport this cargo at peak periods during the year.

In addition to despatching copper ore and spoil, the Copper Mine needs regular supplies of fuel oil, pit props and explosives.

General merchandise such as building materials, groceries, fuel oil, coal and special deliveries are transported up and down the line.

The freight generation procedure picks wagons at random from the database and then decides where they should be sent, based on the above criteria for goods traffic requirements. Once a possible train has been generated, it is presented:

I can then decide to accept this train or generate an alternative .....

.... until I am happy with what is on offer.

Once accepted I am then taken to the next procedure where the freight movements can be managed station, by station.

The Stations Procedure

Let's assume, the pickup goods will be starting from Beeston Market. Pressing the 'M' key on the menu screen ..

.... allows me to see which wagons will be departing from or arriving at the station via the Pickup Goods train.

This enables me to see which wagons need to be marshalled into the train - in this case, Van 3 and the bolster wagons to be sent to Peckforton, and Open Wagon 3 and cattle wagon 2 to be sent down the line to Beeston Castle.

Once the train has been made up, when it reaches Peckforton, for instance, I can then see what needs to be received and despatched from this station.

Pressing the relevant key on the keyboard allows me to show that any particular wagon has been delivered to the station successfully (signified by the wagon code being replaced with OK).

This updates the database, shifting the relevant wagons to their new location.

On return to Beeston Market, if everything has gone according to plan, all the wagons to and from the station will be shown as delivered and the whole process can start over again.

The Utilities Procedures

The four utilities procedures accessible from the main menu allow for blanket manipulation of the records in the database.


As the name suggests, this procedure sorts the records in the database into numerical order based on the record number field. As each wagon is moved to a new location, its record is appended to the end of the database and so, after a while, the records become jumbled. This makes it easier to browse through the records in the database app.


This resets the location of every wagon (apart from those Out of Service), to the main station (Beeston Market). This is useful at the start of the season thus enabling the system to start from scratch.


This procedure presents a list of all the wagons on the railway showing their present location.

This is useful at the start of a session to make sure each wagon has been correctly positioned before freight operations commence.


This procedure randomises the locations of the wagons, based on the criteria set out above. This procedure will prove useful at the start of a season or on occasions when I fancy a change.


OK - so my Psion computer is not what you'd call 'state of the art', but it is functional and pocket-sized. It does the required job and as the programming language is easily accessible I can modify and extend the program in the future if necessary. For example, I'm thinking of adding a 'Specials' option to the freight train management procedure to generate movements for special trains such as the Market Day Special and a Fruit Pickers Special. For now, however, I am happy with the sort of freight movements which the program throws up and the way if offers me the facility to change things on the fly.

I have noticed that Psion palmtops such as my 3a can be bought on eBay for as little as £20 (20GBP) and so, if you wanted to follow in my footsteps, it is possible. I'd be happy to share the code if only I could discover a way of interfacing my old RS232 lead with my USB equipped laptop. I have tried, but with only limited success.

If I was more experienced with programming apps for phones etc., I might consider writing an Android version, but I struggle to see the screen of my mobile phone when out in the garden and so I'm not convinced it would be any more sophisticated than I have produced on my Psion.