ZigEmbeddedGroup / serial

Serial port configuration library for Zig
MIT License
53 stars 18 forks source link
serial serial-port uart zig zig-package ziglang

Zig Serial Port Library

Library for configuring and listing serial ports.

Features

Example

// 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:

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;

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.