6.3.90.900
libserial: Portable Serial Port Access
Jan Dvořák <mordae@anilinux.org>
Serial port handling for Racket utilizing "libserialport".
The libserialport itself is a minimal, cross-platform shared library written in C that is intended to take care of the OS-specific details when writing software that uses serial ports.
It must be installed externally to this Racket module, preferrably via the system package manager.
(require libserialport) | package: libserialport |
A high-level interface to port enumeration, access and configuration.
syntax
syntax
procedure
(serial-ports) → (Listof Path-String)
Produce list of system serial port paths or names.
Example:
> (serial-ports) '("/dev/ttyUSB0")
procedure
Iterate over known serial port paths or names.
Produces Path-String values.
Example:
> (for ((serial-port (in-serial-ports))) (printf "found ~a\n" serial-port)) found /dev/ttyUSB0
procedure
(open-serial-port path [ #:baudrate baudrate #:bits bits #:parity parity #:stopbits stopbits #:flowcontrol flowcontrol])
→
Input-Port Output-Port path : Path-String baudrate : Positive-Integer = 9600 bits : Positive-Integer = 8 parity : Parity = 'none stopbits : Natural = 1 flowcontrol : Flow-Control = 'none
Opens (and configures) selected serial port for both reading and writing.
The default options correspond to the most frequently used null-modem case
typical for switches and other similar embedded devices.
Examples:
> (define-values (in out) (open-serial-port "/dev/ttyUSB0" #:baudrate 115200))
> (write-bytes #"x1AVx3\n" out) 7