File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ ## FileHandle example
2
+
3
+ The example monitors a serial console device, and every time it outputs a character, send it to the console back and toggle LED2.
4
+
5
+ 1 . Flash the board, and ensure the target's USB is plugged into the PC.
6
+ 2 . Open serial console (select associated COM port, transmission speed: 19200 bps).
7
+ 3 . Reset the target.
8
+ 4 . Every time that device outputs a character, the character should appear in the console and LED2 should be toggled LED2.
9
+
10
+ ** Note:** You can check the associated serial port using ` mbedls ` command.
Original file line number Diff line number Diff line change
1
+ #include " mbed.h"
2
+
3
+ static DigitalOut led2 (LED2);
4
+
5
+ // UARTSerial derives from FileHandle
6
+ static UARTSerial device (STDIO_UART_TX, STDIO_UART_RX);
7
+
8
+ int main ()
9
+ {
10
+ // Perform device-specific setup
11
+ device.set_baud (19200 );
12
+
13
+ // Once set up, access through the C library
14
+ FILE *devin = fdopen (&device, " r" );
15
+
16
+ while (1 ) {
17
+ putchar (fgetc (devin));
18
+ led2 = !led2;
19
+ }
20
+ }
You can’t perform that action at this time.
0 commit comments