C# - 从串口缓冲区看书 [英] C# - readin from serial port buffer

查看:218
本文介绍了C# - 从串口缓冲区看书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个RS-232端口读取数据。任何人不会有我如何从端口/缓冲器获取数据的例子,并确保我有所有的数据,因为它可以多行数据。



我只是?如下读

 字符串Rxstring = port.ReadLine(); 
Console.WriteLine(Rxstring);


解决方案

试试这个:

 使用System.IO.Ports; 


私人的SerialPort端口=新的SerialPort(COM1,9600,Parity.None,8,StopBits.One);

Console.WriteLine(port.ReadExisting());



详情可在的科德的代码


I am trying to read data from an RS-232 port. Does anyone have an example of how I get the data from the port/buffer and make sure that I have all the data as it can be multiline data.

Do I simply read it as follows ?

string Rxstring = port.ReadLine();
Console.WriteLine(Rxstring);

解决方案

Try this:

using System.IO.Ports;
...

private SerialPort port = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One);

Console.WriteLine(port.ReadExisting());

Details can be found at Coad's Code.

这篇关于C# - 从串口缓冲区看书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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