如何防止 Microsoft.SPOT.Hardware.InterruptPort 的无效配置?
我正在尝试使用 .NET Micro Framework 的 Microsoft.SPOT.Hardware .InterruptPort
类。然而,文档让我困惑:
可以将
InterruptPort
对象配置为无效状态。在这种情况下,您的程序在实际使用InterruptPort 之前可能不会生成异常对象。 例如,假设您创建一个
InterruptPort
对象,其电阻模式设置为Port.ResistorMode.PullUp
,中断模式设置为Port.InterruptMode.InterruptEdgeLevelHigh
,并将毛刺滤波器设置为true
。当您实例化InterruptPort
对象时,此配置不会生成异常。如果您随后添加中断处理程序,.NET Micro Framework 将引发异常。
(重点是我自己的)
它没有提及哪些配置会导致这些无效状态,只给我留下了一个不该做什么的任意示例。
我缺少任何文档吗?
有没有我忽略的重要电子知识?
或者 MSDN 在文档方面毫无用处?
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
. 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实上,我也遇到过同样的问题?/类似的问题。 Hans 是正确的,这取决于硬件 - 如果您使用 GHI 的 FEZ 系列设备,那么(我在几天后才从制造商处发现)它们不支持级别中断,因此任何使用 InterruptMode 的配置。一旦您尝试连接中断处理程序,InterruptEdgeLevelHigh 或 InterruptMode.InterruptEdgeLevelLow 将失败。 MSDN 上的文档非常少,主要是因为 MicroFramework 是社区贡献的开源代码。恐怕 Microsoft 应用于其他版本的 .NET 框架的相同(商业)质量标准并不适用。如果您的主板制造商不是 GHI,请首先咨询他们是否支持电平中断。
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.
我有同样的问题,但我的解决方案不同。是的,InterruptEdgeLevelHigh 和 Low 都是无效选项。但是,我发现问题是设备未连接到支持中断的连接。即使是这样,代码也略有不同。
通常您可以连接这样的按钮。
要使用中断端口,代码如下所示。
因此,只要设备连接到启用中断的端口,并且您从 InterruptPort 而不是 InputPort 创建输入设备,您应该能够创建中断事件处理程序。
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.
To use an Interrupt port the code looks like this.
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.