RXTXを使ってRaspberry PiとXbeeでシリアル通信(Communicate with Xbee using RXTX on Raspberry Pi)

Xbeeとの通信の利便性を図るためにjavaでxbeed(gpsdのようなもののイメージ)を作ろうかと画策中。コンセプトはこんな感じ。
(I’m planning to develop the xbeed which is similar to gpsd for convenient communication with xbee. The concept is like below.)

xbeed_concept

とりあえず、javaでシリアル通信をする必要があるのですが、これはRXTXというライブラリを使って実装できそうです。すでにRaspberry Pi用に用意されており、下記コマンドでインストールできます。
(To use serial communication in Java, there is RXTX library. This library is prepared for Raspberry Pi and you can install using below command.)

> apt-get install librxtx-java

詳しい使い方は説明しているサイトが多々あるため省略しますが、java起動時にいくつかオプションが必要になります。
(You need some options to execute Java which use RXTX library.)

> java -Djava.library.path=/usr/lib/jni -classpath "/usr/share/java/RXTXcomm.jar"

ただ、なぜか/dev/ttyAMA0にはエラーとなって接続できませんでした・・・xbeeを認識している/dev/ttyUSB0とは通信ができました。
(The error happens when I tried to connect to /tty/AMA0 and I couldn’t connect. However, when I tried to connect to /tty/USB0 which is mounted to xbee, I could connect correctly.)

Leave a comment