设计通过串行端口与硬件通信的应用程序 [英] Designing an application that communicates to hardware through serialport

查看:72
本文介绍了设计通过串行端口与硬件通信的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在c#中设计一个通过串行端口进行通信的Windows应用程序.该项目将具有一个连接选择屏幕,一个带菜单栏的主窗体以及连接到每个菜单项的多个对话框.应用程序的流程如下所示:

连接选择对话框将显示在MainForm_Load事件上,并捕获串行端口名称.

选择菜单项后,将通过串行端口发送关联的命令,并且对话框将显示响应数据.

我遇到了来自c ++的基本c#概念的麻烦.

如何只创建一个可以在所有对话框之间共享数据的串行类?
如何从对话框访问串行读取响应并以文本字段或更有意义的方式显示该数据?

当我进行绘制时,它看起来很简单,但是我不知道如何从串行端口访问数据以在每个对话框中显示.

I am making an attempt to design a Windows application in c# that communicates through a serial port. The project will have a connection select screen, a main form with a menu bar and multiple dialogs connected to each menu item. The flow of the application would look like this:

The connection select dialog will be shown on the MainForm_Load event and capture the serial port name.

When a menu items is selected, the associated command will be sent through the serial port and the dialog will show the response data.

I am having trouble with the basic c# concepts coming from c++.

How can I create just one serial class that can share data between all the dialogs?
How can I access the serial read response from my dialog and display that data in a text field or a more meaningful way?

When I draw this up, it appears simple, but I do not know how to access data from the serial port to display in each dialog.

推荐答案

Microsoft文档应该可以帮助您:
http://msdn.microsoft.com/en-us/library/system. io.ports.serialport.aspx [ ^ ]

这是具有完整代码的网站:
http://www.dreamincode.net/forums/topic/35775 -serial-port-communication-in-c%23/ [
The documentation from Microsoft should help you along:
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx[^]

Here is a site with complete code:
http://www.dreamincode.net/forums/topic/35775-serial-port-communication-in-c%23/[^]


这篇关于设计通过串行端口与硬件通信的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