Samuel Mokrani
/
USBSerial_Echo
USBSerial echo example
main.cpp@4:583cafe16ec7, 2011-11-17 (annotated)
- Committer:
- samux
- Date:
- Thu Nov 17 12:01:32 2011 +0000
- Revision:
- 4:583cafe16ec7
- Parent:
- 0:5cd54b826046
- Child:
- 5:fa2fa6aa36b1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 0:5cd54b826046 | 1 | #include "mbed.h" |
samux | 0:5cd54b826046 | 2 | #include "USBSerial.h" |
samux | 0:5cd54b826046 | 3 | |
samux | 0:5cd54b826046 | 4 | //Virtual serial port over USB |
samux | 0:5cd54b826046 | 5 | USBSerial serial; |
samux | 0:5cd54b826046 | 6 | Serial pc(USBTX, USBRX); |
samux | 0:5cd54b826046 | 7 | |
samux | 0:5cd54b826046 | 8 | int main(void) { |
samux | 4:583cafe16ec7 | 9 | char buf[128]; |
samux | 4:583cafe16ec7 | 10 | char echo[128]; |
samux | 0:5cd54b826046 | 11 | while(1) |
samux | 0:5cd54b826046 | 12 | { |
samux | 0:5cd54b826046 | 13 | serial.scanf("%s", buf); |
samux | 4:583cafe16ec7 | 14 | |
samux | 4:583cafe16ec7 | 15 | // build the echo response |
samux | 4:583cafe16ec7 | 16 | sprintf(echo, "recv: %s\r\n", buf); |
samux | 4:583cafe16ec7 | 17 | |
samux | 4:583cafe16ec7 | 18 | //send to the virtual serial port and the mbed serial port |
samux | 4:583cafe16ec7 | 19 | serial.print(echo); |
samux | 4:583cafe16ec7 | 20 | pc.printf("%s", echo); |
samux | 0:5cd54b826046 | 21 | } |
samux | 0:5cd54b826046 | 22 | } |