Tool to connect Serial USB devices to MSFS2020 via SimConnect/WASM using VS2022

ps: Here’s a recent pic of my sim:

1 Like

Hello @TheBeechHouse,

Wow, that picture looks impressive. I hope I can say the same of my simulator within 10… 15 years?

Although I didn’t post anything since quite some time, the project is definitely active. But “only” being 57, I still have a job, which doesn’t leave me “full time” to work on it.

The shortages on the chip-market didn’t help neither. I was ready to build the FCU with the PIC18F45K50 microcontroller, but that chip wasn’t available anywhere (or I had to wait until mid 2023). I took the decision to move to the PIC18F47J53. But then I had to deal with some changes first. The PIC18F47J53 used 3.3V, and my 7-segment digits based on the MAX7219CWG use 5V. I also couldn’t find my LED-drivers for the backlight any longer, so had to start searching the market again. At the end, I could find all my components, but to be sure I built another test-board first. On that test board I also learned how to solder SMD (using soldering station, but also used hot air for the first time). I also discovered that I didn’t have enough I/O, so played a bit with I2C I/O expanders as well. Etc, etc, etc…

But finally, I’m ready for the first build. My FCU PCB is on its way from JLCPCB (my regular stop for PCB manufacturing). I also ordered all my missing components, did some final adjustments on my self-made push pull encoders (added adjustment screws to precisely align the push and pull microswitches), and am now ready for the big build.

So that answers your first question: Yes, the project is active!

About your second question. Would you convert your X-Plane simulator to a MSFS simulator? That would be quite an interesting story (worth a long post :slight_smile:). But then you would rather need my help, instead me needing help from you. So I’m not so sure how to interpret your second question. Of course, your experience on the real build exceeds mine with a factor 1 to 100! Always good to know somebody that has already solved 1001 problems, and who is offering help. Really appreciated, thanks a lot! If I’m ever stuck…

I think it should be perfectly possible to control your hardware through the tool I developed. As long as your Teensy has a USB port through which you can receive and send commands (commands are textual, not even binary), then you are ok. I am now using the PIC18F47J53 microcontroller, but I have tested a lot of my software using Arduino. The main difference is that my MPLAB X IDE (the free of charge IDE used for PIC18F47J53 from Microchip Technology) uses C, and for Arduino I could use C++. Although, I used C in both developments to have some re-usability. I can share you my Arduino source code if you want, and if you need some explanation, I can share some insights as well.

The biggest challenge will be to find the correct commands in MSFS. I am using the FBW A32NX, which is of course different then Beechcraft 1900D. And I don’t know if MSFS has this type of plane available (I could only find Beechcraft type 18). If I’m not mistaken, PMDG had (or has?) a Beechcraft 1900D add-on.

A good starting point to get an idea of the commands is using the SDK documentation that you can find here. And if you haven’t done so, I suggest you read my tutorial mentioned at the beginning of this post. It will give some insights in how my tool fits together. Or maybe you know all this already, and you are the real expert here :laughing:

Once you have the commands, with your programming skills, it should be a piece of cake to gradually convert all your modules. Although, be aware that I have never tested my own tool on a large-scale project. I’m still a bit in the dark regarding performance, and I anticipate that I might need to tweak things in the future when I’m developing my own hardware. Regarding speed, with my PIC microcontroller I can easily run at about 300 commands per second (and the main limitation is the main loop cycling speed - one command per main loop cycle). On Arduino, with comparable complexity, I “only” reached 240 commands per second. Although, these numbers are still very premature. I hope to come with some better benchmarks when my FCU is finished.

