
send RS485 for testing Delta Sevro
Fork of RS4851121R by
Diff: main.cpp
- Revision:
- 4:ee9afe2292fd
- Parent:
- 2:bbb217e1219e
--- a/main.cpp Fri Apr 13 06:29:35 2018 +0000 +++ b/main.cpp Fri Apr 13 09:26:05 2018 +0000 @@ -6,53 +6,44 @@ Serial pc(USBTX,USBRX); DigitalOut Receiver(D7);//(p5); #define LENG 31 //0x42 + 31 bytes equal to 32 bytes -unsigned char buf[LENG]; +char buf[LENG]; //attributes - program variables char stringOverSerialBuffer[41]; // buffer to store received string over pc int newCommandFlag = 0; // flag for ISR - +int i; char data[BUFFER]; int num1,num2; int idx; +int len = 0; bool flagrec = false; void pc_rx(){ - //pc.putc(rs485.getc()); - int index = 0; + //pc.putc(rs485.getc()); Receiver = 0; -// while(rs485.readable() || (rx != '\n')) { -// while(flagrec) { - num1 = rs485.readable(); - for(idx= 0; rs485.readable(); idx++) - { - data[idx]= rs485.getc(); + for(idx= 0; rs485.readable(); idx++){ + data[idx]= rs485.getc(); + buf[len] = data[idx]; + len++; + } + if (len>8) flagrec = true; - } - - data[++idx]= '\0'; - for(idx= 0; data[idx] != '\0'; idx++) - pc.putc(data[idx]); - flagrec = true; -// } -// pc.printf("finish!"); - } int main() { rs485.baud(115200); pc.baud(115200); - pc.printf("1"); Receiver=0; rs485.attach(pc_rx, Serial::RxIrq); - while(1) - { -// pc.printf("test"); + while(1){ wait_ms(10); - if (flagrec) - { + if (flagrec){ flagrec = false; - pc.putc(num1);//data[idx]); + + for(i= 0; i<len; i++){ + pc.putc(buf[i]); } + len = 0; } + } } \ No newline at end of file