-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,45 @@ | ||
# serialport | ||
|
||
![Linux Port Iteration Result](assets/Linux_Iteration_Demo.png) | ||
|
||
## Examples | ||
|
||
### Port Iteration | ||
|
||
```zig | ||
// ... | ||
var it = try serialport.iterate(); | ||
defer it.deinit(); | ||
while (try it.next()) |stub| { | ||
// Stub name used only to identify port, not to open it. | ||
std.log.info("Found COM port {s}", .{stub.name}); | ||
std.log.info("Port file path: {s}", .{stub.path}); | ||
} | ||
// ... | ||
``` | ||
|
||
### Polling Reads | ||
|
||
```zig | ||
// ... | ||
var port = try serialport.open(my_port_path); | ||
defer port.close(); | ||
try port.configure(.{ | ||
.baud_rate = .B115200, | ||
}); | ||
const reader = port.reader(); | ||
var read_buffer: [128]u8 = undefined; | ||
while (true) { | ||
if (try port.poll()) { | ||
const read_size = try reader.read(&read_buffer); | ||
std.log.info("Port bytes arrived: {any}", .{read_buffer[0..read_size]}); | ||
} | ||
} | ||
// ... | ||
``` |