我如何知道要发送到串行端口的内容? [英] How do I know what to send to the Serial Port?

查看:128
本文介绍了我如何知道要发送到串行端口的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我知道如何使用MFC / C ++打开,读取,写入和关闭串口。



问题是我不知道要把什么发送到串口。



我见过我的同事发送的内容如21 04 07 00 08 00 0F 22。



我将它转换为控制,它说! EOT BEL NUL BS NUL SI



这也意味着!(文字结束)(铃声)(null)(退格)(null)(转入)



我不确定我翻译的内容是否有用但是我想了解我的同事发送了什么,也许我可以设计自己的十六进制行发送到港口。



我觉得这是一个愚蠢的问题,但我对此比较陌生。



上周我只接触过MFC / C ++和二进制文件。



我是否应该在我的问题中不清楚,或者我是以错误的方式提问,请赐教。



我准备学习,我不是要求直接答案。



我希望Code Project中的编程老师可以帮助我。



非常感谢。

解决方案

< blockquote>您必须发送的内容完全由您在RS-232电缆另一端的内容定义。阅读与其连接的设备上的文档。内容并非全部;您还需要知道串口参数:波特率,控制位数,握手等。



-SA


21 04 07 00 08 00 0F 22



0x21是起始字节,设备使用它同步自己以检测帧的开始。



0x22是结束字节,确认不会有更多的字节跟随。设备使用它来知道帧已被完全接收,因此它可以处理数据。



0x04是编码要跟随的字节数的长度字节。 br $>


0x07和0x08可能是16位值。



0x00可能是消息的一部分在协议中说明。



0x0F是用于验证数据是否已损坏的校验和。



如果不查看设备的文档和协议,十六进制0x07,0x00,0x08,0x00很难说出他们想说的是什么。当我被要求提到文件时,谢尔盖亚历山德罗维奇Kryukov是对的。但是,我需要考虑和考虑更多的事情。最后,非常感谢 Hans Passant 帮助我 Stack Over Flow


Hi
I do know how to Open, Read, Write and Close a serial port using MFC/C++.

The problem is I do not know what to send to the serial port.

I have seen my colleagues sending something like 21 04 07 00 08 00 0F 22.

I converted it to control and it says ! EOT BEL NUL BS NUL SI "

Which also means ! (end of text)(bell)(null)(backspace)(null)(shift in)"

I'm not sure if what I have translated would be useful but I'm trying to understand what my have colleague sent and perhaps I could devise my own lines of hexadecimal to send to the port.

I get that this is a silly question but I am relatively new to this.

I was exposed to MFC/C++ and binary last week only.

Should I be unclear in my question or I am asking the question in a wrong way, please enlighten me.

I am ready to learn and I am not asking for direct answers.

I hope my fellow programming seniors in Code Project can help me out here.

Many thanks.

解决方案

What you have to send is fully defined by what you have on the other end of your RS-232 cable. Read the documentation on the device connected to it. The content is not all; you also need to know the serial port parameters: baud rate, number of control bits, handshake and so on.

—SA


21 04 07 00 08 00 0F 22

0x21 is the start byte, the device uses it to synchronise itself in order to detect the start of the frame.

0x22 is the end byte, a confirmation that no more bytes are expected to follow. The device uses this to know that the frame was received in full so it can process the data.

0x04 is the length byte which encodes how many bytes to follow.

0x07 and 0x08 are probably 16-bit values.

0x00 could be part of the message that is stated in the protocol.

0x0F is the checksum to verify that the data is not corrupted.

The hexadecimal 0x07, 0x00, 0x08, 0x00 are quite difficult to tell what they are trying to say without looking at the documentation and protocol of the device. Sergey Alexandrovich Kryukov was right when I am required to referred to the documentation. However, there are a ton more things that I had to look at and consider. Ultimately, many thanks to Hans Passant who helped me on Stack Over Flow.


这篇关于我如何知道要发送到串行端口的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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