Good day,
I have 2 Byte Arrays that I want to read on an RS485 Device. Reading one is working fine, but it does not allow me to read another one. I have different Addresses for the Data Reading.
Please see below Data I am trying to read.
byte data1 = {0x7E, 0x01, 0x01, 0x00, 0xFE, 0x0D};
byte data2 = {0x7E, 0x01, 0xDC, 0x03, 0x06, 0x00, 0x00, 0xC2, 0x0D};
As soon as the first Data is read, it blocks half the data and then reads the next, and only provides half the Data from the first request.
I am using ESP32 with RS485 to TTL YX-G485
void loop() {
unsigned long currentTime = millis();
struct commands_t {
byte data1 = {0x7E, 0x01, 0x01, 0x00, 0xFE, 0x0D};
// byte data2 = {0x7E, 0x01, 0xDC, 0x03, 0x06, 0x00, 0x00, 0xC2, 0x0D};
} commands;
int i;
int len=6;
Serial.println("SEND DATA");
for(i = 0 ; i < len ; i++){
Serial2.write(msg[i]);
Serial.print("[");
Serial.print(i);
Serial.print("]");
Serial.print("=");
Serial.print(String(msg[i], HEX));
}
len = 0;
Serial.println();
int a = 0;
while(Serial2.available())
{
ByteArray[a] = Serial2.read();
a++;
}
int b = 0;
String registerHex;
String registerDec;
Serial.println("DATA RECEPTION - RECEPCIĆN DATOS");
for(b = 0 ; b < a ; b++){
Serial.print("[");
Serial.print(b);
Serial.print("]");
Serial.print("=");
registerHex = String(ByteArray[b], HEX);
Serial.print("H: ");
Serial.print(registerHex);
registerDec = String(ByteArray[b], DEC);
Serial.print("D: ");
Serial.print(registerDec);
}
Serial.println();
Reading them Individually works fine but when i try to read both of them, they dont give all the information.
Do you have both ends of the link configured for the same type of data structure? I thought my vision was messed up but apparently you did not follow the forum guidelines and use the </> things to post your code so myself and many others will not bother to read it. Best to read the forum guidelines first then try again.
system
Closed
August 29, 2023, 7:07pm
5
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.