calimero-project / serial-ffm

Serial communication library using the Foreign Function and Memory API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Serial port communication using the Foreign Function and Memory API

This Java library provides serial port access for Linux, macOS, and Windows using Java's Foreign Function and Memory (FFM) API.

Project Panama aims at improving interoperability between Java and native libraries. It provides the new Foreign Function & Memory API, and enables access to native code in pure Java.

Serial-ffm requires Java 22 (java.base) or newer. The implementation is a port of the serial-native C libraries written to use JNI.

The header files are generated using jextract, leveraging the gradle-jextract plugin in the gradle build file.

Build with Gradle

./gradlew build -x test

Examples

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

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 ...
}

About

Serial communication library using the Foreign Function and Memory API

License:MIT License


Languages

Language:Java 99.0%Language:C 1.0%