SerialPort.ReadLine物业用途 [英] SerialPort.ReadLine Property Usage

查看:148
本文介绍了SerialPort.ReadLine物业用途的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题要问。

我需要读取串口数据。这些数据来自逐行(我的意思是数据+输入)
我必须设置的SerialPort属性新的生产线,如下?

I need to read data from serial port. The data come line by line(I mean data + enter) Do I have to set the serialPort property new line as below?

SerialPort sp = new SerialPort();
sp.NewLine = "\r";
sp.ReadLine();



什么是换行属性的值?
我最诚挚的问候...

What is the value for newline property? My best regards...

推荐答案

这取决于你所使用的协议。这意味着,这是用于发送和接收部分协议的标的。

It depends on the protocol you are using. This mean that this is the subject of agreement for sending and receiving parts.

如果对方使用的Windows .NET最有可能的新行沃尔德是的环境.NewLine 的,你可以跳过设置它,因为它是Windows的默认值。

If the other side uses .NET on windows most probably the new line wold be Environment.NewLine and you could skip setting it because it is default value on windows.

在一般情况下,默认的新行序列是:对于Windows'\r\\\
'结果
为Mac结果
\r结果
为Linux的\\\
'结果
定制控制器 - 无论放在那里。

In general, default new line sequences are:
for windows '\r\n'
for mac '\r'
for linux '\n'
custom controller - whatever the developer of the controller put there

因此,如果你写一个软件来接收来自Linux的东西,你可能会等待\\\
'作为一个新行值等。

Thus if you write a software to receive something from linux, you might await '\n' as a NewLine value, etc.

如果你有数据交换一些控制器(带一些设备交换)换行字符串可能是不管使用什么设备软件开发人员设置。

If you have data exchange with some controller (exchange with some device) the NewLine string could be WHATEVER the device software developer set it.

如果你开发这个协议,有疑问设置换行还是不行,我可以建议你,如果你认为你的应用程序可以在多平台环境中运行设置(IE发送者在Windows中,接收器在Linux上)。

If you develop this protocol and are in doubt to set NewLine or not, I could suggest you to set if you assume that your application may run in multiplatform environment (I.E. sender on windows, receiver on linux).

这篇关于SerialPort.ReadLine物业用途的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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