I'm developing an application on C# using Unosquare.RaspberryIO. My question related to interrupts and callbacks. According to the documentation, it's possible to register callbacks. For example:

pin.RegisterInterruptCallback(EdgeDetection.FallingEdge, ISRCallback);

But, how to unregister from them? Looks like the related method is not available in Unosquare.RaspberryIO. I have tried to reregister one more blank method on the same pin, like this:

pin.RegisterInterruptCallback(EdgeDetection.FallingEdge, () => { });

, but received an exception:

"Unhandled Exception: System.InvalidOperationException: An interrupt callback was already registered."

Any ideas how to solve this?

p.s. As an option, it can be possible to use if-else statement and bool variable. But, I don't like it.

  • What is Unosquare.RaspberryIO? – NomadMaker Jun 19 '18 at 22:17

Surprisingly, there is no way. Here is the code: https://github.com/unosquare/raspberryio/blob/master/src/Unosquare.RaspberryIO/Gpio/GpioPin.cs

The InterruptCallback cannot be changed once it is set (!).

You might wish to submit an issue to the library owners to address this lack.

As a workaround you might consider a hack where you pass in a callback that has its own callback pointer that you manage. Very ugly but...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.