Thursday 2nd April, 2015
The hitch-hiker's guide to raildriver.dll, part 2: more functions for your plugins. There are three other functions that you as the plugin can call to extract information from the simulator. I'm not going to give full examples for these because they're fairly straightforward. I've updated RailDriver.cs in the previous post to include these functions.

GetRailSimConnected does exactly what it says on the tin. Note, however, that this relies on a flag that is stored in the DLL. It is quite possible for a railway simulator to go away and not unset this flag. Thus, don't use this as a way of predicting whether GetRailSimValue will block, or whether the rail simulator is actually there.

Here might be a good place to talk about something mildly contentious that I did in the demos in the previous posts. Note that they call SetRailDriverConnected(true) but they never clear that when they leave: they never call SetRailDriverConnected(false). The reason for this is that this, too, is implemented as a flag inside the DLL. If you have multiple programs talking to the DLL, and one of them calls SetRailDriverConnected(false), then the rail simulator is quite within its rights to stop talking to all of those programs.

In the general case, in fact, the DLL may not behave at all well if more than one plugin uses it at once. If you are just sending control traffic in using SetRailSimValue, then this is likely not to be a problem: later changes to any given control will override earlier ones, and the rail simulator will just pick up the latest. However, if you are calling GetRailSimValue, be careful! If two plugins call GetRailSimValue at the same time, and the rail simulator is being slow, then one of the requests will get lost. Caveat haxor.

Returning to the point:

GetRailSimLocoChanged returns true if the simulator has changed locomotive since the last time GetRailSimLocoChanged was called.

GetRailSimCombinedThrottleBrake returns true if the throttle and brake are combined in one lever on the locomotive currently being simulated, or false if they're not.

posted by Rob Mitchelmore, 18:54 (anchor)