Need a small program to read serial data from microcontroller via USB. Usually i was using screen
cli.
- to acquire data form USB serial port, syscalls is used. one for opening file descriptor, one for acquiring termios, one for configuring port and one for each character received.
- termios is a structure that configures port. probably stands for terminal OS.
- comptime functions/structures can be used as interface in zig
- zig is good for cross-compiling due to possibility of determining OS during comptime.
[100]u8
is array/slice,[]u8
is pointer to array/slice.- speed for port transferring in zig can not be chosen as cross-platform, only as
os.linux.B115200
os.open
requires 3 arguments, in case file is only opened without creating one, 3-rd argumentmode
is not required (set to 0)- for some reason
{}
need to be added at the end ofstd.heap.GeneralPurposeAllocator(.{}){}
statement - cli parameters can be transformed to slice of strings
switch
cannot be used with strings
- Serial Programming HOWTO
https://tldp.org/HOWTO/Serial-Programming-HOWTO/x115.html - termios man page
https://man7.org/linux/man-pages/man3/termios.3.html - termios structure
https://www.mkssoftware.com/docs/man5/struct_termios.5.asp - Linux Serial Ports Using C/C++
https://blog.mbedded.ninja/programming/operating-systems/linux/linux-serial-ports-using-c-cpp/ - working zig version for serial communication
https://github.com/MasterQ32/zig-serial
$ zig build-exe main.zig --name serial
- handle errors properly
- add tests
- add handler for buffer out of bound