read write test for UART/RS232, debug via USB

Dependencies:   mbed

Fork of DataLoggerRS232trial by Terry Tam

Revision:
2:6ebf09171de9
Parent:
1:875d121e9ce9
diff -r 875d121e9ce9 -r 6ebf09171de9 main.cpp
--- a/main.cpp	Wed Sep 14 10:32:49 2016 +0000
+++ b/main.cpp	Sun Sep 18 05:45:40 2016 +0000
@@ -2,43 +2,58 @@
 #include "DataLoggerRS232.h"
  
 Serial pc (USBTX, USBRX); // tx, rx
-DataLoggerRS232 dataLogger (PA_2,PA_3);  // tx, rx
+Serial dataLogger (PA_2,PA_3);  // tx, rx
 
-char DLcommand;
+//char DLcommand;
+int abc[]={104,87,36,19,0,0,0,104,17,4,51,51,51,51,63,22};
+
 char DLcommand2;
 int main() {    
 
     pc.baud(115200);
     pc.printf("PC and Datalogger serial set up complete !!\n\r");
-    dataLogger.baud(9600);
+    dataLogger.baud(2400);
+    dataLogger.format(9,SerialBase::Even,1);
     pc.printf("Here !!\n\r");
-    
+ int i;
+ const int m=16;
     while(1) {
-        if(pc.readable()) {
+        i=0;
+//        if(pc.readable()) {
+            if(dataLogger.writeable()){
+            for(i=0;i<m;i++){
+            dataLogger.putc(abc[i]);
+             }            
+             pc.printf("T");
+ //           dataLogger.printf("%c",DLcommand);
+//            dataLogger.count = 0;
+//            DLcommand = pc.getc();
+//            pc.printf("\n\r%c\n\r",DLcommand);
             
-            dataLogger.count = 0;
-            DLcommand = pc.getc();
-            pc.printf("\n\r%c\n\r",DLcommand);
-            
-            dataLogger.putc(DLcommand);
-            dataLogger.get_ECU_databyte();
+//            dataLogger.putc(DLcommand);
+//            dataLogger.get_ECU_databyte();
         }
-        //dataLogger.display_ECU_databyte(); 
-        wait(2);
+//        dataLogger.display_ECU_databyte(); 
+//            wait(4);
 //-----------------------------------------------        
-        if(dataLogger.readable()) {
+  if(dataLogger.readable()) {
+            pc.printf("R");
+            char DLcommand[25];
+//          dataLogger.count = 0;
+for(i=0;i<25;i++){
+            DLcommand[i]= dataLogger.getc();
+            pc.putc(DLcommand[i]);
+             }
+ //           DLcommand = dataLogger.getc();
+//            DLcommand2 = dataLogger.getc();
+    
+            ;
+//            pc.printf("\n\r%c\n\r",DLcommand2);
+ //         dataLogger.putc(DLcommand); 
+//          dataLogger.get_ECU_databyte();
+      }
+//      dataLogger.display_ECU_databyte(); 
+        
+      wait(4);
             
-            dataLogger.count = 0;
-            DLcommand = dataLogger.getc();
-            DLcommand2 = dataLogger.getc();
-            pc.printf("\n\r%c\n\r",DLcommand);
-            pc.printf("\n\r%c\n\r",DLcommand2);
-            dataLogger.putc(DLcommand);
-            dataLogger.get_ECU_databyte();
-        }
-        dataLogger.display_ECU_databyte(); 
-        
-        wait(2);
-            
-    }
-}
\ No newline at end of file
+    }}