How can I prevent invalid configuration of a Microsoft.SPOT.Hardware.InterruptPort?
I'm trying to use the .NET Micro Framework's Microsoft.SPOT.Hardware.InterruptPort
class. However, the documentation perplexes me:
It is possible to configure an
InterruptPort
object into an invalid state. In such cases, your program may not generate an exception until it actually uses theInterruptPort
object. For example, suppose you create anInterruptPort
object with its resistor mode set toPort.ResistorMode.PullUp
, the interrupt mode set toPort.InterruptMode.InterruptEdgeLevelHigh
, and the glitch filter set totrue开发者_Go百科
. This configuration does not generate an exception when you instantiate anInterruptPort
object. If you then add an interrupt handler, the .NET Micro Framework throws an exception.
(emphasis is my own)
It fails to mention which configurations cause these invalid states, leaving me with just one arbitrary example of what not to do.
Is there any documentation I'm missing?
Is there an essential piece of electronics knowledge I've overlooked? Or are MSDN just useless at documentation?Actually, I have suffered the same?/similar problem. Hans is correct that it is down to the hardware - if you are using GHI's FEZ range of devices then (I only found out from the manufacturer after tearing my hair out for days) they don't support level interrupts so any configuration using InterruptMode.InterruptEdgeLevelHigh or InterruptMode.InterruptEdgeLevelLow will fail as soon as you try and hook up the interrupt handler. The documentation on MSDN is quite scant primarily because the MicroFramework is community-contributed open-source. The same (commercial) quality standards applied to other versions of the .NET framework by Microsoft don't apply I'm afraid. If your board manufacturer is not GHI, check with them that Level Interrupts are supported in the first place.
I had the same issue, but my solution was different. Yes, the InterruptEdgeLevelHigh and Low were both invalid options. However, I discovered the problem for me was the device was not connected to an Interrupt capable connection. Even when it was the code is slightly different.
Typicall you may connect a button like this.
InputPort yourButton = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false,
Port.ResistorMode.PullUp);
To use an Interrupt port the code looks like this.
InterruptPort yourButton =
new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.LDR, true,
Port.ResistorMode.PullUp,
Port.InterruptMode.InterruptEdgeBoth);
So, provided the device is connect to an interrupt enabled port and you created your input devices from an InterruptPort and not an InputPort you should be able to create the Interrupt EventHandler.
精彩评论