Click here to Skip to main content
15,891,670 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
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.
Posted

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
 
Share this answer
 
Comments
Bryan Se To 22-Aug-14 3:55am    
Hi.

I am unclear about the 'documentation on the device connected to it' part. May I ask what do I need to understand?

As to the parameters of the serial port, I have fully grasp it with some research. Thanks!

Are they also any keywords I could Google to learn about this problem that I am facing?
Sergey Alexandrovich Kryukov 22-Aug-14 11:15am    
What keywords? You cannot Google like "find me that-I-don't-know-what". You did not tell us a single word about what you have connected.
—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.
 
Share this answer
 
Comments
[no name] 28-Aug-14 23:19pm    
This is absolutely meaningless and not an answer. It refers to a specific protocol for a device which you have not even identified.
Bryan Se To 28-Aug-14 23:37pm    
It's not. If I am going to write more of this, I am expected to know this mean and do. It is absolutely essential. The specific protocol for the device will differentiate the other bytes like 0x07, 0x00, 0x08, 0x00. Nothing is meaningless.
[no name] 28-Aug-14 23:40pm    
When you know something post your knowledge. Until then listening is good. At the moment your question and answer has not risen above spam.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900