与 WPF 应用程序中的串行设备通信

发布于 2024-10-05 20:50:28 字数 144 浏览 0 评论 0原文

我正在尝试在实现 MVVM 设计的 WPF 应用程序中与串行设备进行通信的基础知识。现在我有一个硬环回,只期望接收发送的字符。

我过去曾见过 Win Forms 控件执行此操作的提示,也许还有框架类,但现在我对本着 MVVM 策略的精神可以使用什么一无所知。

I'm dabbling with the basics of communicating with a serial device from within a WPF application implementing an MVVM design. Right now I have a hard loopback and only expect to receive characters sent.

I have in the past seen hints of a Win Forms control to do this, and maybe a framework class, but right now I am a bit clueless as to what I can use in the spirit of an MVVM strategy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

鼻尖触碰 2024-10-12 20:50:28

我有点困惑,在我看来你可能对 MVVM 想得太多了。 MVVM是一种表示模式;串行通信不是表示,并且表示层是什么并不重要。

如果我这样做并且我正确理解你的问题,我就会有一个封装串行通信的类。如果您只期望将字符发送给您,我会让该类公开一个基本的“已接收”事件。然后,您的视图模型可以使用此类的实例来填充您的视图附加到的一些属性。

希望这有帮助。

I am a bit confused and it seems to me you might be overthinking MVVM. MVVM is a presentation pattern; serial communication is not presentation and it doesn't matter what your presentation layer is.

If I were to do this and I understand your problem correctly, I would have a class that encapsulates the serial communication. If you are only expecting characters to be sent to you, I'd have the class expose a basic "Received" event. Your View Model can then use an instance of this class to populate some properties that your View is attached to.

Hope this helps.

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