Reading Serial Data...
 
Notifications
Clear all

Reading Serial Data from custom arduino

3 Posts
2 Users
0 Likes
613 Views
(@judgie)
Active Member
Joined: 1 year ago
Posts: 5
Topic starter  

Hi, I am currently working on a plugin using a custom serial device (arduino).

I am trying to use a switch as a button to simulate a ignition switch. I got it working using SHCustomProtocol.h as well as using my own arduino code.

Now I would like to write C# Plugin for SimHub to store some settings as well as trying to synchronise the state of the ignition coming from the game with the state of the ignition switch, sth. like:

If switch is off and ignitionStateFromGame is On -> trigger button

If switch is on and ignitionStateFromGame is Off -> trigger button

I understand how to write serial data to the arduino via the custom serial device protocol. What I am currently missing, is how to read data from the arduino via the serial port.

My idea was to reference the Custom Serial Plugin and loop through the registered devices like this in my init function and then listen to incoming serial communication.

var cSerial = this.PluginManager.GetPlugin<CustomSerialPlugin>();
            if (cSerial.Settings != null && cSerial.Settings.Devices != null)
            {
                foreach (var device in cSerial.Settings.Devices)
                {
                    if (device.IsEnabled)
                    {
                        if (device.Name.StartsWith("JDG_IGN"))
                        {
                            this.Settings.Device = device;
                        }
                    }
                }
            }

But Settings is always null, so my question would be:
Is this the right approach to read from a registered custom serial device? And if yes, what would be the best way to communicate to the device?


   
Quote
(@donutz)
Active Member
Joined: 9 months ago
Posts: 4
 

Did you find it out? I am more less trying the same at the moment.


   
ReplyQuote
(@judgie)
Active Member
Joined: 1 year ago
Posts: 5
Topic starter  

Yes and no,

I essentially wrote my own USB Poll/Listener and forbid the Arduino Settings Page to poll the COM Port of the device. 


   
ReplyQuote
Share: