I am reading data from RS485 which is in the following format:
void sendkwh()
{
RS485Serial.write((byte)0x01); // Meter Address
RS485Serial.write((byte)0x03); // Read Function Code
RS485Serial.write((byte)0x40); // Register Address Variable (Start address high bit)
RS485Serial.write((byte)0x34); // Register Address Variable (Start address low bit)
RS485Serial.write((byte)0x00); // Register Quantity (High Bit)
RS485Serial.write((byte)0x02); // Register Quantity (Low Bit)
RS485Serial.write((byte)0x90); // CRC check code (CRC code Low bit)
RS485Serial.write((byte)0x05); // CRC check code (CRC code High bit)
}
and I need to read only the 4th and 5th frame of the packet. I am doing it the following way:
RS485Serial.listen();
if (RS485Serial.available() > 0)
{
if(RS485Serial.read() == 0x01)
{
for(int i=0; i<4; i++) {
byte discard = RS485Serial.read();
}
byteReceived = RS485Serial.read(); // 4th frame
byteReceived2 = RS485Serial.read(); // 5th frame
which is working fine. I wanted to know if there is a method to discard the packets without loop?
As in I have changed the sendkwh()
as below:
byte SendKWh[] = { 0x01, 0x03, 0x40, 0x34, 0x00, 0x02, 0x90, 0x05 };
RS485Serial.write(SendKWh, sizeof(SendKWh));
But don't know how to proceed with tapping the 4th and the 5th frame. Your help is appreciated.