Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/helins/rxtx.clj
Serial IO based on RXTX from Clojure JVM
https://github.com/helins/rxtx.clj
clojure io iot jrxtx rxtx serial-port
Last synced: 26 days ago
JSON representation
Serial IO based on RXTX from Clojure JVM
- Host: GitHub
- URL: https://github.com/helins/rxtx.clj
- Owner: helins
- License: mpl-2.0
- Created: 2017-09-06T10:46:21.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2021-03-25T09:19:33.000Z (over 3 years ago)
- Last Synced: 2024-09-28T17:40:54.640Z (about 1 month ago)
- Topics: clojure, io, iot, jrxtx, rxtx, serial-port
- Language: Clojure
- Homepage:
- Size: 34.2 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# RXTX, using the serial port from Clojure JVM
[![Clojars
Project](https://img.shields.io/clojars/v/io.helins/rxtx.svg)](https://clojars.org/io.helins/rxtx)[![Cljdoc](https://cljdoc.org/badge/io.helins/rxtx)](https://cljdoc.org/d/io.helins/rxtx)
Simple API for doing serial IO.
Based on [jRxTx](https://github.com/openmuc/jrxtx).
Supports a (very) wide variety of platforms.
## Installation
There is a bit of a setup but nothing to worry about, it is fairly easy.
For more information about the process or if something goes wrong, go to
[jRxTx](https://github.com/openmuc/jrxtx).For instance, on a debian based distribution :
```
sudo apt install librxtx-java
```When starting your application or a repl, check if the "java.library.path"
property contains a path to the installed native libs. On debian, that should be
'/usr/lib/jni' :```clj
(System/getProperty "java.library.path")
```If this property is not properly set, you must do it yourself.
In your project file :
```clj
:jvm-opts ["-Djava.library.path=/PATH/TO/LIBS"]
```When executing your uberjar :
```sh
java -Djava.library.path=/PATH/TO/LIBS -jar your_program.jar
```## Usage
This is a very brief overview.
The [full API is available on Cljdoc](https://cljdoc.org/d/io.helins/rxtx).
In short, without error handling :
```clj
(require '[helins.rxtx :as rxtx])(with-open [port (rxtx/serial-port "/dev/ttyUSB0"
{:rxtx/baud-rate 9600
:rxtx/parity :even})];; Different things can be written to a serial port besides a byte array.
;;
(rxtx/write port
"Hello ")
(rxtx/write port
\w)
(rxtx/write port
111)
(rxtx/write port
[114 108 100]);; Reads the answer, up to 16 unsigned bytes, but with a timeout of 2000 milliseconds.
(println :answer
(String. (byte-array (rxtx/read port
16
2000)))))
```## License
Copyright © 2017 Adam Helinski
Licensed under the term of the Mozilla Public License 2.0, see LICENSE.