receive-rs485-data

antoniorruiz/rs485/receive-rs485-data

No description
receive-rs485-data
@/receive-rs485-data
Addressbyte
Include the Address number
Functionbyte
Include the Function number
Start_Address_1byte
Include the Start_Address_1 number
Start_Address_2byte
Include the Start_Address_2 number
Register_Length_1byte
Include the Register_Length_1 number
Register_Length_2byte
Include the Register_Length_2 number
CRC_Lbyte
Include the CRC_L number
CRC_Hbyte
Include the CRC_H number
UPDpulse
SETnumber
Connect to SET1 pin in ltt-device node
IN@/ttl-device
Connect to ltt device node
receive-rs485-data
IN
Address
Function
Start_Address_1
Start_Address_2
Register_Length_1
Register_Length_2
CRC_L
CRC_H
UPD
SET
DONE
Measurement
Measurementnumber
The data is shown in this pin
DONEpulse
Gives 1 when the node has successfully executed
To use the node in your project you should have the antoniorruiz/rs485 library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

#include<SoftwareSerial.h>


node {
    // Internal state variables defined at this level persists across evaluations
    Number foo;
    uint8_t bar = 5;

    void evaluate(Context ctx) {
        bar += 42;

        if (isSettingUp()) {
            // This run once
            foo = (Number)(bar + 1);
        }
        if (!isInputDirty<input_UPD>(ctx)) 
            return;

auto RS485_serial = getValue<input_IN>(ctx);
int SET;    
uint8_t Address = getValue<input_Address>(ctx);
uint8_t Function = getValue<input_Function>(ctx);
uint8_t Start_Address_1 = getValue<input_Start_Address_1>(ctx);
uint8_t Start_Address_2 = getValue<input_Start_Address_2>(ctx);
uint8_t Register_Length_1 = getValue<input_Register_Length_1>(ctx);
uint8_t Register_Length_2 = getValue<input_Register_Length_2>(ctx);
uint8_t CRC_L = getValue<input_CRC_L>(ctx);
uint8_t CRC_H = getValue<input_CRC_H>(ctx);
uint8_t ADDR[] = {Address, Function, Start_Address_1, Start_Address_2, Register_Length_1, Register_Length_2, CRC_L, CRC_H};
uint8_t val[2];
int i;
int val1;
int val2;
int val3;
SET = getValue<input_SET>(ctx);

digitalWrite (SET, 1);
delay (1000);
RS485_serial->write(ADDR, 8);

digitalWrite(SET,0);
    
delay (100);
if(RS485_serial->available ())
{
for (i=0; i<8; i++){
    
uint8_t RX1 = RS485_serial->read();


if (i==3){

val[0] = RX1;
    }

if (i==4){

val[1] = RX1;
    }
}
val1 = val[0];
val2 = val1 % 10;
val1 = val1/10;
val1 = val1*4096;
val2 = val2*256;
val3 = val[1];
val3 = val3 + val2 + val1;
emitValue<output_Measurement>(ctx, val3);
emitValue<output_DONE>(ctx, 1);
}
}
}