Home > Software engineering >  A serial port is how to control the machine?
A serial port is how to control the machine?

Time:02-25

Part of the communication protocol is as follows:
Eight IO input query: (check digit 2 byte) are shown in brackets
Issued by: C1 C2 (00 00 0 06 02 a 0 d
Returns: C1 C2 6 0 a... 00 00 0 a 0 d (... Followed by eight IO status, 0 for the low level to high level 1)
Note: a command parsing failure: C9 C8 FF 02 (00 00 0 a 0 d

Saw some information about a serial port, asked some bosses
My understanding is:

PC sends a packet to the lower machine x

Under a machine back a packet to the upper machine y

According to the communication protocol of parity and the calculation method of calculating y its check code, a communication protocol above return check again calculation to b

A and b, if equal to perform operations

I understand it right?

CodePudding user response:

Protocol format:
Byte header (2 -) + function code (1 -) + byte length (1 -) + data bits (nbit) + parity bit (2) + word goeldi (2 -)

Byte header: C1 C2
Word goeldi: 0 a 0 d
Data bytes (1 -)=(nbit) + parity bit (2)

Check digit:
Calculation method: first the length byte header + function code + + data a cumulative sum, accumulate the value of the 16 bit high value added to the low 16 bits, that is the accumulation of highest carry to its lowest level, finally to invert,



Question 1. Returns: C1 C2 6 0 a... 00 00 0 a 0 d (... Followed by eight IO status, 0 for low level to high level 1),
See eight IO status from here? The eight IO state is to return from a machine under packet parsing out of y?


Question 2. PC sends packets to lower place machine and lower machine back a packet to the upper machine, could you tell me the two packets of
Is the same type, follow the same communication protocol?


Question 3. I don't see some check serial port communication, simply send the packet to the machine, the machine will start to work; I am a
To check, check digit after correctly, how to control the machine, in other words, the machine began to work how do you write the code?

CodePudding user response:

I feel like I become a big problem teenagers

CodePudding user response:

Is there a big help to have a look at, so confused

CodePudding user response:

General master-slave system, and the active control of part of the human-computer interaction PC, passive receive commands & amp; Perform operations are called lower machine
So, generally refers to the issuance of the PC sends a machine; Return (sometimes called response) is refers to under a machine sent to PC

Issued by: C1 C2 (00 00 0 06 02 a 0 d===& gt; Is to send a machine under want to read the request of the state of input command
Returns: C1 C2 6 0 a... (00 00 0 a 0 d==& gt; A machine back to upper machine under the current state, 0 a=10 (8 bytes input status data check + 2 bytes); ... 8 bytes input state

From under the agreement that the PC machine transmission to follow the same protocol

Normal send {according to the communication protocol frame structure (frame head + code + data + data length), and check, add tail frame, sending data}
Normal receive {receiving data, check the frame integrity (frame head and tail frame, data length), check and correct? According to the response code line points further processing}

In general agreement there will be a typical example of a data frame, assistant can directly use the serial port to send data, analysis the corresponding response data, and help to further deepen the understanding of agreement






CodePudding user response:

Question 1. Returns: C1 C2 6 0 a... 00 00 0 a 0 d (... Followed by eight IO status, 0 for low level to high level 1),
See eight IO status from here? The eight IO state is to return from a machine under packet parsing out of y?
What about this
  • Related