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)
> (serial-ports) '("/dev/ttyUSB0")
procedure
> (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
> (define-values (in out) (open-serial-port "/dev/ttyUSB0" #:baudrate 115200)) > (write-bytes #"x1AVx3\n" out) 7
> (let loop () (define read-result (read-bytes-avail!* read-buffer port)) (cond [(or (eof-object? read-result) (and (number? read-result) (not (= read-result 0)))) (display (bytes->string/utf-8 (read-bytes read-result port))) (display "")] [else (sleep 0.1)]) (loop)) eval: unable to replay evaluation of (let loop () (define
read-result (read-bytes-avail!* read-buffer port)) (cond
((or (eof-object? read-result) (and (number? read-result)
(not (= read-result 0)))) (display (bytes->string/utf-8
(read-bytes read-result port))) (display "")) (else (sleep
0....