View Full Version : Sharing a Serial Port

March 17th, 2003, 07:59 AM
Scenario: I have a serial device (actually a HomeVision home automation controller) which I want to control using Girder most of the time, but it also has its own windows application which I need to use occasionally to program it. Secondly, I use Windows XP and want this to work from multiple user accounts with “fast user switching”. Only one program can have the serial port open at a time.

Part 1 (one account, all Windows Versions): The solution requires Mark Fiechtner’s Generic Serial Support plugin and Ron’s AlarmTimer. Having got the device set up and running with Girder via Mark’s plugin, I did the following: Firstly I replaced the shortcut that normally runs the devices PC client with one that runs Girder’s “event.exe” program specifying my own event string and –silent. You can even change the icon to the one in the original client program so it is indistinguishable from the original! In Girder I added a MultiGroup which responds to my new event string by first doing a “disable device” in the Generic Serial Support, then uses OS Execute to start the client program, then starts an AlarmTimer with 10 seconds timeout and repeat. On End, this timer runs a Window Exists command targeted on the client programs main window. If the window does not exist, it runs another multigroup which first stops the timer and then does Enable Device in Generic Serial Support.

With this setup, Girder has the con by default, but when I start the client program, Girder backs off until it sees that the client has been exited whence it takes the con again. From the users point of view it looks exactly as before.

Part 2 (multiple accounts in Windows XP): this solution additionally requires Ron’s SessionSwitch plugin (or my forthcoming re-write of this). I added a command which responds to CONSOLE_DISCONNECT by doing a Disable Device. A MultiGroup responds to CONSOLE_CONNECT by waiting 5 seconds (Wait on the Window tab) and then Enable Device. I found that the wait was necessary for reliable operation, presumably because sometimes the CONSOLE_CONNECT is processed before the CONSOLE_DISCONNECT otherwise. Using Ron’s plugin, I had to edit the GML file to get these session switch events, prompting my own re-write which adds a UI. Also, the shipping version of “event.exe” did not work with multiple sessions. Ron kindly did a quick fix for me which I assume will be shipped with the next version (but you could ask him nicely!).

Writing this down, it occurs that the above will fail if I do a session switch while the client program is running – best fix will probably be to close this on CONSOLE_DISCONNECT.

July 20th, 2003, 11:40 PM

John Hind has since written a plugin (for Part 2, above) that supersedes Ron's SessionSwitch plugin. John's enhanced version is called XPPlugin.

However, you won't find XPPlugin on this website (at least I couldn't). Fortunately, you can download a copy that includes instructions and an already compiled DLL from the following URL:


Here is what I have in my Girder GUI:
DisableIt (single command), select the Girder Tab,
Disable Device, Device 201
(you specify your own device number
(found in Settings - Plugins))
EventString: select XP Support from the dropdown
then click Learn Event then select
from the dropdown.

EnableIt (multigroup command)
Wait: select the Window Tab, Wait, 5000 for Timeout
Enable: select the Girder Tab, Enable Device, Device 201

Save the GML file even if Girder doesn't indicate that the file needs to be saved. Logoff all other users. The Girder program shortcut should be in your "All Users" startup folder, not in only one user's startup folder.

Now it should work. It works very well for me. The only thing that I don't understand is why the initial user session doesn't contend with the new user session over the serial port when the CONSOLE_CONNECT message is broadcast by Windows. Anyway, during my initial testing at least, the new user session is always able to "lock" the serial port for its instance of Girder without any interference from the original user session. This is good news.

After seeing the following post in this topic, I realize that I incorrectly thought that all of the plugins on this site were on the Developer page at http://www.girder.nl/developer.php. My mistake. :)

July 21st, 2003, 04:18 AM
XPPlugin is also available from this site at:


It's the last plugin on the page.

The reason why the CONSOLE_CONNECT does not cause the two instances of Girder to contend is that the message is set to be sent only to windows in the console effected.