如何防止 Microsoft.SPOT.Hardware.InterruptPort 的无效配置?

发布于 2024-11-03 04:42:13 字数 775 浏览 0 评论 0原文

我正在尝试使用 .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 the InterruptPort object. For example, suppose you create an InterruptPort object with its resistor mode set to Port.ResistorMode.PullUp, the interrupt mode set to Port.InterruptMode.InterruptEdgeLevelHigh, and the glitch filter set to true. This configuration does not generate an exception when you instantiate an InterruptPort 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

顾铮苏瑾 2024-11-10 04:42:13

事实上,我也遇到过同样的问题?/类似的问题。 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.

猫烠⑼条掵仅有一顆心 2024-11-10 04:42:13

我有同样的问题,但我的解决方案不同。是的,InterruptEdgeLevelHigh 和 Low 都是无效选项。但是,我发现问题是设备未连接到支持中断的连接。即使是这样,代码也略有不同。

通常您可以连接这样的按钮。

InputPort yourButton = new InputPort((Cpu.Pin)FEZ_Pin.Digital.LDR, false,
Port.ResistorMode.PullUp);

要使用中断端口,代码如下所示。

InterruptPort yourButton =
new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.LDR, true,
Port.ResistorMode.PullUp,
Port.InterruptMode.InterruptEdgeBoth);

因此,只要设备连接到启用中断的端口,并且您从 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.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文