Posts: 64
Joined: Sun Jun 22, 2014 2:49 pm

WiringPi wiringPiISR not working with C# even though return 0

Wed Sep 06, 2017 1:27 am

Hi All,

I'm using Gordon's WiringPi api and wrote a web service interfacing with GPIO using C#. Everything is working as intended. Just one minor issue i observed in wiringPiISR api.

When my program start running, it will always call for initialization of GPIO ports once. One of them is to assign an interrupt for one input pin. Refer to below for my code:

Code: Select all

\\ Set GPIO.21 to input
GPIO.pinMode(21, Convert.ToInt32(GPIO.GPIOpinmode.Input));
\\ Enable internal pull down resistor for GPIO.21
GPIO.pullUpDnControl(21, Convert.ToInt32(GPIO.PullUpDnValue.Down));
\\ Set interrupt call back for GPIO.21
int result = PiThreadInterrupts.wiringPiISR(21,
                    new PiThreadInterrupts.ISRCallback(() => MyCallBackMethod()));
What i observed is if i start my program, MyCallBackMethod() did not fire even though wiringPiISR return 0. I hooked up a button to the input pin and try triggering it manually, still seeing the same thing. This symptom can be reproduced by simply restarting the program, but it seems that this symptom doesn't appear every time.

To solve this, i add one process calling command "gpio unexportall" inside my initialization method. Code below:

Code: Select all

        private static int UnexportCall()
            Process a = new Process();
            a.StartInfo.FileName = "gpio";
            a.StartInfo.Arguments = "unexportall";
            a.StartInfo.CreateNoWindow = true;
            a.StartInfo.UseShellExecute = false;
            a.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            if (a.WaitForExit(5000))
                return a.ExitCode;
                return -1;
With this code added to my initialization method, MyCallBackMethod() fires every time i restart my program. So it seems like there is some problem with wiringPiISR api returning 0 even though it failed to assign the call back method?

Is there an api for "gpio unexportall" command? I can't find it under this link https://projects.drogon.net/raspberry-p ... functions/. Even though calling additional process works, but i prefer to call the api method as it is more cleaner that way.

Thank you.


User avatar
Posts: 39867
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: WiringPi wiringPiISR not working even though return 0

Thu Sep 07, 2017 8:21 pm

For anyone to help you, you'll have to post your whole program not just a small snippet of code out of context.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

Return to “C/C++”