package serial
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=5034e009b14e0ba3a82b48026de13b2df3d80f37e14bd013b5dbd062f698370c
sha512=3b56e99d7dc4d12cfc3c4624c1b8bf7d5b8aea80b0a60849bd25932af52584cef529075076c0a3e9f61da5db71fd80dc56a9df4b0325f1c3c11c931462ecfbda
Description
Added to opam-repository:
README
OSerial
OCaml Serial Module
Installation
opam install serialIf using dune, add serial to the libraries stanza.
Usage
open Lwt.Infix
let port = "/dev/pts/19" in
let baud_rate = 115200 in
Serial.connect ~port ~baud_rate >>= function
| Ok connection ->
Lwt_io.printl "Awaiting input. Enter 'quit' when done..." >>= fun () ->
Serial.io_loop connection (Some "quit")
| Error e -> Lwt_io.printlf "Error connecting: %s" (Printexc.to_string e)See examples for more.
No serial device to play around with?
socat -d -d pty,raw,echo=0 pty,raw,echo=0
# first two lines may be something like:
# "... N PTY is /dev/pts/14"
# "... N PTY is /dev/pts/19"
# open one using Serial, the other using socat
(or two connections via this library!):
socat - /dev/pts/14,raw,echo=0Supplied Functions
The function returns are wrapped in Lwt.t, so please read up on Lwt should you be unfamiliar with the library.
read_line : connection -> unit -> string Lwt.t
write_line : connection -> string -> unit Lwt.t
write : connection -> string -> unit Lwt.t
baud_rate : connection -> int
port : connection -> stringwait_for_line : connection -> string -> timeout_s:float option -> unit Lwt.t
open Lwt.Infix
wait_for_line connection "ok" ~timeout_s:(Some 5.) >>= function
| Received -> Lwt_io.printlf "ok received for %S" c
| TimedOut -> Lwt_io.printlf "didn't hear back in time for %S" cWaits for a keyword with optional timeout. Passing None to timeout_s means this can wait forever.
io_loop : connection -> string option -> unit Lwt.tOpens a two-way communication channel between stdin and the serial device. Usage: io_loop connection (Some "quit"). If None is supplied instead, does not exit for any keyword.
val make : Connection.t -> (module T)See below.
Usage (module-based)
Once you have a connection record, you can create module:
let module DaytimeSerial = (val Serial.make connection) Use the created module
DaytimeSerial.write_line "Regresaré como lo que soy: como una reina." >>= fun () ->
DaytimeSerial.io_loop (Some "Siniestra belleza")Modules or Records?
It's up to you. The functions are 1:1 equivalent. Side by side:
MySerial.write "Enamórate de ti. De la vida. Y luego de quien tú quieras."
Serial.write connection "Enamórate de ti. De la vida. Y luego de quien tú quieras."
Dev Dependencies
None
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building serial with each compiler on check.ci.ocaml.org, run of against opam-repository 8d8d144. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.1.0 (this version) | good | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure