简体   繁体   English

C# 基于标准方式读取串口数据

[英]C# Read Serial Port Data based on Standard way

its some years i have a software that work with truck scales read data from weight indicator via RS232 serial port and in all devices i just used serial port data received method i want to know whats the standard way to read these data from a serial port i just attached a document from weight indicator company that mentioned the data format几年来我有一个与汽车衡一起工作的软件通过 RS232 串行端口从重量指示器读取数据,在所有设备中我只是使用串行端口数据接收方法我想知道从串行端口读取这些数据的标准方法是什么我刚刚附上一份重量指示器公司的文件,其中提到了数据格式数据格式手册 . . i dont want to read data and then play with char to replace it with blank or any other process i just want its Standard way if anyone help me in this section i will be happy its the output of my serial port which the target is the middle number 10我不想读取数据然后玩 char 以将其替换为空白或任何其他进程我只想要它的标准方式如果有人在本节中帮助我我会很高兴我的串行端口的 output 目标是中间10号

-ip0    10     0
-ip0    10     0
-ip0    10     0
-ip0    10     0
-ip0    10     0
-ip0    10     0
-ip0    10     0
-ip0    10     0
-ip0    10     0
-ip0     0     0
>ip0     0     0
>ip0     0     0
>ip0     0     0
>ip0     0     0
>ip0     0     0

ip0 0 0 ip0 0 0

you can use the System.IO.Ports.SerialPort class to use the serial port in C#. The data received by the SerialPort class is of byte type and can be converted to string type.可以通过System.IO.Ports.SerialPort class来使用C#中的串口。SerialPort class接收到的数据是byte类型,可以转换成string类型。

According to your description, each data frame you receive has a fixed length.根据您的描述,您收到的每个数据帧都是固定长度的。 You can add a processing of parsing the data frame to the receiving function. For example, when data of a certain length is received, it is converted into a data frame, and the extra string On to the next analysis.可以在接收function的时候加上一个解析数据帧的处理,比如接收到一定长度的数据,就转成数据帧,把多余的字符串放到下一步解析。 If the data is not of fixed length, a terminator can be added to the data frame to determine.如果数据不是定长的,可以在数据帧中加一个终止符来确定。

The data frames of serial communication are defined according to their actual needs, and the format of the data frames is uncertain, so the parsing process needs to be completed by yourself.串口通信的数据帧是根据自己的实际需要定义的,数据帧的格式是不确定的,所以需要自己完成解析过程。

hope to help you希望能帮到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM