如何从COM端口读取数据 [英] How to read data from com port

查看:125
本文介绍了如何从COM端口读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用串行数据处理程序,但它永远不会激活

i use serial data handler but it not fire never

推荐答案

首先,使用 SerialPort类 [ ^ ] - 该链接包含一个示例。

其次,检查你的com端口与设备的连接:如果它是一个真正的COM端口而不是USB连接,那么一些设备需要控制信号,如RTS / CTS和DTR才能开始通话。



您还需要检查速度,每个字符的位数,停止位和奇偶校验是否正确,以及设备在发送之前不需要先说话任何数据。



我建议首先使用超级终端或类似的方法检查连接,然后直接转到代码,并添加其他错误的所有可能性。
First, use the SerialPort class[^] - the link includes an example.
Second, check your com port connection to the device: if it's a "real" COM port rather than a USB connection then some devices require control signals such as RTS/CTS and DTR before they can start to talk.

You also need to check the speed, bits per character, stop bits, and parity are correct, and that the device doesn't need to you "talk first" before it sends any data.

I'd recommend checking the connection first using hyperterminal or similar before moving direct to code with all the possibilities for other mistakes that adds.

port = new SerialPort("POrt Name");
                     port.Open();
                     string message = port.ReadExisting();
                     txtMsg.Text = message;





这对我有用。



This works for me.


这篇关于如何从COM端口读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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