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
- Host: GitHub
- URL: https://github.com/calimero-project/serial-ffm
- Owner: calimero-project
- License: mit
- Created: 2023-01-20T18:39:22.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-11-28T19:06:44.000Z (6 months ago)
- Last Synced: 2025-11-30T23:27:06.544Z (6 months ago)
- Topics: foreign-function-memory, java, java-native, java-panama, jdk19, jdk20, jdk22, jdk23, linux, macos, panama, serial, serial-communication, serial-port, windows
- Language: Java
- Homepage:
- Size: 587 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Serial port communication using the Foreign Function and Memory API [](https://jitpack.io/#calimero-project/serial-ffm) [](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 ...
}
```