I'm working on a personal project using a WinCE7 system and coding using C#. I need access to the system's GPIO and I have been provided with a GPIO api but little to no explanation or support from the developer. I've successfully used the api to set the output and get the input via polling but I need to set an interrupt driven mechanism. The api has a function that allows me to achieve this but i have been unable to figure out how to use it. The function looks like this: "BOOL GpioSetupInterruptPin(HANDLE hGPIO, PIN_GPIO_PORT port, UINT pin, INT_TRIGGER_MODE mode, INT_TRIGGER_POLARITY polarity, LPCWSTR szEventName, BOOL enable);"
I've been given the structures for the PORT, TRIGGER_MODE and TRIGGER_POLARITY and the following description for szEventName: "event name of a named event", but that is about it.
I'm new at event handling in c# and i've done a lot of tutorials and code samples i found on google but i'm not sure how to pass my event to the above function. I've followed a number of examples online but I still don't understand what i'm doing wrong.
Things i know i'm doing wrong in the code bellow: my event has no arguments, the code in red is not recognized by the compiler. I would really appreciate some help with this.
public partial class Form1 : Form
{
private void Interrupt_Setup()
{
hGPIO = GPIOapi.GpioOpenHandle(); //returns a handle to the gpio
GIPO_ON = true;
Debug.WriteLine("Driver open \n" + hGPIO);
string Trigger = "InputProcessUpdateHandler";
IntPtr handle = CreateEvent(IntPtr.Zero, false, true, Trigger); //used P/Invoke
GPIO_Output(); //set output pins
GPIO_Interrupt(Trigger);//configure interrupt
}
private void GPIO_Interrupt(string trigger)
{
ok = GPIOapi.GpioSetupInterruptPin(hGPIO, port6, 4, GPIOapi.INT_TRIGGER_MODE.TRIGGER_MODE_EDGE,
GPIOapi.INT_TRIGGER_POLARITY.TRIGGER_POL_HIGH_RISING, trigger, true); //throws exception
Debug.WriteLine("NO interrupt");
Debug.WriteLine("Interrupt set for:" + port6 + "04" + " at " + hGPIO);
private InputProcessor _inputProcessor = null;
public ShowToggle(InputProcessor inputProcessor)
{
_inputProcessor = inputProcessor;
_inputProcessor.updateHandeledBy += InputProcessUpdateHandler;
}
private void InputProcessUpdateHandler()
{
Debug.Write("execute");
}
}
public class InputProcessor{ public event InputProcessUpdateHandler updateHandledBy = null;
public void Process(Label label)
{
if (updateHandledBy != null)
updateHandledBy(label);
}
}
Some of the sites i've looked at:
http://www.pinfaq.com/123/events-and-delegates-and-its-difference-dotnet-application
http://www.codeproject.com/Articles/11541/The-Simplest-C-Events-Example-Imaginable
http://timok.tumblr.com/post/57441520214/simplistic-event-example-in-c
http://www.codearsenal.net/2012/09/csharp-custom-event-handling.html
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682396%28v=vs.85%29.aspx
http://stackoverflow.com/questions/12576944/triggering-event-in-c-sharp-from-c-dll?lq=1
http://stackoverflow.com/questions/17073386/raise-events-in-c-cli-dll-and-consume-in-c-sharp?lq=1