send RS485 for testing Delta Sevro

Dependencies:   mbed

Fork of RS4851121R by albatross

Revision:
2:bbb217e1219e
Parent:
1:41cb97261876
Child:
3:48b96c8c25fa
Child:
4:ee9afe2292fd
--- a/main.cpp	Tue Dec 29 18:21:52 2015 +0000
+++ b/main.cpp	Fri Apr 13 06:29:35 2018 +0000
@@ -2,21 +2,57 @@
 #include "mbed.h"
 #define BUFFER 30
 
-Serial rs485(p9,p10);
+Serial rs485(PA_9,PA_10);//,115200);//(p9,p10);
 Serial pc(USBTX,USBRX);
-DigitalOut Receiver(p5);
+DigitalOut Receiver(D7);//(p5);
+#define LENG 31   //0x42 + 31 bytes equal to 32 bytes
+unsigned char buf[LENG];
+//attributes - program variables
+char stringOverSerialBuffer[41];    // buffer to store received string over pc
+int newCommandFlag = 0;             // flag for ISR
 
-int data[BUFFER];
+char data[BUFFER];
 int num1,num2;
+int idx;
+bool flagrec = false;
+void pc_rx(){
+    //pc.putc(rs485.getc());
+    int index = 0;   
+    
+    Receiver = 0;
+//    while(rs485.readable() || (rx != '\n')) {
+//    while(flagrec) {
+            num1 = rs485.readable();
+        for(idx= 0; rs485.readable(); idx++)
+        {
+            data[idx]= rs485.getc();
+            
+            }
+            
+        data[++idx]= '\0';
+        for(idx= 0; data[idx] != '\0'; idx++)
+            pc.putc(data[idx]);
+            flagrec = true;     
+//    }
+//        pc.printf("finish!");
 
-void pc_rx(){
-    pc.putc(rs485.getc());
 }
 
 int main()
 {
-    pc.printf("test");
+    rs485.baud(115200);
+    pc.baud(115200);
+    pc.printf("1");
     Receiver=0;
-    pc.attach(pc_rx, Serial::RxIrq);
-    while(1);
+    rs485.attach(pc_rx, Serial::RxIrq);
+    while(1)
+    {
+//        pc.printf("test");
+        wait_ms(10);
+        if (flagrec)
+        {
+            flagrec = false;
+                        pc.putc(num1);//data[idx]);   
+            }
+        }
 }
\ No newline at end of file