Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ZigEmbeddedGroup/serial
Serial port configuration library for Zig
https://github.com/ZigEmbeddedGroup/serial
serial serial-port uart zig zig-package ziglang
Last synced: 29 days ago
JSON representation
Serial port configuration library for Zig
- Host: GitHub
- URL: https://github.com/ZigEmbeddedGroup/serial
- Owner: ZigEmbeddedGroup
- License: mit
- Created: 2020-04-19T18:45:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-09T17:52:36.000Z (3 months ago)
- Last Synced: 2024-10-22T23:34:57.420Z (about 2 months ago)
- Topics: serial, serial-port, uart, zig, zig-package, ziglang
- Language: Zig
- Homepage:
- Size: 42 KB
- Stars: 56
- Watchers: 3
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-zig - ZigEmbeddedGroup/serial
README
# Zig Serial Port Library
Library for configuring and listing serial ports.
## Features
- Basic serial port configuration
- Baud Rate
- Parity (none, even, odd, mark, space)
- Stop Bits (one, two)
- Handshake (none, hardware, software)
- Byte Size (5, 6, 7, 8)
- Flush serial port send/receive buffers
- List available serial ports
- API: supports Windows, Linux and Mac## Example
```zig
// Port configuration.
// Serial ports are just files, \\.\COM1 for COM1 on Windows:
var serial = try std.fs.cwd().openFile("\\\\.\\COM1", .{ .mode = .read_write }) ;
defer serial.close();try zig_serial.configureSerialPort(serial, zig_serial.SerialConfig{
.baud_rate = 19200,
.word_size = 8,
.parity = .none,
.stop_bits = .one,
.handshake = .none,
});
```## Usage
### Library integration
Integrate the library in your project via the Zig package manager:
- add `serial` to your `.zig.zon` file by providing the URL to the archive of a tag or specific commit of the library
- to update the hash, run `zig fetch --save [URL/to/tag/or/commit.tar.gz]`### Running tests
The `build.zig` file contains a test step that can be called with `zig build test`. Note that this requires a serial port to be available on the system;
- Linux: `/dev/ttyUSB0`
- Mac: `/dev/cu.usbmodem101`
- Windows: `COM3`### Building the examples
You can build the examples from the `./examples` directory by calling `zig build examples`. Binaries will be generated in `./zig-out/bin` by default.
- Note that the `list_port_info` example currently only works on Windows