Skip to main content

Serial communication protocol

In USB mode, serial communication protocol is used between POS and Payment terminal

Communication parameters

  • Baud Rate : 115200
  • Data bits : 8
  • Stop bits : 1

Message structure

Cross terminal application integration, USB mode integration serial communication protocol message structure
OffsetFieldByte LengthDescription
0x00STX2Start text, fixed value: 0x55AA
0x02Message type10x00: normal package 0x01: handshake command 0x02: handshake confirmation command
0x03ACK1If the field is 0, it means that the field is invalid; non-0, it represents the id of the last received data packet that passed the verification
0x04Message ID1There is no valid data in the message, the value is 0; the initial value can be 1, and each time a new data packet is sent, it will automatically + 1, greater than 255, and reset to the initial value of 1;
0x05Message Data length2Represents the sum of the lengths of message data segments, with high bytes first;
0x07Message DatanValid data, the upper business layer is responsible for parsing the specific Action category;
0x08+nCRC1Checksum, Byte-by-byte XOR result for data from “message type” to “message data”
0x09+nETX2End text, fixed value: 0xCC33
note

The Message max-length is 1024 Bytes

Communication sequence

Cross terminal application integration, USB mode integration serial communication protocol communication sequence

Message type

1. Handshake message

POS sends an empty packet to Payment Terminal, the packet type is 1, the ack field is 0, and the data packet id is 0 After receiving it, the Payment Terminal side sets the current state as connection and returns an empty packet of packet type 2 to pos (handshake persuasion) If the Payment Terminal side is connected before receiving the handshake command, the relevant state needs to be cleared.

Cross terminal application integration, USB mode integration serial communication protocol handshake message structure

Sample message (HEX)

Handshake Message:

55AA010000000001CC33

Handshake Confirmation Message:

55AA020000000002CC33

2. Heartbeat message

This Payment Terminal sends heartbeat message information every 2 seconds.

Cross terminal application integration, USB mode integration serial communication protocol heartbeat message structure

Sample message (HEX)

55AA000000000000CC33

3. ACK message

Due to the unreliability of the serial communication process, the transmitted data will inevitably encounter various situations such as loss, delay, error, repetition, etc. Therefore, this ACK mechanism is used. The core of this mechanism is that after the sender sends data to the receiver, the receiver sends an ACK (receipt) to the sender. If the sender does not receive the correct ACK, it will resend the data until the ACK is received.

Cross terminal application integration, USB mode integration serial communication protocol ACK message structure

Sample message (HEX)

55AA000100000001CC33

4. Transaction message

Send data

For packets with valid data sent by the other party, the receiver should return the ack in time There may be situations where multiple different data packets are received at the same time (with different IDs). In this case, only the ack of the last packet needs to be returned In order to prevent repeated processing of packets retransmitted by the other party, the receiver should record the id of the data packet received last time. If the id is equal, it means that the other party retransmitted it, and the packet is automatically ignored.

Resend data

The new data packet at the top of the stack, after sending it, mark it as sent, and record the number of times the packet was sent as 1 To the next 100ms code packet of the released version time, check the packet receipt before the code packet of the released version, and if the corresponding ack of the other party is received, remove the data packet from the stack If it has not been received, retransmit the packet, + 1 the number of times the packet has been sent. If the opposite ack message has not been received after being sent 5 times, set the connection to disconnected and empty.

Cross terminal application integration, USB mode integration serial communication protocol transaction message structure

Message data field

Field Format

POS application and CodePay Register communicate in JSON format