Program to show buffer fproblem

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 Ticker Box_Comms;                           // Ticker to send a command every 250ms
00004 Serial PC (USBTX,USBRX);                    // Comms with PC via USB cable
00005 Serial Comms (p28,p27);                     // External comms via RS232 IC
00006 
00007 void isr_Comms(void) {
00008     char reply[70];                         // Array to store reply in
00009     char Command[] = {0x01,'R',0x02,'P',0x03};
00010     int ReplyIndex=0;                       // Variable for indexing the read data
00011 
00012     for (int i=0;i<5;i++) {                 // Send the Command
00013         Comms.putc(Command[i]);
00014     }
00015     while (Comms.readable()) {              // While there is data on the line to read...
00016         reply[ReplyIndex] = Comms.getc();   // Read it!
00017         ReplyIndex++;
00018     }
00019     PC.printf("\n\rNumber of bytes received = %d,",ReplyIndex);
00020 }
00021 
00022 int main() {    
00023     Comms.baud(38400);                      //Set up the Baud rates for the comms
00024     Box_Comms.attach(&isr_Comms,0.25);      //Call the isr_Comms function every 1/4 second
00025     
00026     PC.printf("Testing Started");
00027 }