RailPro > RailPro Specific Help & Discussion
Experiments 1: Running RailPro software on Linux using Wine - Part 1
G8B4Life:
Part 1: Introduction, the install and first tests
Obligatory disclaimer
This is not a step by step how-to but rather a commentary of the experiments journey. I don't think I've missed anything in the steps taken that doesn't affect the outcome but I've not included any links etc as it's not supposed to be a step by step how to.
. . .Ok, so why?
Given it seems the there will not be native versions of RailPro software for Linux and Mac anytime in the foreseeable future, and I had a lot of time on my hands due to the Covid-19 pandemic I decided to do some experimentation. I've done experimentation on running RailPro software on alternate operating systems before, both with Wine on Linux and ReactOS but these were failures; Wine had no support for HID devices and ReactOS is based on a version of Windows that RailPro software no longer runs on (I could possibly workaround for that but that's another day).
What started this round of experiments was finding out Wine had come a long way since those early days experiments and now had support for HID devices. I had to try it! For this experiment I ran a 32bit version of Lubuntu (based on Ubuntu 18.04) in a virtual machine (VM) on a old host with not much RAM. By far not the best setup but it's all I had to work with at the time.
. . .The experiment begins...
After setting up Lubuntu in the VM and updating everything I started the journey. Visiting the download page for Wine at WineHQ, the first thing I had to do was to find out which version of Ubuntu my installation of LUbuntu was matched to so I could download the correct version on Wine.
After a little bit of mucking around I found out the version and started the installation process.
In the Lubuntu terminal I downloaded and added the repository key for Wine.
--- Code: ---wget -O - https://dl.winehq.org/wine-builds/winehq.key | sudo apt-key add -
--- End code ---
and then added the apt repository for the correct Ubuntu version for my copy of LUbuntu.
--- Code: ---sudo add-apt-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ bionic main'
--- End code ---
A note at the top of the installation page mentioned that the version of Wine I needed to use required some extra packages that they didn't include so I had to download them separately. Given the choice of two ways to do this I opted to add the repository to Apt the same way as for Wine.
After updating the packages in apt we can then install Wine. For this I chose the stable branch (there is also the development and staging branches, which for non techies basically means beta), also installing the recommend packages.
--- Code: ---sudo apt install --install-recommends winehq-stable
--- End code ---
After this Wine should be ready to go. I had already downloaded the installers for RailPro Assistant and HC Simulator to the desktop. As they were automatically associated with Wine it was just a matter of double clicking the installers.
Well not quite ready to go
When first run, Wine will update it's prefix (configuration). It's at this point some not so well written words made me do the opposite of what I should have done. Wine will look for a couple of packages (Gecko and Mono) and after not finding them ask if it should fetch and install them. According to the installation guide at the WineHQ website you should answer YES here. The way I read the wording in the messagebox made me select no. This resulted in me having to install them later after working out which versions of each I actually needed; another not straight forward exercise because it wasn't specified anywhere.Once the prefix is updated the installation will continue.
Click to enlarge
Looking good. You can ignore the admin notice and just click YES, Windows administrator permissions don't matter here
Click to enlarge
Installation Done!
Will it run? Yes it does, and is connected to the Internet too!.
Click to enlarge
Ok, so it wasn't quite that simple. When I first ran it Railpro Assistant didn't connect to the internet. I had forgotten to change the network adapter type in the VM from NAT to Bridge. For some reason RailPro Assistant doesn't work in NAT mode. I spent more minutes than I'd like to admit pondering why it wouldn't connect in Wine before I remembered about the network adapter in the VM So, with RailPro Assitant able to connect to the internet it was time to see if RailPro Assistant could see HC Simulator when it was running.
Click to enlarge
Success!
Being quite pleased at this point it came to the first real test; can we download anything?
Click to enlarge
Yes we can!
More success. Knowing how RailPro Assistant and HC Simulator communicate to each other this was a pretty big deal to see this work right off the bat running in Wine. So we had gotten Wine installed and confirmed that the software runs in Wine. We we're off to a good start. Next in Part 2; The CI-1, the HC-2b, and getting them working
- Tim
G8B4Life:
Part 2: The CI-1, the HC-2b and getting them working
With both RPA and HC Simulator running it under Wine it was time to find out the answer to the BIG question; can the software see the hardware; and does it work? I did a lot of research from this point as I knew from previous experiments that HC Simulator would not be able to see the CI-1 (or RPA see the HC-2b) with the way Linux permissions work with USB devices, and also that I'd likely have to help Wine know about the devices. Plugging in the CI-1 and passing it though to the VM Linux can see the CI-1 and identify it.
lsusb and dmesg output showing the CI-1
The information given by the dmesg and lsusb commands gave me the information to know which device in Linux was the CI-1, which was Hidraw1 in this case. Changing the permissions for it is easy.
--- Code: ---sudo chmod 0666 /dev/hidraw1
--- End code ---
No, that isn't a bad reference but just the way *nix permissions work, each number represents a user type on the system and the number relates to a set of permissions that the user has in relation to reading, writing and executing (running) a file, directory or device. The number 6 is read and write permissions which is what we need to be able to access the device.
With the permissions changed lets try HC Simulator. Can it see the CI-1?
Click to enlarge
[ Attachment ]
Nope, no luck there
I figured as much would happen but it was worth the shot. Now came the "fun" part. Previous study from years ago when I identified a bug in both RailPro Assistant and HC Simulator that prevented the CI-1 and HC-2b from being detected by RailPro Assistant and HC Simulator on some computers I knew how they both got the information they needed to locate and use the CI-1 and HC-2b. This information was in the Windows Registry and was called from a Windows DLL file. I'd have to duplicate this registry information into Wine manually and hope that the Wine version of that Windows DLL file implemented the functions needed to retrieve the information. Starting off in the Windows Registry I'd had to find where all this information relevant to the CI-1 and HC-2b was. Thankfully that previous knowledge came in handy again. Knowing that USB devices have a vendor id and product id and knowing what they were I was about to search quickly for them.
[ Attachment ]
One of the registry entries for the CI-1
One thing to note about this is that for every different port you plug the same USB device into an entry is created in the registry for it. You can see that I've had the CI-1 plugged into different ports over time. Because there are entries in different places of the registry and the different entries are tied together I'd have to find which entries matched which. In the beginning I did not do this and just duplicated all the entries for the CI-1 and HC-2b (or so I thought) but this was not a good approach and it was messy and didn't work. After some more research to work out how the entries were tied together I redid the exercise methodologically and made a registry file each for the CI-1 and HC-2b that I could import into Wine.
Registry file for the CI-1
--- Code: ---Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{4d1e55b2-f16f-11cf-88cb-001111000030}\##?#HID#Vid_04d8&Pid_f321#6&24b60e9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}]
"DeviceInstance"="HID\\Vid_04d8&Pid_f321\\6&24b60e9&0&0000"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\DeviceClasses\{4d1e55b2-f16f-11cf-88cb-001111000030}\##?#HID#Vid_04d8&Pid_f321#6&24b60e9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}\#]
"SymbolicLink"="\\\\?\\HID#Vid_04d8&Pid_f321#6&24b60e9&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\Vid_04d8&Pid_f321\6&24b60e9&0&0000]
"Capabilities"=dword:000000e0
"UINumber"=dword:00000000
"ConfigFlags"=dword:00000000
"HardwareID"=hex(7):48,00,49,00,44,00,5c,00,56,00,69,00,64,00,5f,00,30,00,34,\
00,64,00,38,00,26,00,50,00,69,00,64,00,5f,00,66,00,33,00,32,00,31,00,26,00,\
52,00,65,00,76,00,5f,00,30,00,30,00,30,00,32,00,00,00,48,00,49,00,44,00,5c,\
00,56,00,69,00,64,00,5f,00,30,00,34,00,64,00,38,00,26,00,50,00,69,00,64,00,\
5f,00,66,00,33,00,32,00,31,00,00,00,48,00,49,00,44,00,5f,00,44,00,45,00,56,\
00,49,00,43,00,45,00,5f,00,55,00,50,00,3a,00,46,00,46,00,30,00,30,00,5f,00,\
55,00,3a,00,30,00,30,00,30,00,31,00,00,00,48,00,49,00,44,00,5f,00,44,00,45,\
00,56,00,49,00,43,00,45,00,00,00,00,00
"CompatibleIDs"=hex(7):00,00,00,00
"ClassGUID"="{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}"
"Class"="HIDClass"
"Driver"="{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\\0011"
"Mfg"="(Standard system devices)"
"DeviceDesc"="HID-compliant device"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\Vid_04d8&Pid_f321\6&24b60e9&0&0000\Device Parameters]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\HID\Vid_04d8&Pid_f321\6&24b60e9&0&0000\LogConf]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_04d8&Pid_f321\5&269a58e2&0&8]
"DeviceDesc"="USB Human Interface Device"
"LocationInformation"="CI-1"
"Capabilities"=dword:00000084
"UINumber"=dword:00000000
"HardwareID"=hex(7):55,00,53,00,42,00,5c,00,56,00,69,00,64,00,5f,00,30,00,34,\
00,64,00,38,00,26,00,50,00,69,00,64,00,5f,00,66,00,33,00,32,00,31,00,26,00,\
52,00,65,00,76,00,5f,00,30,00,30,00,30,00,32,00,00,00,55,00,53,00,42,00,5c,\
00,56,00,69,00,64,00,5f,00,30,00,34,00,64,00,38,00,26,00,50,00,69,00,64,00,\
5f,00,66,00,33,00,32,00,31,00,00,00,00,00
"CompatibleIDs"=hex(7):55,00,53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,\
5f,00,30,00,33,00,26,00,53,00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,\
00,30,00,30,00,26,00,50,00,72,00,6f,00,74,00,5f,00,30,00,30,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,33,00,26,00,53,\
00,75,00,62,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,30,00,00,00,55,00,\
53,00,42,00,5c,00,43,00,6c,00,61,00,73,00,73,00,5f,00,30,00,33,00,00,00,00,\
00
"ClassGUID"="{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}"
"Class"="HIDClass"
"Driver"="{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\\0010"
"Mfg"="(Standard system devices)"
"Service"="HidUsb"
"ConfigFlags"=dword:00000000
"ParentIdPrefix"="6&24b60e9&0"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_04d8&Pid_f321\5&269a58e2&0&8\Device Parameters]
"ExtPropDescSemaphore"=dword:00000001
"SymbolicName"="\\??\\USB#Vid_04d8&Pid_f321#5&269a58e2&0&8#{a5dcbf10-6530-11d2-901f-00c04fb951ed}"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USB\Vid_04d8&Pid_f321\5&269a58e2&0&8\LogConf]
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\0010]
"InfPath"="input.inf"
"InfSection"="HID_Inst"
"InfSectionExt"=".NT"
"ProviderName"="Microsoft"
"DriverDateData"=hex:00,80,62,c5,c0,01,c1,01
"DriverDate"="7-1-2001"
"DriverVersion"="5.1.2600.5512"
"MatchingDeviceId"="usb\\class_03"
"DriverDesc"="USB Human Interface Device"
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{745A17A0-74D3-11D0-B6FE-00A0C90F57DA}\0011]
"InfPath"="input.inf"
"InfSection"="HID_Raw_Inst"
"InfSectionExt"=".NT"
"ProviderName"="Microsoft"
"DriverDateData"=hex:00,80,62,c5,c0,01,c1,01
"DriverDate"="7-1-2001"
"DriverVersion"="5.1.2600.5512"
"MatchingDeviceId"="hid_device"
"DriverDesc"="HID-compliant device"
--- End code ---
I imported the registry entries into Wine and called the "fun" part of the exercise done. Will we be successful with HC Simulator being able to detect the CI-1 now?
Click to enlarge
Still no luck
At this point I figured that those dll functions that were needed weren't implemented in the wine version of the dll file. As I had run a debug trace on that dll while HC Simulator loaded when I checked the debug output I could see that the calls were being made and the information from the registry was being loaded. So what could be wrong? Some more research picked up a clue hidden away in a single blog post from years ago. With Wine there are three ways to detect HID devices; hidraw, evdev and SDL. The blog post was from a user who was seeking help on a game being broken by a Wine update. The solution was to disable SDL as it was being used as the default detection method since the update, which stopped the game working. After disabling SDL the game worked again.
Click to enlarge
Disabling SDL in the Wine registry
Running HC Simulator again we have a Winner!!!
Click to enlarge
But does it work?
Click to enlarge
Throw your arms in the air and say yes! We can control RailPro devices.
With the CI-1 worked out and working, what about the HC-2b? After unplugging the CI-1 and plugging in the HC-2b and passing it to the VM running the dmesg and lsusb commands again gives us the same device identifier in Linux, hidraw1. Because we created a new hidraw1 device we need to change the permissions on it as we did for the CI-1. Loading up RailPro Assistant the HC-2b is detected so it was time for the big test, selecting a file to download would the HC-2b download the file?
Click to enlarge
The file downloaded to the HC-2b without any problems.
Next in Part 3, The HC-1, the old HC-2 and wrapping the experiment up.
- Tim
G8B4Life:
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 be
Once 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.
--- Code: ---ln -s /opt/wine-stable/lib/libwine.so.1.0 /usr/lib/libwine/libwine.so.1
--- End code ---
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.
--- Code: ---rmmod ftdi_sio
rmmod usbserial
--- End code ---
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 enlarge
Yes, it now downloads!
This was finally successful, with the old HC-2 downloading the file without issue.
. . .Wrap up
The 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
William Brillinger:
That is great work Tim, I can't wait to see where this goes in the next experiment!
G8B4Life:
Thanks Bill,
Some light reading for your Sunday morning ? ;) Unfortunately no matter what I did the forum just won't put two of those pictures inline in part 2.
Anyway, Experiment 2 (and 3) is on it's way to me. I still have to get a couple of things to do it though but I do have high hopes for the next experiment, and it should be a much more interesting subject for the group should it be a success.
- Tim
Navigation
[0] Message Index
[#] Next page
Go to full version