RS485 example
RS485_example
#include <io>
#include <read>
#include <float>
#include <string>
#include <core>
#include <write>
#include <define>
new rs[10];
new len;
main(){
Init(RS485, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE); // Baud rate: 9600, Word length: 8bit, Stop bit: 1, Parity: none
while(1){
len = buf_len(RS485); // Read RS485 buffer length
if(len != 0){ // If lenght not equal 0 then read RS485 buffer
read_buf(RS485, 4, rs); // Read RS485 buffer into rs array (read 4 bytes length array)
if(strcmp(rs, "test", false, 4) == 0){ // Compare rs buffer with "test" text (Compare 4 bytes) if equal send OK
write_buf(RS485, 6 ,"OK 4 !"); // Send data "OK 4 !" over RS485 (length 6 bytes)
}
}
Delay(1000); // Delay 1 sec.
}
}