Program to show buffer fproblem

Dependencies:   mbed

Committer:
ms523
Date:
Thu Dec 23 12:44:35 2010 +0000
Revision:
0:cdbac2e32a1b

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ms523 0:cdbac2e32a1b 1 #include "mbed.h"
ms523 0:cdbac2e32a1b 2
ms523 0:cdbac2e32a1b 3 Ticker Box_Comms; // Ticker to send a command every 250ms
ms523 0:cdbac2e32a1b 4 Serial PC (USBTX,USBRX); // Comms with PC via USB cable
ms523 0:cdbac2e32a1b 5 Serial Comms (p28,p27); // External comms via RS232 IC
ms523 0:cdbac2e32a1b 6
ms523 0:cdbac2e32a1b 7 void isr_Comms(void) {
ms523 0:cdbac2e32a1b 8 char reply[70]; // Array to store reply in
ms523 0:cdbac2e32a1b 9 char Command[] = {0x01,'R',0x02,'P',0x03};
ms523 0:cdbac2e32a1b 10 int ReplyIndex=0; // Variable for indexing the read data
ms523 0:cdbac2e32a1b 11
ms523 0:cdbac2e32a1b 12 for (int i=0;i<5;i++) { // Send the Command
ms523 0:cdbac2e32a1b 13 Comms.putc(Command[i]);
ms523 0:cdbac2e32a1b 14 }
ms523 0:cdbac2e32a1b 15 while (Comms.readable()) { // While there is data on the line to read...
ms523 0:cdbac2e32a1b 16 reply[ReplyIndex] = Comms.getc(); // Read it!
ms523 0:cdbac2e32a1b 17 ReplyIndex++;
ms523 0:cdbac2e32a1b 18 }
ms523 0:cdbac2e32a1b 19 PC.printf("\n\rNumber of bytes received = %d,",ReplyIndex);
ms523 0:cdbac2e32a1b 20 }
ms523 0:cdbac2e32a1b 21
ms523 0:cdbac2e32a1b 22 int main() {
ms523 0:cdbac2e32a1b 23 Comms.baud(38400); //Set up the Baud rates for the comms
ms523 0:cdbac2e32a1b 24 Box_Comms.attach(&isr_Comms,0.25); //Call the isr_Comms function every 1/4 second
ms523 0:cdbac2e32a1b 25
ms523 0:cdbac2e32a1b 26 PC.printf("Testing Started");
ms523 0:cdbac2e32a1b 27 }