You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Use SerialPort serialPort("/dev/ttyACM0", 13000); instead if you want to provide a custom baud rate
73
+
serialPort.SetTimeout(-1); // Block when reading until any data is received
74
+
serialPort.Open();
71
75
72
76
// Write some ASCII datae
73
-
serialPort0.Write("Hello");
77
+
serialPort.Write("Hello");
74
78
75
-
// Read some data back
79
+
// Read some data back (will block until at least 1 byte is received due to the SetTimeout(-1) call above)
76
80
std::string readData;
77
-
serialPort0.Read(readData);
81
+
serialPort.Read(readData);
78
82
79
83
// Close the serial port
80
-
serialPort0.Close();
84
+
serialPort.Close();
81
85
}
82
86
```
83
87
@@ -87,42 +91,15 @@ If the above code was in a file called `main.cpp` and you had installed `CppLinu
87
91
g++ main.cpp -lCppLinuxSerial
88
92
```
89
93
90
-
For more examples, see the `.cpp` files in `test/unit/`.
91
-
92
-
## Dependencies
93
-
94
-
The following table lists all of the libraries dependencies.
95
-
96
-
<table>
97
-
<thead>
98
-
<tr>
99
-
<td>Dependency</td>
100
-
<td>Comments</td>
101
-
</tr>
102
-
</thead>
103
-
<tbody>
104
-
<tr>
105
-
<td>C++14</td>
106
-
<td>C++14 used for strongly typed enums, `std::chrono` and literals.</td>
107
-
</tr>
108
-
<tr>
109
-
<td>stdio.h</td>
110
-
<td>snprintf()</td>
111
-
</tr>
112
-
<tr>
113
-
<td>stty</td>
114
-
<td>Used in unit tests to verify the serial port is configured correctly.</td>
115
-
</tr>
116
-
</tbody>
117
-
</table>
94
+
For more examples, see the files in `test/`.
118
95
119
96
## Issues
120
97
121
98
See GitHub Issues.
122
99
123
100
## FAQ
124
101
125
-
1. My code stalls when calling functions like `SerialPort::Read()`. This is probably because the library is set up to do a blocking read, and not enough characters have been received to allow `SerialPort::Read()` to return. Use`SerialPort::SetNumCharsToWait()`to determine how many characters to wait for before returning (set to 0 for non-blocking mode).
102
+
1. My code stalls when calling functions like `SerialPort::Read()`. This is probably because the library is set up to do a blocking read, and not enough characters have been received to allow `SerialPort::Read()` to return. Call`SerialPort::SetTimeout(0)`before the serial port is open to set a non-blocking mode.
0 commit comments