简体   繁体   English

如何记录从 Arduino 的 C# 的串行 com 端口随机出现的特定变量数据

[英]How to log the particular variable data which comes randomly at serial com port in C# from Arduino

I am working on a project in which I have set up a serial communication between Arduino and C# window form application.我正在开展一个项目,在该项目中,我在 Arduino 和 C# window 表单应用程序之间建立了串行通信。 When I send a start command to Arduino, Arduino starts rotating the servo motor attached to it and sends the angle position to c# in a continuous manner.当我向 Arduino 发送启动命令时,Arduino 开始旋转连接到它的伺服电机,并以连续的方式将角度 position 发送到 Z240AA2CEC4B29C56F3BEE520A。

Now while Arduino is sending the data to C#, I request a variable data stored in Arduino at a random time at the same serial port and I want to log that variable data in my c#.i can log whatever data is being received on serial port but I can't select and extract that particular variable. Now while Arduino is sending the data to C#, I request a variable data stored in Arduino at a random time at the same serial port and I want to log that variable data in my c#.i can log whatever data is being received on serial port但我不能 select 并提取该特定变量。

Can anyone please help me with that?有人可以帮我吗?

I'll just lay this out here.我就在这里说一下吧。 Picking up where jdweng left off, your messages also need to contain messaging protocol state information.从 jdweng 停止的地方开始,您的消息还需要包含消息协议 state 信息。 Once this information has been included, you will be able to de-serialize any message in any order because the information required to process it is contained in the message.包含此信息后,您将能够以任何顺序对任何消息进行反序列化,因为处理它所需的信息包含在消息中。

Here is an example protocol.这是一个示例协议。

Message -信息 -

  • MessageLength - 2 bytes消息长度 - 2 个字节
  • MessageType - 2 bytes消息类型 - 2 个字节
  • MessageBody - n bytes MessageBody - n 字节

So your angle message would consist of three parts Length, Type, and Value所以你的角度信息将由长度、类型和值三部分组成

AngleMessage角度消息

  • MessageLength = 6消息长度 = 6
  • MessageType = (Int16)MessageTypes.Angle MessageType = (Int16)MessageTypes.Angle
  • MessageBody = (Int16)0-359 MessageBody = (Int16)0-359

ParameterMessage参数消息

  • MessageLength = 10 + size of value MessageLength = 10 + 值的大小
  • MessageType = (Int16)MessageTypes.Parameter MessageType = (Int16)MessageTypes.Parameter
  • MessageBody = {消息体 = {

    • (Int16)ParameterOperation.Updated, (Int16)ParameterOperation.Updated,
    • (Int16)ParameterNumber, (Int16)ParameterNumber,
    • (Int16)ParameterType, (Int16)参数类型,
    • (Byte[])ParameterValue (Byte[])ParameterValue

    } }

    Using this scheme your message contains all the information you need to process it.使用此方案,您的消息包含处理它所需的所有信息。

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

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