# \[ANN\] Serialport - new serial communication library

**URL:** <https://discuss.ocaml.org/t/ann-serialport-new-serial-communication-library/17594>\
**Category:** Community\
**Tags:** unix, announce\
**Created:** [December 13, 2025, 4:34pm UTC](https://discuss.ocaml.org/t/ann-serialport-new-serial-communication-library/17594 "2025-12-13T16:34:30Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![dx3mod](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/dx3mod/32/6704_2.png) [@dx3mod](https://discuss.ocaml.org/u/dx3mod)\
**Post date:** [December 13, 2025, 4:34pm UTC](https://discuss.ocaml.org/t/ann-serialport-new-serial-communication-library/17594/1 "2025-12-13T16:34:30Z")

</div>

Hi there!

I’m happy to announce the first release of the [serialport](https://github.com/dx3mod/serialport) library. The library is planned to be a cross-platform library for serial port communication in OCaml, which supports both POSIX and Windows systems. It provides synchronous and asynchronous interfaces using various I/O libraries (like Lwt and other).

The library currently only supports POSIX systems.

![](https://gist.githubusercontent.com/dx3mod/402ef4c5f3f06645c6c7100da2e8676f/raw/31f21f19923ed2dd4a1a477d8cbbc1d06d59f07b/serialport.svg)

The main motivation behind creating this project is to address the lack of a comprehensive library for managing serial port communication in different environments, as well as the lack of an intuitive API for this task. The existing [OSerial](https://github.com/m-laniakea/oserial) library has significant limitations in terms of functionality and future development, making it unsuitable for use in modern environments.

The serial port library is most inspired by similar implementations in other languages, such as Rust’s serialport and Golang’s bugst/go-serial.

#### Usage

Typically, an example of usage is communication between a PC and an Arduino board or other devices via an old-school serial port.

```ocaml
# #require "serialport.unix";;
 (* #require "serialport.lwt";; *)

# let port_opts = Serialport.Port_options.make ~baud_rate:9600 ()
  and port_name = "/dev/ttyUSB0" in

  Serialport_unix.with_open_communication ~opts:port_opts port_name
    begin fun ser_port ->
      (* Get channels abstractions for high-level working with I/O without buffering. *)
      let ic, oc = Serialport_unix.to_channels ser_port in
      (* Wait until Arduino has been initialized. *)
      Unix.sleep 2;
      (* Send the message to the Arduino via the serial port. *)
      Out_channel.output_string oc "Hello from PC!\n";
      (* Read the response from the serial port. *)
      In_channel.input_line ic
    end

```

Enjoy it!

#### Windows supports

I will be implementing Windows support in the next version (coming soon).

#### P.S.

I would be delighted to discuss your ideas and suggestion!

---

_[View the full topic](https://discuss.ocaml.org/t/ann-serialport-new-serial-communication-library/17594)._
