Part 3: The HC-1, the old HC-2 and wrapping the experiment up.There's a lot less pictures in this part.
I had actually started this experiment with an old HC-2 because it should have been easier to get this working in Wine than the CI-1 and HC-2b but it proved to be around the other way around. The amount of text and pictures for this part do not do the amount of head scratching, research and typing in commands into the terminal justice.
Plugging in the old HC-2 (the HC-1 would be exactly the same for this) and running the dmesg and lsusb commands gives us a device on ttyUSB0 and not hidraw. This is because the HC-1 and old HC-2 are not USB HID devices like the CI-1 and HC-2b but present to the operating system as a serial device on a Com port, or to put that in a finer detail, a virtual Com port. This is due to them having what's called a usb to serial converter built into them.
It was at this point I had some head scratching to do. There are two methods of accessing FTDI usb to serial converters, a way directly via the virtual com port, and another using the functions in FTDI's third party DLL file, ftd2xx.dll. Both ways seem to have a lot of propriety drivers on Windows to make this happen, which can not be used in Wine.Now if Ring Engineering had chosen to use the directly via the virtual com port method to talk to the old HC's this likely would have been quicker and much easier but they chose the ftd2xx.dll method for RailPro Assistant to access the old HC's. I knew it was highly unlikely that I'd be able to use this Windows dll in Wine, and trying it on the chance confirmed that to be the case so off I was to do more research, starting with FTDI themselves.
FTDI make drivers for many operating systems, and so make the functions in ftd2xx.dll available for Linux in a Linux library as well. This is now the reverse of the issue because RailPro Assisant being a Windows program would not be able to use the Linux version of the ftd2xx.dll. What was needed was a way for Wine to pass those ftd2xx.dll functions calls from RailPro Assistant to the Linux ftd2xx library. The web is littered with posts on various websites from people who want to get serial to usb working on wine and failed but I found a couple of "wrappers" amongst the litter to do the passing but they were all quite old and the instructions likely to be well out of date, if they would even work with the much newer version of Wine that I was using.
To save myself from having to compile code, and running in a virtual machine so security wasn't much of an issue I chose a compiled version wrapper that made reference to the latest Linux ftd2xx library to work with. Starting out, the instructions were definitely out of date, with the file locations wrong for then the files are located today
libwine.so.1 not found, it's no longer in the place that the old ftd2xx.dll.so thinks it should beOnce I had located the location to put the files and created a link from the old location to the new location all was ready to go.
ln -s /opt/wine-stable/lib/libwine.so.1.0 /usr/lib/libwine/libwine.so.1
Success. RailPro Assistant was able to detect the old HC-2 through the Wine wrapper to the Linux ftd2xx library. All that was left to do was to try downloading something.This was a failure. While RailPro Assistant could see the old HC-2 the HC-2 gave that old message "Can not connect" when trying to download. Back to square one.
As I couldn't see what was going on I tried a different wrapper. This one had debug information in it which allowed me to see what was going on. The debug output indicated that ftd2xx could not get a handle on the file, meaning the HC-2. Some more research led me to an old technical note from FTDI that stated that the virtual com port driver and ftd2xx were not compatible on Linux, and to use ftd2xx the virtual com port driver needs to be unloaded.
rmmod ftdi_sio
rmmod usbserial
After doing this the ttyUSB0 device disappears however when running RailPro Assistant the HC-2 can still be detected. Will it download now?
Click to enlargeYes, it now downloads!This was finally successful, with the old HC-2 downloading the file without issue.
. . .
Wrap upThe experiment was a success, I was able to successfully run RailPro Windows software on Linux using Wine, and communicate and use all the hardware as well. This means that there is a viable way to run RailPro on Linux until native Linux versions become available, if ever. I know that probably only interests me but...
It also means that there is likely another free way to run RailPro software on a Mac as well, Wine is available for Mac (some versions excepted) and Mac OS is really just an expensive Linux (both Linux and Mac OS are Unix derived).
While the experiment was a success there is more to do to make the experience better for a ready to go solution that I didn't bother to do for the experiment, like creating rules so one would not have to change the permissions of the hidraw every time a CI-1, HC-2b was plugged in, compiling a new version of ftd2xx and also making a script to do many parts of the setup automatically instead of having to type out every command needed.
I hope you enjoyed Experiment 1. Experiment 1 was a precursor for Experiment 2; hopefully coming in a couple of weeks.
Final thought? There were a lot of dead ends in this experiment. The internet is littered with out of date information on using HID and serial to USB converters. A lot of reading and testing went into extracting the still relevant parts from all the outdated stuff to put together into a working solution.
... and lastly, trying to do this a virtual machine running only 1 GB of RAM is painful to say the least!
- Tim