Skip to content

Commit 123fd62

Browse files
committed
Add FileHandle example
1 parent 2898b0e commit 123fd62

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

APIs_Platform/FileHandle/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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.

APIs_Platform/FileHandle/main.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

0 commit comments

Comments
 (0)