Hey guys!
Working with C#.NET in simple game projects and other stuff for about 4 years.
Now I just started with Arduino and managed to kick through all the starter kit projects.
My youngest project currently is to create a simple hardware control device to control a simple game.
So i created a simple on/off switch on the Arduino Uno which sends bytes through .NET's "System.IO.Ports.SerialPort" - Library.
Now I have to create my own little driver software.
It really just should be controllable to a minimum - just to test things out.
Heres the code:
public class ButtonBoy
{
public delegate void ButtonPressHandler();
public event ButtonPressHandler ButtonEvent;
SerialPort serialPort = new SerialPort("COM3", 9600);
public ButtonBoy()
{
serialPort.Open();
}
public void CheckButton()
{
int pressed = 0;
pressed = serialPort.ReadByte();
if (pressed == 1)
{
ButtonEvent();
}
}
}
So whats my biggest issue here?
When I load this simple driver-api to one of my other projects to test things out - I actually don't have a way to receive the event like common Windows OS Keys. As far as I know its because the OS has its own thread iterating through the common key events or mouse events.
What I need to do always with this state of the API is to create a loop to iterate through my CheckButton-Method just to launch the event of the pressed button on my hardware device.
I'm sure that's not how things work.
So i was curious if anybody knows how to let my driver work just like other drivers work. In fact I only want to care about the ButtonEvent handling and not if the CheckButton-Method is being called all the time.
I hope you get my idea here?
greets Charlie