Looks like we have quite some things in common. We have about the same age, we both seem to have knowledge of the same languages (I learned Python, but never really used it, but I “speak” fluently C, C++ and C# - and I am familiar with SQL) and we both have knowledge about microcontrollers and other hardware stuff. If you want to stay in touch, no problem! You can also PM me, and give me your email address, which might be easier when exchanging stuff. Up to you.

Marvelous piece of information you had shared! My gratitude for you to share your expert knowledge on the coding. I am currently doing a similar project and man MSFS does cause a headache for developers (Compared to X Plane which are way more developer friendlier). I really suggest Asobo should housekeep the API…

BTW, I don’t think the engines will quit if you turn all fuel pumps off, they will just be gravity fed (Unless your fuel is not deaerated, in which case it may cause vapour locking the fuel line, but then I don’t think FBW has that deep level of simulation) :wink:

2 Likes

Hello Mr. Billiet.
I have problems with USB/Serial connections and your Cockpit Hardware HUB.
I’ve tried many boards like mega 2560 ‘big’ version, mega 2560 mini version and some arduino nano with CH340 USB TTL converter.
Only the ‘BIG’ version of mega 2560 seems to work with the software (i have also tried with different baudrate in the HUB, also 9600) but same problem.
What’s the problem? Simple, the other boards weren’t recognized during the initialization process and nothing appened when i click ‘Connect’.
The board are named different in arduino Sketch but only the normal version of “Elegoo Mega 2560” was recognized and register the vars.

Can you have a clue of what is going on?
Thanks,
Simone

Hello Simone,

Please call me Hans, no need to call me ‘Mr.’ :slight_smile:

Are you using the second version of my CockpitHardwareHUB (see CockpitHardwareHUB_v2). This is a completely rewritten version, and is more robust than the first version. It also includes a detailed user manual. It also has an easy way to send logging to a file, which can be interesting while trouble shooting.

I assume that MSFS 2020 was running for your connection, because that is required.

Honestly, I only have the ‘BIG’ mega myself, so I haven’t tested it with different types. But there should be no reason that it doesn’t work.

Please try with the new version, set ‘Log level’ to ‘info’, and log to a file. You can send me the file via a private message (I assume that is possible?). I am interested in investigating this, because there was another person that sent me some improvement suggestion that has to do with detecting USB devices. If your logging doesn’t provide any results, I might just implement this little change, and we could try if this helps.

Hans

FYI, broken link.

Correction
flybywiresim/aircraft · GitHub

Hi Hans!
Thanks for this fast reply!
I haven’t founded the way to send private message, so i will post here.

I’ve downloaded the v2 but this time is getting worse, i think.
With the same board (and the stock arduino firmware that you provided with HUB v1) that worked with version v1, this time no life of usb connection in the software.
Also the Connect/Disconnect button doesn’t change when connected to SimConnect (via the log box).

I attach the log file (info level):

21/01/2024 20:24:21: Logfile created
-------------------------------------------------
20:24:25:758[0000] - Info - APP - SimClient.SetLogLevel: LogLevel set to Info
20:24:43:315[9999] - Info - CLT - Initializing WASimClient v1.2.0.1 for client 000007AD with net config ID -1
20:24:43:319[0004] - Info - APP - Simclient.ClientStatusHandler: Client event SimConnecting: "Simulator Connecting" - Client status: Initializing
20:24:43:360[0041] - Info - APP - Simclient.ClientStatusHandler: Client event SimConnected: "Simulator Connected" - Client status: SimConnected
20:24:44:366[1005] - Warning - CLT - Server did not respond to ping after 1000ms
20:24:44:367[0001] - Error - APP - SimClient.Connect: Server did not respond to ping, quitting.
20:24:44:370[0003] - Info - APP - Simclient.ClientStatusHandler: Client event SimDisconnecting: "Simulator Disconnecting" - Client status: 18
20:24:44:490[0119] - Info - APP - Simclient.ClientStatusHandler: Client event SimDisconnected: "Simulator Disconnected" - Client status: Idle
20:24:44:491[0000] - Info - CLT - Shutdown complete, network disconnected.
20:24:43:349[-999] - Info - CLT - Connected to Simulator "KittyHawk" v11.0.282174.999, with SimConnect v11.0.62651.3 (Server v5)

Screenshot of MSFS2020 A32NX in execution with v2 software opened.

Hope you can understand what’s going on.

Really appreciate your work!

Thanks,
Simone

EDIT:
I just read that the wasimcommander folder needs to be copied to the simulator’s Community folder.

Now it seems that the connection with the simulator is working correctly but still problems with USB devices.

Even the card that was previously recognized now gives a Timeout error.

I attach the log:

21/01/2024 21:37:14: Logfile created
-------------------------------------------------
21:37:17:112[0000] - Info - APP - SimClient.SetLogLevel: LogLevel set to Info
21:37:18:803[1690] - Info - CLT - Initializing WASimClient v1.2.0.1 for client 000007AD with net config ID -1
21:37:18:807[0004] - Info - APP - Simclient.ClientStatusHandler: Client event SimConnecting: "Simulator Connecting" - Client status: Initializing
21:37:18:831[0024] - Info - APP - Simclient.ClientStatusHandler: Client event SimConnected: "Simulator Connected" - Client status: SimConnected
21:37:18:851[0019] - Info - CLT - Server responded to ping, reported version: 01020000
21:37:18:851[0000] - Info - APP - SimClient.Connect: Found WASimModule Server v1.2.0.0
21:37:18:852[0000] - Info - CLT - Connecting to WASimCommander server...
21:37:18:855[0003] - Info - APP - Simclient.ClientStatusHandler: Client event ServerConnecting: "Server Connecting" - Client status: 6
21:37:18:886[0030] - Info - CLT - Connected to WASimCommander server v01020000
21:37:19:018[0132] - Info - APP - DeviceServer.OnPortFoundEvent: COM12\USB\VID_2341&PID_0042\55732323930351407041 found
21:37:19:089[0071] - Info - APP - DeviceServer.Start: DeviceServer Started
21:37:19:091[0001] - Info - APP - Simclient.ClientStatusHandler: Client event ServerConnected: "Server Connected" - Client status: AllConnected
21:37:19:092[0001] - Info - APP - SimClient.SetLogLevel: LogLevel set to Info
21:37:18:823[-269] - Info - CLT - Connected to Simulator "KittyHawk" v11.0.282174.999, with SimConnect v11.0.62651.3 (Server v5)
21:37:19:280[0457] - Info - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX IDENT = "MEGA BIG A32NX" - "ARDUINO"
21:37:19:613[0332] - Error - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX TimeoutException The operation has timed out.
21:37:20:852[1239] - Info - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX IDENT = "MEGA BIG A32NX" - "ARDUINO"
21:37:21:166[0313] - Error - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX TimeoutException The operation has timed out.
21:37:22:412[1246] - Info - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX IDENT = "MEGA BIG A32NX" - "ARDUINO"
21:37:22:727[0314] - Error - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX TimeoutException The operation has timed out.
21:37:23:968[1240] - Info - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX IDENT = "MEGA BIG A32NX" - "ARDUINO"
21:37:24:286[0317] - Error - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX TimeoutException The operation has timed out.
21:37:25:528[1242] - Info - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX IDENT = "MEGA BIG A32NX" - "ARDUINO"
21:37:25:846[0317] - Error - DEV - COMDevice.GetProperties: 01\COM12\MEGA BIG A32NX TimeoutException The operation has timed out.
21:37:26:866[1019] - Error - APP - DeviceServer.AddDevice: 01\COM12\MEGA BIG A32NX GetProperties failed after 5 times
21:37:26:867[0001] - Error - DEV - COMDevice.StopPumps: 01\COM12\MEGA BIG A32NX Pumps already stopped

Hello again,

CockpitHardwareHUB_v2 works indeed with a different WASM Module. You can even remove the previous WASM Module.

Looking at the logs above, I have the feeling that there is something wrong with your Registration process.

You have indeed sent the command “INDENT\n”, which returns the Device Name and the Processor Type, 2 strings coming from the device. But then there seems some communication issue. CockpitHardwareHUB_v2 will send “REGISTER\n”, and then your device should send all the properties terminated by “\n”. Then you need to send an empty string “\n”. That will terminate the registration sequence.

Ok, the good news is that your device is detected, and that communication is established. You are getting back the DeviceName and the ProcessorType, so that is great! It even repeats this 5 times, which is pretty consistent. So it must be that after receiving the “REGISTER\n” command, your device is not responding. If you don’t have any properties yet, and just want to test the connection on its own, you can also send back just an empty string “\n” (I never tried, but that should work).

Can’t you use your Arduino “Device Monitor” (or something like that) and see if you are getting the “REGISTER/n” command after your device sent the ProcessorType? Just reply this with an empty string to see what this gives.

Hans

Thanks for this! I updated the link with the one you provided in the post.

Ok, now I managed to get the “always worked” board working (I changed a carriage return in the firmware).

However the other cards I just can’t get them to work. I also updated the CH340 drivers to version 3.8 (the latest available).

If I manually try to send commands to the board with the Serial Monitor I can get correct IDENT and properties with \n final. With the HUB nothing happens however. Not even a single log line is generated.

If you have a board with a CH340 USB-TTL converter chip at home you could try to replicate the problem. Virtually all cheap Arduino boards from China have it on board.

Simone.

I found a small solution for the com devices problem.

In Win32_SerialPort we find the “Name” property which contains the name of the device and almost always also the reference COM port.
In the ScanPorts routine I am going to make a regex of the Name property to extrapolate the COMxx string:

string result = FindCOM((string)queryObj[“Name”]);

If it found a correct string of ‘COMxx’, I create the device with its port (return new SerialPortEventArgs).

Now even old devices with (CH340) works and at the same time:

Obviously it’s not a solid and reliable solution but for now I see that it works.

Simone

Hello Simone,

First of all, congratulations with your persistence to make it work! Great job! It’s really nice to see my tool working with somebody else. What do you think of the tool so far? Useful? Handy? Difficult? Overcomplicated? Don’t hesitate to give tips and/or suggestions.

I think that this connection problem is exactly the issue that @CrossWinnd has reported to me a while agoo. The original SELECT statement in the “SerialPortManager.cs” module seems not to work with some FTDI chips.

His suggestion was to use the below SELECT statement in the ‘queryString’ (see method ‘ScanPorts’ in SerialPortManager.cs).

SELECT DeviceID, PNPDeviceID FROM Win32_PnPEntity WHERE Name LIKE ‘%(COM[0-9]%’

I haven’t tried it myself yet, because I don’t have a lot of Arduino’s. As you could read in my posts, I’m using the PIC Microcontroller, which have onboard USB capabilities.

Would you mind to try this solution and let me know if it works?

Oh, and by the way, the ‘SerialPortManager.cs’ is not written by myself. All credits go to @Massey919 - here you find the original version (mine has been slightly adapted).

Greetz,

Hans

Hello Hans,
The tool is great and exactly what I wanted. SimConnect and WASM combined in the same software that I could adapt to my needs.
I’m not a programmer but with a little time and patience I can adapt it to all my needs regarding compatibility with my hardware.

You and Massey919 have done a great job especially making it open source.

Thanks!

1 Like

Thanks for these nice words.

Let’s not forget mpaperno (Max), because it’s his WASM module I’m using. Yep, good teamwork. That’s the advantage of open source - you combine stuff and you learn a lot from eachother.

Did you have the chance to test my suggestions regarding the SELECT statement? Would be nice to see if that works, because I can’t test it myself.

But hey, no obligation of course. I won’t be mad :slight_smile:

In my post for the solution founded i made a mistake.
The current SELECT statement on actual code is:

SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%(COM[0-9]%'

and not Win32_SerialPort.

So the actual statement is the same you had advised to use in the commented lines.

The last (very little) problem is that with this statement it grabs also the bluetooth devices virtualized COM (and i don’t why are so many with only one usb-to-bluetooth dongle).

Even with the parser on DeviceServer.AddDevice, it take like 1 minute to overpass these devices and go on with my Arduino devices.

I’ll spend some fun time on this :slight_smile:

Simone

Thank you for the investigations you do. You said you are not a programmer, but you seem to have quite some knowledge on this. I’m really not an expert on WMI I’m afraid :frowning:

So you mean that now you get a ton of devices? And is it that that takes so much time? Not sure if there would be a clever way to put additional filtering on the SELECT statement? Maybe ChatGPT know? :slight_smile:

Yes, now i get a lot of COM devices because i have a USB-BLUETOOTH dongle for wireless headset and some other bluetooth stuff.
This dongle create a VIRTUAL COM for each paired device (stored in history) on my PC. Of course if i remove the dongle i will get just the USB device attached.

This simple log can help you to understand:

18:10:28:250[0000] - Info - CLT - Shutdown complete, network disconnected.
18:10:30:962[2712] - Info - CLT - Initializing WASimClient v1.2.0.1 for client 000007AD with net config ID -1
18:10:30:962[0000] - Info - APP - Simclient.ClientStatusHandler: Client event SimConnecting: "Simulator Connecting" - Client status: Initializing
18:10:31:004[0041] - Info - APP - Simclient.ClientStatusHandler: Client event SimConnected: "Simulator Connected" - Client status: SimConnected
18:10:31:068[0063] - Info - CLT - Server responded to ping, reported version: 01020000
18:10:31:069[0001] - Info - APP - SimClient.Connect: Found WASimModule Server v1.2.0.0
18:10:31:069[0000] - Info - CLT - Connecting to WASimCommander server...
18:10:31:070[0001] - Info - APP - Simclient.ClientStatusHandler: Client event ServerConnecting: "Server Connecting" - Client status: 6
18:10:31:149[0078] - Info - CLT - Connected to WASimCommander server v01020000
18:10:31:287[0138] - Error - APP - DeviceServer.ScanPorts: PNPDeviceID "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_VID&0001005D_PID&223B\9&2A3E3A38&0&742A8AE311DE_C00000000" is like Bluetooth device
18:10:31:299[0011] - Error - APP - DeviceServer.ScanPorts: PNPDeviceID "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&000F\9&2A3E3A38&0&18703BF7EE1A_C00000000" is like Bluetooth device
18:10:31:312[0012] - Error - APP - DeviceServer.ScanPorts: ENTRATO CON "USB\VID_1A86&PID_7523\6&39A452A4&0&1" 
18:10:31:313[0001] - Info - DEV - CreatePortArgs => DeviceName: "USB-SERIAL CH340 (COM7)"
18:10:31:314[0001] - Info - APP - DeviceServer.OnPortFoundEvent: COM7\USB\VID_1A86&PID_7523\6&39A452A4&0&1 found
18:10:31:372[0057] - Error - APP - DeviceServer.ScanPorts: PNPDeviceID "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\9&2A3E3A38&0&000000000000_00000000" is like Bluetooth device
18:10:31:382[0010] - Error - APP - DeviceServer.ScanPorts: PNPDeviceID "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\9&2A3E3A38&0&000000000000_00000002" is like Bluetooth device
18:10:31:404[0021] - Error - APP - DeviceServer.ScanPorts: PNPDeviceID "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&0000\9&2A3E3A38&0&000000000000_00000004" is like Bluetooth device
18:10:31:455[0051] - Error - APP - DeviceServer.ScanPorts: PNPDeviceID "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&000F\9&2A3E3A38&0&91D2D01322A5_C00000000" is like Bluetooth device
18:11:13:965[9999] - Info - APP - DeviceServer.Start: DeviceServer Started
18:11:13:967[0001] - Info - APP - Simclient.ClientStatusHandler: Client event ServerConnected: "Server Connected" - Client status: AllConnected
18:11:13:968[0001] - Info - APP - SimClient.SetLogLevel: LogLevel set to Info
18:10:31:000[-999] - Info - CLT - Connected to Simulator "KittyHawk" v11.0.282174.999, with SimConnect v11.0.62651.3 (Server v5)
18:11:13:971[9999] - Info - DEV - COMDevice.GetProperties: 02\COM7\MINI MEGA IDENT = "MINI MEGA" - "MEGA2560 MINI"
18:11:14:042[0071] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_AP_1_PUSH" with Id's 30/69650 successfully registered for "W"
18:11:14:046[0003] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_AP_2_PUSH" with Id's 31/69651 successfully registered for "W"
18:11:14:050[0003] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_ATHR_PUSH" with Id's 32/69652 successfully registered for "W"
18:11:14:054[0004] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_LOC_PUSH" with Id's 33/69653 successfully registered for "W"
18:11:14:060[0005] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_APPR_PUSH" with Id's 34/69654 successfully registered for "W"
18:11:14:075[0015] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_EXPED_PUSH" with Id's 35/69655 successfully registered for "W"
18:11:14:095[0019] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_SPD_MACH_TOGGLE_PUSH" with Id's 36/69656 successfully registered for "W"
18:11:14:104[0009] - Info - APP - SimClient.RegisterSimVar: Custom 'K'-var "A32NX.FCU_TRK_FPA_TOGGLE_PUSH" with Id's 37/69657 successfully registered for "W"
18:11:14:154[0049] - Info - APP - SimClient.RegisterSimVar: 'L'-var "A32NX_METRIC_ALT_TOGGLE" with Id's 38/0 successfully registered for "RW"

Notice the delay at about 18:10:31 and 18:11:13. During this time the software is freezed and i can’t do nothing, even on UI.
And notice the 6 BTHENUM element that are the virtualized com port by the dongle.

You can see a little more strange log lines that i added for investigation and debug.

I entered a few filter to NOT ADDING the bluetooth device but without success. It continue to freeze and after about 50 sec it will continue to process other stuff.

Mystery of softwares :sweat_smile:

EDIT: i suggest the awesome tool WMI DELPHI CODE CREATOR for investigate with WMI.

Hmmm, not really sure why it freezes there?

18:10:31:455[0051] - Error - APP - DeviceServer.ScanPorts: PNPDeviceID "BTHENUM\{00001101-0000-1000-8000-00805F9B34FB}_LOCALMFG&000F\9&2A3E3A38&0&91D2D01322A5_C00000000" is like Bluetooth device
18:11:13:965[9999] - Info - APP - DeviceServer.Start: DeviceServer Started

Really curious. A pity that I can’t help testing it, because I don’t have a USB dongle.

At least what I learn here is that you might be in the same timezone as I am :slight_smile:

It freeze in ScanPorts routine, here exactly:

    if (watchForChanges)
    {
        _watchingAddedObject.Start();
        _watchingRemovedObject.Start();
    }

watchingAddedObject 15 sec of freeze.
watchingRemovedObject 30 sec of freeze.

Times are from Debug of Visual Studio

Removed of boolean true and set to false, it works like a charms!!

However, i live in Abruzzo, Italy :smile: