RS232 example

RS232 example

RS232_example
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> new rs[10]; new len; main(){ Init(RS232, 9600, WORDLENGTH_8, STOPBITS_1, PARITY_NONE); // Baud rate: 9600, Word length: 8bit, Stop bit: 1, Parity: none while(1){ len = buf_len(RS232); // Read RS232 buffer length if(len != 0){ // If lenght not equal 0 then read RS232 buffer read_buf(RS232, len, rs); // Read RS232 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(RS232, 6 ,"OK 4 !"); // Send data "OK 4 !" over RS232 (length 6 bytes) } } Delay(1000); // Delay 1 sec. } }