Xinput Game Controller Raildriver Dll

Discussion in 'TSW General Discussion' started by Michael Huggins, Sep 21, 2021.

  1. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Hi Guys,

    I have added a new version of the DLL that can now take a XInput game controller input. With this you can map your game controllers and use directly as TSW2 analog inputs.

    https://github.com/skaako/raildriver/tree/main/XInput

    This allows game controllers to be used. I use x360ce https://www.x360ce.com/ to map my controls to an emulated Xbox 360 Controller. Use anything other than Controller 1 as this controller is mapped to the usual Train Sim World 2 controller functions. The DLL will pickup only one controller that is not mapped to controller 1.

    I have tested it with a PS4 controller mapped to Controller 2 for example to test it. Going into the Raildriver Calibrate settings in TSW2 will allow you to check it.

    Here is how the DLL interprets the game controller axis...

    Reverser - Left Thumbstick X
    Throttle/Brake - Left Thumbstick Y
    Automatic Brake - Right Thumbstick X
    Independent Brake/Bail-off* - Right Thumbstick Y
    Rotary Switch 1 - Left Trigger
    Rotary Switch 2 - Right Trigger

    *Note: The bail-off control on the original Raildriver is a 0-255 analog value like the rest. I have set it up so to use bail-off hold the DPad Up Button. The Bail-Off value will be that of the Right Thubstick Y and Independent Brake value will be 0. (Let me know if this needs work as I'm not famililar with the outputs of the actual Raildriver)
     
    Last edited: Sep 21, 2021
    • Like Like x 7
    • Helpful Helpful x 3
  2. marvin.lenk760

    marvin.lenk760 New Member

    Joined:
    Sep 26, 2020
    Messages:
    8
    Likes Received:
    4
    First of all thank you for your work. Iam eagerly waiting for some sort of joystick support to get my real world throttle lever (that i mounted into the desk) working with TSW. Every - truely every - other simulator i use supports input devices (other then a poor non configurable gamepad). So i do have this piece of Equipment sitting in front of me, and have to use the old fashioned keyboard again everytime iam willing to play TSW. Thats a shame and in my opinion degrades TSW from beeing a simulator to just a game. But, enough of rant here :)

    I replaced the PieHid64.dll with yours, but TSW 2 keeps crashing now while loading! When i revert to the original dll everything works normal again. Any thoughts about this?

    Unhandled Exception: EXCEPTION_ACCESS_VIOLATION reading address 0xffffffffffffffff

    ntdll
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    TS2Prototype_Win64_Shipping
    kernel32
    ntdll

    Marvin
     
    Last edited: Sep 21, 2021
    • Like Like x 1
  3. JohnHedgehog

    JohnHedgehog New Member

    Joined:
    Aug 27, 2020
    Messages:
    14
    Likes Received:
    9
    I am loving this concept, but I seem to have the same issue with the game crashing at start-up, do you have some tips for troubleshooting?
     
    • Like Like x 1
  4. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Hi Marvin and John. Sorry that it is crashing on your system. I have just made sure the one on Github is working by copying it into the folder from scratch and it loaded the game fine on my system. This was without any controllers or emulators plugged in or open.

    If you don't mind, could you try the serial port version of the DLL and see if that one has the same result?

    One thing to mention is that in the instructions I changed the drive letter of the install folder. On my system the installation is in my R drive which is just a separate hard drive with drive letter R. I'm not sure if your installations are on C drive and if that would cause an issue or not.

    I had a few crashes early on in the testing but the crash report on mine showed more information. Let me know how it goes or if anyone else has had this issue or success.
     
  5. marvin.lenk760

    marvin.lenk760 New Member

    Joined:
    Sep 26, 2020
    Messages:
    8
    Likes Received:
    4
    Hi Michael,

    Tried the serial port version of your DLL. Unfortunately with the exact same result. I do not have any other informations/logs other than what i had posted.

    I run Win10, x64, TSW2 (Steam Version) is installed on Drive D:\
     
    • Like Like x 1
  6. JohnHedgehog

    JohnHedgehog New Member

    Joined:
    Aug 27, 2020
    Messages:
    14
    Likes Received:
    9
    Hi, I have also tried to run the serial port version but the game still crashes at start up.
    FYI I run Windows 10 (Steam) and I have the game installed on my C: drive.
    I tried using my Arduino and potentiometer with it but I have a feeling that either my Arduino or pot is faulty, as I am unable to read any values from it. What Arduino do you use and what resistance does your potentiometer have? I am making some plans to make a custom controller based on your serial port version.
     
    Last edited: Sep 23, 2021
  7. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Hi guys. That's a pain. If I get time this weekend, I'll do a fresh Win10 install and TSW2 to see if I can reproduce the problem. I looked in the forum and saw some were getting that same crash report from certain routes while playing but can't see why that would make it crash from the beginning.

    I'm on Win10 Pro x64 21H1 with an admin account. GPU is GTX1070 with GeForce driver 472.12.

    I'm using a Leonardo as it has built in USB. This is so I can use it in the serial port version or the XInput game controller version. The standard Arduino or Mega will only work in the serial port version. I'm using a 10k pot for my testing. It shouldn't really matter about the resistance but make sure it is a linear pot. The Arduino Leonardo analog inputs are 10bit so you should read a value of 0-1023. You then map this to 0-255 as that is what the Raildriver DLL outputs to the game. I would suggest testing with the analog input example first to make sure it's all working.

    The pot I'm using is from another project and has a resistor inline with the voltage in so my mapping is different.

    val[1] = map(val[1], 0, 388, 135, 230); Mine is mapping 0-388 (For my pot) to 135-230 (This is so I have one pot just for the throttle half of the combined throttle/brake that's on the Raildriver controller. I Limited my upper value to 230 as above this value seemed to be a deadzone.

    val[1] = map(val[1], 0, 1023, 135, 230); This would be how your one should look mapping 0-1023 to 135-230

    val[1] = map(val[1], 0, 1023, 0, 255); This would map the complete range of the control. For the other controls or if you want the combined throttle control on one pot.

    I'll look at making a blank DLL with all the functions to see if that causes the same crashing issues on your machines.
     
  8. JohnHedgehog

    JohnHedgehog New Member

    Joined:
    Aug 27, 2020
    Messages:
    14
    Likes Received:
    9
    Thanks a lot for your help! If you need any extra help with testing please let me know as I am eager to get this working :). If it helps I can send you the crash dump files generated by Unreal when the game crashes. If you want them please let me know.
     
    • Like Like x 1
  9. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Hi John, No problem. If you could send me the dump file would be great and can have a look. It's not my area of expertise so if anyone else has any suggestions would be great too.

    Just wondering if you are running any other mods or anything? I should have that test DLL tomorrow hopefully so would be good to see if you get the same result with that.

    Cheers
     
  10. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    I have made a blank DLL if you could try and see if you get the same result?

    https://github.com/skaako/raildriver/tree/main/Blank

    I just want to see if it still crashes your game on startup. I'm running a complete fresh install with no mods or modifications to engine.ini
     
  11. marvin.lenk760

    marvin.lenk760 New Member

    Joined:
    Sep 26, 2020
    Messages:
    8
    Likes Received:
    4
    I've tried the blank dll, still crashing.

    I really don't have a clue. I never had any crashes before (with the original dll)
     
  12. marvin.lenk760

    marvin.lenk760 New Member

    Joined:
    Sep 26, 2020
    Messages:
    8
    Likes Received:
    4
    Okay, thats strange... I managed to get TSW running with both, the blank dll and the Xinput dll as well.
    It worked flawless right after i installed Microsoft Visual Studio 2019 including C++ and Unreal Package!
     
    • Like Like x 1
  13. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Hi Marvin. That's great to hear you got it working. That explains part of the issue as when I loaded TSW2 on the second machine, I already had VS19 installed. I wonder if it's because I'm doing debug instead of release or something. I'll have to do some more testing this weekend to see if I can get it to work on a fresh machine. I developed it in VS19 but it shouldn't require any of the UE dependencies.

    Let me know how it goes as I haven't had a chance to build much more of my controller.

    Cheers
     
  14. marvin.lenk760

    marvin.lenk760 New Member

    Joined:
    Sep 26, 2020
    Messages:
    8
    Likes Received:
    4
    I've made a test, and it worked as intended as far as i can tell. At the moment I can't really use it however, cause i programmed my throttle lever to mimic an XBox controller already which means that it will interfere with the native xbox controller support built in TSW. So my "Xbox controller" (the Lever on my Desk) accidently pans the Camera, its Sifa Button or the Emergency Brake notch forces the game to the "do you really want to quit?" message and so on...

    I may have to change my lever from an Xbox device to an regular Joystick, so that TSW will not recognize it as input device anymore. I could then use a virtual mapped device with your dll. But therefore i have to rewrite/recompile my lever from Xinput to Directinput, and also have to change a bunch of simulators that are already finetuned to my Lever. One of them only works well with Xinput Devices, so i would also have to use another virtual device here...

    It would be so easy if i just could force TSW to ignore the xbox controller, but i guess that there is no way to set this up.
     
    • Like Like x 1
  15. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    I had the same issue the first time I tried it with my Xinput controller I made with my Arduino Leonardo. With x360ce you can add a Test Device to Controller 1 then add your controller to another 2 - 4.

    This was a reason why I was looking to go back to the Serial Port version personally as I don't have a lot of existing controllers I want to use with TSW2. Sometimes the controller ID's jump around and requires a restart to get them back to normal. I think this is a Windows issue so watch out for it as it took me awhile to figure out what had happened.

    TSW2 will pick the first controller (Controller 1) it sees for the main controller. Then the extra controller should be picked up by my DLL. My DLL skips Controller 1 and looks to see if there is a controller on ports 2 - 4.
     
  16. marvin.lenk760

    marvin.lenk760 New Member

    Joined:
    Sep 26, 2020
    Messages:
    8
    Likes Received:
    4
    Okay. I made an Directinput device that get sent via x360ce to TSW as Controller2. It worked! Throttle Lever or Combined Lever moves according to my real world counterpart. Thats great so far.
    But i encountered a bunch of Problems. First i noticed that TSW acted weird - i could drive without the reverserhandle plugged in. But maybe the raildriver calibration setting (have no reverser assigned) sets it into an forward position, and i didn't notice because i had not applied the virtual handle in the Loco.

    But whats more of a serious problem for me: My FPS dropped from 55 Frames with the original dll to 24 with your dll. TSW started stuttering, even the sounds, and TSW got very heavy on my CPU - from 20-30ish to ~100% (i7 8700K, all cores @4.8 GHz).

    So, something seems not right here. Maybe you can check if you see decrease in your performance as well.
     
  17. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    What loco were you driving as that is strange. I usually use the loco's in Sand Patch Grade and couldn't get the loco throttle to even move in the game if the handle wasn't in.

    I'll do some tests regarding the performance on both the XInput and Serial versions. On the XInput version it might be reading from the controllers too often as I didn't put any delay between reads.
     
  18. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    I've uploaded a revised version that should improve the performance. It's in the XInput folder on Github. I modified the code so it's only reading the inputs 20 times a sec. Testing the original DLL I saw a 15% CPU hit running the DLL by itself. Now with the change in code I see no difference. Let me know how it goes on your system.
     
    • Like Like x 1
  19. spoorzicht#7424

    spoorzicht#7424 New Member

    Joined:
    Dec 19, 2021
    Messages:
    2
    Likes Received:
    0
    I really love this idea to use the DLL to create a custom interface. I used it to create a browser interface served on a noceMcu to control the trains with sliders on my ipad. I have no problems with crashes and so on. But I have another problem with the timing of writing to Serial. If I do it to slow the controllers hick all at once to 0 kind of random from time to time. When I do it to fast it looks like some kind of buffer got filled and the controllers start to act slower and slower.

    I'm wondering if it is possible to change the DLL so that it uses old values when there's no new information available or so.

    This speed output you write about on Github, I think it is useful to build a cruise control for trains without afb so maybe you can look into that as well.
    Last but not least: I was wondering how you managed to edit this DLL and if this is possible for me to do as well?

    What are you're thoughts about this?

    Jerke Kloek
     
  20. spoorzicht#7424

    spoorzicht#7424 New Member

    Joined:
    Dec 19, 2021
    Messages:
    2
    Likes Received:
    0
    These timing part struggles I talked about are over since I used a different type of nodeMcu with another UART controller.
     
  21. skysailor98*

    skysailor98* New Member

    Joined:
    Dec 24, 2021
    Messages:
    1
    Likes Received:
    0
    The controls work beautifully, so thank you for that! However, I have an issue where my controller overrides my mouse controls and because of this, I get massive framerate drops whenever I use my mouse. It is also impossible to navigate through menus.

    I have assigned my controller to Controller #2 on X360ce, but it doesn't make any difference
     
  22. gtaboncer

    gtaboncer New Member

    Joined:
    Dec 25, 2021
    Messages:
    1
    Likes Received:
    0
    I have registered here just to say a big thank you to Michael. About a day ago I was thinking that there should be a way to emulate a RailDriver device input somehow. Did some googling and here you are with this awesome solution!

    Frankly, I did have the same issues like skysailor98 with the Xinput dll. Looks like even if I map my throttle to xbox controller 2, TSW2 still finds it and tries to use it as a regular xbox controller. I also get massive fps drops when that happens. As a workaround I tried to set up 2 virtual xbox controllers with the first being dummy, but this worked halfway and I still got massive fps drops.

    Then I tried your serial port dll version. In order for it to work with my setup, I created a simple utility that gets input from my throttle(Logitech G Saitek Pro Flight Throttle Quadrant) and sends it to a serial port. After fixing some of my bugs and calibrating it in the TSW2 Advanced Controls Settings, it started to work brilliantly. No FPS hits or crashes whatsoever.

    So, thank you so much for sharing your solution with us! With custom throttles working properly now, it brings immersion to a whole new level!

    PS. Currently, Dovetail is just one simple step away from adding support for custom input devices, hopefully they will listen and add it eventually(as it happened with TrackIR).
     
    Last edited: Dec 25, 2021
  23. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    I'm messing about 3D printing some control levers, and want to use them to ...well drive (German) trains.

    Was using TS2022.. as i have TSW2 on the PS5,
    but decided to get TSW2 on the pc to try your DLL out.


    Firstly, thankyou for making this .dll,
    it's people like you who make these sims better, not everyone wants to drive with the keyboard or a game controller with spring return axis (but apparently about 99% of people do use just the keyboard... i read one post where someone was complaining it ruined the immersion that there was no lever on the screen to drag with a mouse aka TS20xx style!!!, and he hated having to move the vie about to virtually grab the levers on the driving console of the simulated train)


    Anyway, as usual, i'm fine with mechanical things, but useless at software/programming, so i'm having a few problems.


    Firstly i tried the main pieHid64.dll, that crashes TSW2 on start up,... i get the same error log as posted in the 2nd post.
    i tried the blank one... same issue.

    Tried the Xinput version, and that dosen't crash TSW2, which is handy as i believe thats the one i need to use a potentiometer connected to an arduino?

    loaded the script onto an arduino uno, serial monitor shows the 2nd output is live, i.e. moving my lever sends different numbers on the 2nd output of the string.

    So i started up TSW2, went into advanced controls, and it has 'raildriver detected' in green...woohoo, getting somewhere,

    But when i try to calibrate it, i get nowhere.

    do i need all inputs to change for it to do a sucsessfull up calibration?

    I've only got a single lever/pot connected to A1 on the arduino atm... as i want to try it with the BR 442, which has a combined power and brake lever.

    Do the levers in the graphic of the raildriver on TSW2 move when you move the 'real' lever to show it's picking up movement?

    Right now, i just click 'accept' to get past the levers i dont have, and move my lever for the throttle one, but at the end it remains 'uncalibrated'

    Any ideas what i'm doing wrong?
     
  24. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    Ok, scrub that.

    i downloaded visual studio 2022, ticked the box for it to include the game stuff, where i spotted the words 'unreal' and after it had installed...

    It works ... woohoo

    the lever can be seen moving in the raildriver calibrate thing in TSW2, and i can move the lever in the train with the lever in my hand.


    i did dig out my old raildriver, and went through the calibration procedure with that, and got a green 'calibrated' result.. but maaan it's horrible trying to drive a German train with the US train style levers (hence why i am 3D printing a set of German train style levers to make my own 'Schienen Fahrer' with half sized levers)


    Got a little issue tho:
    I only have a single pot connected to the arduino, so i cant get a successful calibration...

    but i'm wondering if part of the real rail driver calibration is still present in the system, as i am getting random lever movements... like the wipers and lights will go on and off, the direct brake lever will shoot to emergency, even the lever i do have control over will shoot to full brakes and back randomly.

    i have all other inputs commented out in the arduino code (using a leonardo) so it shouldnt be that sending any random lever position numbers should it? i know not to leave floating inputs for analogue inputs on microcontrollers.
     
  25. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Hi Guys, really appreciate the feedback. Glad to find you are finding it useful. I had been off the forum for a while and were not getting email notifications so apologies for the delay. I am not a programmer and used this as a work training example while in lockdown so though I can share the DLL created I can't really share the source code as it is technically company IP. I haven't had a chance to use it since creating it so all feedback is great but time is limited if any changes are needed.

    I had similar issues with the XInput version so had settled on using the serial port version as it was the original goal. The XInput version was just to see if it could be done really.

    If time permits, I'll look at redoing this if more people are interested. It would be something where an arduino could be used to work as an AFB as you suggested. I created the DLL from scratch using a DLL debugger to work out the references of the original DLL.

    I had all sorts of issues with the XInput version. I could get it to work well sometimes and not others. As I was only intending to do the serial version it might be best to use a controller to serial script as suggested by gtabouncer below...


    Cheers gtabouncer!! That's a great idea using a utility to convert from the controller to serial. I did not originally plan on creating the XInput version and don't plan on continuing further with it.

    No problem at all. I'm glad others are finding it useful and not too buggy! I have been waiting on Raildriver support ever since they talked about it in TSW1. Waited so long then waited until it was released for TSW2. I'd like to think full controller support is only around the corner from Dovetail but the corner might be a very long one.


    Cheers that's great you got it working! I had the same issue when testing it with my Arduino as I only had 2 pots. It's been a while since using it but I think I set the values to their midpoints instead of zero and I'm sure that stopped the inputs jumping around. After I tried it with the XInput version with a PS4 controller using all analogs there was no jumping around either. Even then I don't think I could ever get it to show calibrated. I'll have to set it up again and give it a try.

    One thing I was never sure of is how the brake with the bail-off was suppose to work or what outputs it was to give. There are 2 analog values for that one lever. I guessed it would keep the bail-off value at 0 until it was used and then go to the analog value of the lever but really was only a guess as I had no Raildriver to check what outputs are given to the DLL. If anyone could clarify this would be great.

    Thanks again guys for all the great comments! Would be cool to see some of your custom controls.
     
  26. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    Thankyou once again for writing this little bit of software, i've got some more pots on order and will try and get this working nicely.

    One day we may get built in game controller support in TSW... but will that be in TSW3 or 4 i wonder.

    I kinda wish DTG would team up with CobraOne and integrate something like his "TS20xx raildriver and joystick interface" into TSW2.... that thing has so many features... like the virtual notches, unlimited inputs, overlays that can go on a second monitor etc, it can be as simple or as complicated as you want to make it,


    I'm still learning what can and can't be done with TSW2 for the PC, i started with it for the PS5, bought a few routes, and 3D printed some keyboard keys for a bluetooth keyboard to allow me to drive the trains a little better, but i miss using levers... and the PS version can't even use a raildriver :(

    So i bought the PC version of TSW2, and bought more routes... so have some duplicates now, just so i could use joystick input... then found out it's raildriver only,

    Whilst i do have a raildriver, i hate it, i drive German trains only (plus the london underground stock occasionally) and its just too far from european train driving levers i find.
    So this bail off brake position thing is totally alien to me, no idea what it's for, as it doesn't seem to be applicable to european trains.


    Custom controllers:

    i am in the middle of making a 3D printed and laser cut 'ZugFahrer'
    a sort of raildriver but with German train style levers at 50% scale from the real things (my avatar photo is the driving desk in the BR111 steuerwagen that i went to Germany and bought 10 years ago now... but that lot is in storage until i get a place with enough room for a dedicated games room again)

    I have the the levers working mechanically, i'll be working on the coupling for the air and electric brake levers next, then it'll be designing the 50% size switches for PZB etc.

    Here's a capture from Fusion 360 of the levers i'm making:

    levers.jpg
    I do have a few of these printed out and working (with TS2022) using 'FreeJoy' on a STM32F board to do the talking from the potentiometer and switches and the sim,

    And now i'm playing with them on an arduino uno and your program,

    do you know if it's possible to get send the raildriver keys?

    i found out the other day that on raildriver there's a button for 'close doors' as well as open left, and open right,
    using a keyboard there's just open left and right, and you press the same one again to close them.

    but i also found out that practically every train has different functions mapped to the raildrivers buttons, it's a right mess from the sounds of it,
    so we deffo need some external software that can change the button assignments as we load up different routes and trains, so we don';t have to keep changing the button inserts.
     
    • Like Like x 2
  27. protonmw

    protonmw Active Member

    Joined:
    Mar 18, 2022
    Messages:
    133
    Likes Received:
    91
    Hi, I have the same issue. Arduino is sending the correct string, TSW2 says Raildriver recognized, but there is no axis movement during calibration.
    What exactly components of Visual Studio did you install?
     
  28. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    sorry, only just noticed this Q.

    i installed the "main visual studio community" the free package : https://visualstudio.microsoft.com/downloads/

    And on installing it i clicked the checkbox for 'Game development with C++' which listed 'Unreal' as its components :
    visual studio install.jpg
    Not sure if that last bit is actually needed, but it can't hurt to have on the system i thought.




    One thing, in the arduino sketch, it has stuff that remaps the pots readings.

    that's the :
    val[0] = map(val[0], 0, 388, 1, 64); // I had to remap for how my pot was setup
    val[0] = val[0] * 4; // Was trying to reduce number of steps here

    The above 2 lines are on every input,

    i commented out the first line as it wasnt needed for my 10K linear taper potentiometers (when buying potentiometers, avoid logarithmic ones, they are used for volume controls on stereo's, with those the output is reduced at the bottom/beginning of turning it, then after halfway rises sharply... something to do with how amplifiers work to get the same amount of volume increase throughout the range for the amount you turn the knob...
    so basically buy 'linear taper' potentiometers, with a 10K value and you'll be fine.

    The 2nd line seems to scale the pot input down (or up) to 8 bits (i think, a 0 - 255 value input that the raildriver outputs) please correct me if i'm wrong.

    i am using a board with a 16 bit ADC, so with that line removed i was getting a value of 0 - 16380 which is 16 bits resolution, and trying to calibrate with that resolution i'd get a tiny portion of the potentiometers movement registered, then it goes to full scale as it's gone over the max of 255 that is expected.

    so i changed line 2 to :
    val[0] = val[0] / 16;

    to divide the input 16 bits to 8 bits, and when clicking 'serial monitor' on the arduino IDE, i got a 0 - 255 output when moving the potentiometers from one end to the other, and was able to calibrate the 'raildriver' inputs in TSW2 (still no 'calibrated' message no matter what i do, but who cares, it works regardless)



    I am playing with this right now, on a brand new laptop so i had nothing on here that others should not have if you are using windows,

    just visual studio, and the arduino IDE, and TSW2 of course.

    infact i'm not using an arduino board this time, but an STM32F board, but still programmed with the arduino IDE after i flashed on the arduino bootloader.

    i am a total klutz when it comes to software stuff, so i just followed a tutorial online at :
    https://predictabledesigns.com/introduction-stm32-blue-pill-stm32duino/

    I did this as i wanted to use a STM32F because i am already using one with FreeJoy to 'power' my train levers and drive trains in Train Simulator 2022 (with cobraones joystick interface)

    As nothing like cobraones joystick interface exists for TSW2, i'm using this raildriver workaround,

    So i have 2 STM boards, and swap between them depending on if i am driving in TS2022 or TSW2... a clunky way to do things, but untill we get either access to the trains control files to use something like cobraones joystick interface, or native usb joystick input, these are the kinds of work arounds we must use.
     
  29. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    Are you still about Michael Huggins??

    Wondering if you got anywhere adding the raildriver button support to your .dll,

    I'm slowly progressing with my 3D printed 'Euro RailDriver' i have the levers working via your .dll nicely,

    Driving Train small.jpg

    i have multiple bits of code in my arduino program that changes the lever assignments depending on which train i want to drive... i.e. splits the combined throttle and brake lever into 2 seperate full travel levers for the loco's,
    leaves the power lever combined for the EMU's, switches the loco brake lever to the power lever for the BR112 and so on (ATM i just comment out #define statements, and upload it to the arduino before i start TSW2, bit i'll use a rotary switch to select lever layouts on the fly next)

    I am now working on designing and printing the switches, and would love to be able to assign them to the raildriver buttons, as they do things that keyboard presses don't do.

    like the door open / close method, where the door selector switch is rotated left or right with 2 buttons, then the open / close switch is operated with another 2 buttons, much better than the 'Y' for open / close left doors, 'U' for open / close right doors we have on the keyboard.
     
  30. CobraOne

    CobraOne Active Member

    Joined:
    Jun 3, 2022
    Messages:
    148
    Likes Received:
    133
    Hi Michael I am the creator of the TS Classic Raildriver and Joystick interface
    When you get a chance, I have started a conversation with you regarding your replacement dll for TSW2
    Chris
     
    • Like Like x 5
  31. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Apologies for the delay in getting back into this. I'm aiming to get the buttons implemented which I think I had done already and should be able to put the full source code up for anyone who would like to contribute.

    Will keep you posted!

    Mike
     
    • Like Like x 2
  32. DROGE

    DROGE Active Member

    Joined:
    Jul 4, 2019
    Messages:
    49
    Likes Received:
    101
    Am I right in thinking that this development cannot be used to allow a device such as the Saitek/Logitech Throttle Quad's axes to be assigned?

    Eg.. As CobraOne's excellent program can in TS2022.
     
  33. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    unfortunately not, you need to connect the potentiometers from the levers directly to an arduino, so this is more for people building controllers from scratch.


    CobraOne has been working on trying to get something like what you want working, an API that can read any joystick that is plugged in to the computer and translate it into 'raildriver speak'
    but it's not an easy thing to do, basically interpreting usb joystick signals and translating them into raildriver signals in a way that TSW2 thinks a real raildriver is attached.

    He has managed to get an arduino to 'pretend' its a raildriver, but again this is only of use for people building train driving controllers, as the arduino reads the buttons and potentiometers directly again.


    he is looking at the possibility of using an arduino as a go between box, with a USB HID input shield, the idea being you'd plug your throttle quadrant into the USB HID shield that's connected to the arduino that plugs into the PC, the arduino would read the joystick data and translate it into raildriver speak,

    But not sure how well that will work, if it will work at all... i ordered a USB HID shield to have a play, but it's coming from china on the slow boat <grrrr, seller claimed it was in the uk>
    So i think cobraone would have got his USB HID shield by now, and be playing with it.
    the last few pages of posts on the TS Classic Raildriver and Joystick Interface on the atomic forums is me and him talking about the possibility of getting something to work on TSW2.


    This would all be a hell of a lot easier if DTG could give us an API in TSW2 that works like the one that's in TSC, where you can access the trains data, and thus can control any switch, lever or button that works in the train with any input you like, and also read out data to get things like EBuLa screens working, as well as speedo's, brake gauges, lights that turn on and off with the PZB/AWS etc systems.
     
    • Like Like x 3
  34. CobraOne

    CobraOne Active Member

    Joined:
    Jun 3, 2022
    Messages:
    148
    Likes Received:
    133
    I have received my USB Host shield but haven't had much play time to try it yet.
    What I am hoping to do, now that I am in contact with Michael, is have access to his code for the dll he uses and create a version that will talk to a C# program I create. That program will intercept either a joystick or Raildriver (the same as my TS Classic Raildriver and Joystick Interface) and allow you to assign any lever to any of the Raildriver levers in TSW2, the same with the buttons. You will also have separate profiles for each loco. That way anyone with a Raildriver, Joystick or Arduino acting as a Joystick will be able to use them in TSW2.
    As I say, that is what I am hoping to do.

    As Gazz says, if DTG had created a API similar to the Raildriver.dll, then I could have had this up and running by now.
     
    • Like Like x 4
  35. zappatime

    zappatime Well-Known Member

    Joined:
    Mar 19, 2020
    Messages:
    152
    Likes Received:
    263
    This is great news, I wish you every success, your TS Classic joystick interface is a brilliant utility, combined with a diy controller it transforms the sim, so here’s hoping you can crack this nut between you for TSW2
     
    • Like Like x 1
  36. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    Dang... and i've spent the last few weeks faffing about making a built in train profile selector for my Euro RailDriver:

    Train Selector.jpg Still testing it and writing code for the arduino that runs it, so this is just the raw components in a holding panel i quickly 3D printed.

    But i'll be doing things slightly different, i'm using an arduino Due as it can output multiple HID things at once, like be a joystick and a keyboard, and have a serial output all at once (i hope)
    As i want to try and operate as many functions that are working in the TSW2 trains as possible from my controller, and some functions are raildriver only, some are keyboard only, and some controls need mapping differently depending on the train.

    I may even try and use the little oled screen for speed display, the only thing the raildriver can output in TSW2 :(





    Please DTG, give us the level of access you gave us in TSC to directly operate the controls, and ideally read back variables, not everyone likes to drive trains with a keyboard or a raildriver... raildrivers are for american trains, they are horrible to drive UK and European trains with.
     
    • Like Like x 5
  37. protonmw

    protonmw Active Member

    Joined:
    Mar 18, 2022
    Messages:
    133
    Likes Received:
    91
    Please consider to implement modern tcp connection. Then you are able to split incoming data (from joystick, raildriver, diy simulator, other computers, raspberries, ...) from connection to the sim via dll.
     
  38. gazz292

    gazz292 Well-Known Member

    Joined:
    Jun 15, 2018
    Messages:
    422
    Likes Received:
    874
    TBH, when all we have is a one way interface i'm not sure all that is really needed.

    If we ever get something like the raildriver.dll that train simulator classic has, where you can access the trains data and move the levers and switches, and get feedback on their position along with the data out for EBuLa's and MFA panels, running servos/stepper motors in real gauges and so on,
    then an interface like Zusi has with the TCP thing would be handy, as with so much data going to and from the sim some people need a second computer to run the control interface, or it slows the simulator down too much.
     
    • Like Like x 2
  39. Lokomotiv

    Lokomotiv Active Member

    Joined:
    Jul 30, 2022
    Messages:
    85
    Likes Received:
    134
    Can the XInput version pick up other emulators than the x360ce? Any non Xbox 360 emulators? The reason why I ask is because my TSW2 detects Xbox 360 controller activity even though controller #2 is used in x360ce, and it prioritises Xbox over keyboard which makes keyboard and mouse unusable. Assigning a gamepad to controller #1 in x360ce does allow me to interact with TSW2 without the flickering and control fighting. But using a keyboard and mouse for in game interactions is far easier than fumbling around with a gamepad imo.

    Edit: I guess I found the answer when I looked into what XInput actually is: XInput Game Controller API enables applications to receive input from the Xbox Controller for Windows. :D

    Aside from that I must say that I've really enjoyed using the XInput version together with Saitek throttle quadrants and a rudder pedal (for deadman's SIFA, actuated with FreePIE). Being able to drive a train with hardware is really a game changer. I really appreciate your efforts with this project.
     
    Last edited: Aug 2, 2022
  40. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Hi Guys, I've been away for a while but back in the office now.

    I've just tidied up the Serial version code and uploaded it to Github. This implements the buttons and also allows for faster refresh rate from the Arduino. It should also work without Visual Studio so if someone can test it would be great as all my machines have VS on.

    I haven't worked on the XInput code as I was getting too many bugs in the way TSW handles the controllers and I plan to build some custom hardware at some stage. Have been saying this for the last 5 years but one day!!

    I still can't believe how Dovetail couldn't come up with something other than just Raildriver support. Even then that took them forever. 2 way TCP comms would be great but I just can't see them doing it. It was only by chance my work had to deal with an obscure DLL and lockdown gave me the time to work on that and the Raildriver DLL at the same time.
     
    • Like Like x 3
  41. favorit1

    favorit1 New Member

    Joined:
    Aug 20, 2021
    Messages:
    2
    Likes Received:
    0
    Hi, I've been watching this thread and it's great that it's been revived recently.
    Could you release the source code of the dll? I'm not that skilled in coding but I'm still curious how it works, how it interacts with the game, etc.
     
  42. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Thanks Lokomotiv! Great to hear you are finding it useful.


    Thanks for your interest. I thought I would be able to but it turns out I can't release the source code. Here was where I started when learning how DLL's work and it's a great resource...

    https://docs.microsoft.com/en-us/cp...sing-a-dynamic-link-library-cpp?view=msvc-170

    Then going through the SDK from PI Engineering for the RailDriver give you all the information on how the DLL communicates to the external program. It even comes with a useful test program for checking the DLL...

    http://raildriver.com/support/downloads.php

    Then it's a case of matching the custom DLL's functions and pointers to match that of the original RailDriver DLL.
     
  43. Michael Huggins

    Michael Huggins New Member

    Joined:
    Sep 18, 2021
    Messages:
    21
    Likes Received:
    23
    Thanks for the feedback. I don't have TSW3 yet and was wondering if it would work just the same. Great to hear!
     
    • Like Like x 1

Share This Page