package serial

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
module Make (T : sig ... end) : sig ... end

You'll probably want to use make below.

module type T = sig ... end
val make : Serial__.Connection.t -> (module T)

Create a module using Connection.t

let module DaytimeSerial = (val Serial.make connection)
val baud_rate : Serial__.Connection.t -> int
val connect : port:string -> baud_rate:int -> (Serial__.Connection.t, exn) Lwt_result.t

Create a connection. Returns a connection Lwt_result.t.

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 _ -> Lwt.return () (* TODO: handle exception *)
val connect_exn : port:string -> baud_rate:int -> Serial__.Connection.t Lwt.t

Create a connection. May raise an exception (e.g. port not found).

Serial.connect_exn ~port ~baud_rate >>= fun connection ->
Lwt_io.printl "Awaiting input. Enter 'quit' when done..." >>= fun () ->
Serial.io_loop connection (Some "quit")
val io_loop : Serial__.Connection.t -> string option -> unit Lwt.t

Enters a loop reading from serial -> stdout, stdin -> serial. Optionally exit loop when $TERMINATOR is entered.

io_loop connection (Some "done!")
val read_line : Serial__.Connection.t -> string Lwt.t
val write_line : Serial__.Connection.t -> string -> unit Lwt.t
val write : Serial__.Connection.t -> string -> unit Lwt.t

Unlike write_line, write does not terminate the string with a newline

val port : Serial__.Connection.t -> string
val wait_for_line : Serial__.Connection.t -> string -> timeout_s:float option -> Serial__.Wait_for.t Lwt.t

Waits for a keyword with optional timeout.

wait_for_line connection "wait for me!" ~timeout_s:(Some 8.)
wait_for_line connection "wait for me!" ~timeout_s:None

Returns either Received or TimedOut.

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" c
OCaml

Innovation. Community. Security.