
Simplifies access to USB/Serial ports, offering coroutine support and Kotlin data types. Wraps jSerialComm for desktop and Android, excluding iOS support.
This library is a KMM (Kotlin Multiplatform Module) which makes it easier to access USB/Serial Ports from Kotlin code.
It wraps around the jSerialComm library on desktop, and either jSerialComm or USB Serial For Android on Android. (iOS is not currently supported)
This library provides:
| Platform | Supported | Artifact |
|---|---|---|
| Core | dev.mcarr.usb:library | |
| JVM | ✓ | dev.mcarr.usb:library-jvm |
| Android | ✓ | dev.mcarr.usb:library-android |
| Native | ✗ | |
| iOS | ✗ | |
| Web | ✗ |
// Get available devices
val devices = SerialPortList().get()
// Grab the USB device you want
val device = devices.first()
// Open the device (and close automatically)
device.use{
// Set the baud rate
it.setBaudRate(115200)
// Write some data to the port
it.write(data, writeTimeoutMilliseconds)
// Read the response
val response = it.read(responseSize, readTimeoutMilliseconds)
}Javadoc can be found here.
The setup instructions below assume that you're building a gradle project, with a TOML file for dependency management and KTS files for gradle scripts.
The instructions should still work for other setups with minor changes.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
// For the android serial library
maven(url = "https://jitpack.io")
}
}# libs.versions.toml
[versions]
usb = "1.0.0"
[libraries]
usb-library-core = { module = "dev.mcarr.usb:library", version.ref = "usb" }
usb-library-jvm = { module = "dev.mcarr.usb:library-jvm", version.ref = "usb" }
usb-library-android = { module = "dev.mcarr.usb:library-android", version.ref = "usb" }// app (not root) build.gradle.kts
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.usb.library.core)
}
}
val jvmMain by getting {
dependencies {
implementation(libs.usb.library.jvm)
}
}
val androidMain by getting {
dependencies {
implementation(libs.usb.library.android)
}
}
}
}add Linux native support
look into web support
test Android version
automate unit test CI
check if timeouts are working properly
This library is a KMM (Kotlin Multiplatform Module) which makes it easier to access USB/Serial Ports from Kotlin code.
It wraps around the jSerialComm library on desktop, and either jSerialComm or USB Serial For Android on Android. (iOS is not currently supported)
This library provides:
| Platform | Supported | Artifact |
|---|---|---|
| Core | dev.mcarr.usb:library | |
| JVM | ✓ | dev.mcarr.usb:library-jvm |
| Android | ✓ | dev.mcarr.usb:library-android |
| Native | ✗ | |
| iOS | ✗ | |
| Web | ✗ |
// Get available devices
val devices = SerialPortList().get()
// Grab the USB device you want
val device = devices.first()
// Open the device (and close automatically)
device.use{
// Set the baud rate
it.setBaudRate(115200)
// Write some data to the port
it.write(data, writeTimeoutMilliseconds)
// Read the response
val response = it.read(responseSize, readTimeoutMilliseconds)
}Javadoc can be found here.
The setup instructions below assume that you're building a gradle project, with a TOML file for dependency management and KTS files for gradle scripts.
The instructions should still work for other setups with minor changes.
// settings.gradle.kts
dependencyResolutionManagement {
repositories {
// For the android serial library
maven(url = "https://jitpack.io")
}
}# libs.versions.toml
[versions]
usb = "1.0.0"
[libraries]
usb-library-core = { module = "dev.mcarr.usb:library", version.ref = "usb" }
usb-library-jvm = { module = "dev.mcarr.usb:library-jvm", version.ref = "usb" }
usb-library-android = { module = "dev.mcarr.usb:library-android", version.ref = "usb" }// app (not root) build.gradle.kts
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.usb.library.core)
}
}
val jvmMain by getting {
dependencies {
implementation(libs.usb.library.jvm)
}
}
val androidMain by getting {
dependencies {
implementation(libs.usb.library.android)
}
}
}
}add Linux native support
look into web support
test Android version
automate unit test CI
check if timeouts are working properly