Sending command to scanner RX TX and wait for an answer

Hi,

I'm trying to make a project with QRCode scanners and the manual of the barcode has the following indication:

Customers can periodically send heartbeat packets to ensure the data accuracy. The format is as
follows:
Heartbeat packets from main control
7E 00 0A 01 00 00 00 30 1A
Return command
03 00 00 01 00 33 31
Note: It is recommended to send a heartbeat packet every 10 seconds. If no correct reply is
received for three consecutive times, the main control should be handle

My question is how do I send the commend to the scanner and wait for a reply?

Code example:

#include <SoftwareSerial.h> 

SoftwareSerial QRSerial(3, 4) //RX TX

String QRValue = "";
void setup() {
  Serial.begin(9600);
  QRSerial.begin(9600); 
}

void loop() {
  if (QRSerial.available()) {
    QRValue += QRSerial.readString();
    Serial.println(QRValue);
    }
  }
}

I can use the .available() to check if is there anything coming from the scanner but how do I send a command to it?

byte heartBeat = {0x7E, 0x00, 0x0A, 0x01, 0x00, 0x00, 0x00, 0x30, 0x1A};
QRSerial.write (heartBeat, sizeof(heartBeat));

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.