An open API service indexing awesome lists of open source software.

https://github.com/calimero-project/serial-ffm

Serial communication library using the Foreign Function and Memory API
https://github.com/calimero-project/serial-ffm

foreign-function-memory java java-native java-panama jdk19 jdk20 jdk22 jdk23 linux macos panama serial serial-communication serial-port windows

Last synced: 3 months ago
JSON representation

Serial communication library using the Foreign Function and Memory API

Awesome Lists containing this project

README

          

Serial port communication using the Foreign Function and Memory API [![](https://jitpack.io/v/calimero-project/serial-ffm.svg)](https://jitpack.io/#calimero-project/serial-ffm) [![](https://img.shields.io/badge/jitpack-master-brightgreen?label=JitPack)](https://jitpack.io/#calimero-project/serial-ffm/master)
=====

This Java library provides serial port access for Linux, macOS, and Windows using Java's [Foreign Function & Memory (FFM) API](https://openjdk.org/jeps/454)
([`java.lang.foreign`](https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/foreign/package-summary.html)).

`serial-ffm` requires Java 23 (_java.base_) or newer.
(Older versions exist for [JDK 19](https://github.com/calimero-project/serial-ffm/tree/jdk19), [JDK 21](https://github.com/calimero-project/serial-ffm/tree/jdk21), and [JDK 22](https://github.com/calimero-project/serial-ffm/releases/tag/jdk22)).
The implementation is a port of the [serial-native](https://github.com/calimero-project/serial-native) C libraries written to use JNI.

The Java bindings from native library headers are generated using [jextract](https://github.com/openjdk/jextract), leveraging the [gradle-jextract](https://plugins.gradle.org/plugin/io.github.krakowski.jextract) plugin in the gradle build file.

### Build with Gradle

./gradlew build -x test

Jextract is not run by default; to run it, pass `-PrunJextract`.

### Examples

Using a serial port named _portId_ in a try-with-resources statement:

```java
try (var port = SerialPort.open(portId)
.baudrate(19_200)
.databits(8)
.parity(Parity.Even)
.stopbits(StopBits.One)
.flowControl(FlowControl.None)) {

var in = port.inputStream();
var out = port.outputStream();
// use streams ...
}
```