I am trying to communicate with 3rd party device which RS485 115200 and HDLC protocol.
The problem is, that I am not receiving all data becuase:
I tried to connect my Arduino Mega and pc to bus to compare data. below is the result which missing some bytes:
PC
7E0518BF060D7E
7E0518BF070A7E
7E0551BF06B17E
7E0551BF07B67E
7E25FFAF160A112D021182005DFA640207010000005E011E0163008E008E00340100000000767E
7E0510BF065C7E
7E0511BF06377E
7E0512BF068A7E
7E0513BF06E17E
7E0514BF06F77E
7E0515BF069C7E
7E0516BF06217E
7E0517BF064A7E
7E0518BF060D7E
7E0518BF070A7E
7E0551BF06B17E
7E0551BF07B67E
7E0510BF065C7E
7E0511BF06377E
7E0512BF068A7E
7E0513BF06E17E
7E0514BF06F77E
7E0515BF069C7E
7E0516BF06217E
7E25FFAF160A112D021182005DFA640207010000005E011E0163008E008E00340100000000767E
Arduino Mega
7E0518BF060D7E
7E0518BF070A7E
7E0551BF06B17E
7E0551BF07B67E
7E7E
7E7E
7E7E
7E7E
7E7E
7E7E
7E7E
7E057E
0517BF064A7E7E
0518BF060D7E7E
0518BF070A7E7E
0551BF06B17E7E
0551BF07B67E
7E0510BF065C7E
7E0511BF06377E
7E0512BF068A7E
7E0513BF06E17E
7E0514BF06F77E
7E0515BF069C7E
7E0516BF06217E
7E25FFAF160A112D021182005DFA640207010000005E011E0167E
My code is very simple
void communication::begin() {
Serial1.begin(115200);
Serial.begin(115200);
save.begin();
pinMode(Serial_TxControl, OUTPUT);
digitalWrite(Serial_TxControl, LOW); // Set to Transceiver
}
void communication::receive() {
if (Serial1.available()) {
val = Serial1.read();
Serial.print(val, HEX);
Serial.print(" ");
if (waitForFirst) {
if (val == delimiter) {
if (Baddata == 1) {
Poll_Ack = 1;
}
addToBuffer(val);
waitForFirst = false;
} else if (val != delimiter) {
Baddata = 1;
}
} else if (val == delimiter) {
this->addToBuffer(val);
this->processMessage(message, mPos);
mPos = 0;
waitForFirst = true;
} else {
addToBuffer(val);
}
}
}
void communication::processMessage(byte* values, byte len) {
Serial.println();
// for (byte i = 0; i < len; i++) {
//
// save.record(values[i], 0);
// Serial.write(' ');
// Serial.print(values[i], HEX);
// }
}
void communication::addToBuffer(byte val) {
if (mPos < maxMessage) {
message[mPos++] = val;
}
}
communication::~communication() {
// TODO Auto-generated destructor stub
}