@@ -106,6 +106,8 @@ The disadvantages are:
106106 * [ Serial Port Emulation] ( #SerialPortEmulation )
107107 * [ Unix Line Mode] ( #UnixLineMode )
108108 * [ Enable Terminal Echo] ( #EnableTerminalEcho )
109+ * [ Output to STDERR] ( #OutputToStderr )
110+ * [ Multiple Serial Ports] ( #MultipleSerialPorts )
109111* [ Libraries and Mocks] ( #LibrariesAndMocks )
110112 * [ Inherently Compatible Libraries] ( #InherentlyCompatibleLibraries )
111113 * [ Emulation Libraries] ( #EmulationLibraries )
@@ -1062,7 +1064,7 @@ test(myTest) {
10621064```
10631065
10641066<a name="EnableTerminalEcho"></a>
1065- #### Enable Terminal Echno
1067+ #### Enable Terminal Echo
10661068
10671069By default, the `stdin` of the terminal is set to `NOECHO` mode for consistency
10681070with the actual serial port of an Arduino microcontroller. However when running
@@ -1084,6 +1086,45 @@ void setup() {
10841086}
10851087```
10861088
1089+ <a name =" OutputToStderr " ></a >
1090+ #### Output to STDERR
1091+
1092+ By default, the ` Serial ` instance sends its output to the STDOUT (file
1093+ descriptor ` STDOUT_FILENO ` , i.e. 1). We can override that to send the output to
1094+ STDERR (file descriptor ` STDERR_FILENO ` ) using the
1095+ ` StdioSerial::setOutputFileDescriptor(int fd) ` method:
1096+
1097+ ``` C++
1098+ Serial.println(" This goes to STDOUT" );
1099+ Serial.setOutputFileDescriptor(STDERR_FILENO);
1100+ Serial.println(" This goes to STDERR" );
1101+ ```
1102+
1103+ <a name =" MultipleSerialPorts " ></a >
1104+ #### Multiple Serial Ports
1105+
1106+ By default, a default instance of ` StdioSerial ` class is created named ` Serial ` ,
1107+ which matches the behavior of the Arduino programming framework on actual
1108+ microcontrollers which a single serial port is provided by default.
1109+
1110+ Some microcontrollers provide multiple serial ports, often called ` Serial1 ` or
1111+ ` Serial2 ` . We can emulate that in EpoxyDuino by creating additional instances of
1112+ ` StdioSerial ` . The following creates a ` Serial1 ` instances bound to STDOUT, and
1113+ another ` Serial2 ` bound to STDERR:
1114+
1115+ ``` C++
1116+ #ifdef EPOXY_DUINO
1117+ StdioSerial Serial1(STDOUT_FILENO);
1118+ StdioSerial Serial2(STDERR_FILENO);
1119+ ...
1120+ void someFunction() {
1121+ Serial1.println("Print to STDOUT");
1122+ Serial2.println("Print to STDERR");
1123+ ...
1124+ }
1125+ #endif
1126+ ```
1127+
10871128<a name =" LibrariesAndMocks " ></a >
10881129## Libraries and Mocks
10891130
0 commit comments