All Projects → steveturner → netty-transport-purejavacomm

steveturner / netty-transport-purejavacomm

Licence: Apache-2.0 license
A netty serial pipeline using JNA and PureJavaComm

Programming Languages

ruby
36898 projects - #4 most used programming language
java
68154 projects - #9 most used programming language
Puppet
460 projects

Projects that are alternatives of or similar to netty-transport-purejavacomm

Scriptcommunicator serial Terminal
Scriptable cross-platform data terminal which supports: serial port, UDP, TCP, SPI, I2C and CAN.
Stars: ✭ 462 (+1440%)
Mutual labels:  serial, serialport
pySerialTransfer
Python package to transfer data in a fast, reliable, and packetized form
Stars: ✭ 78 (+160%)
Mutual labels:  serial, serialport
Cserialport
基于C++的轻量级开源跨平台串口类库Lightweight cross-platform serial port library based on C++
Stars: ✭ 296 (+886.67%)
Mutual labels:  serial, serialport
Node Serialport
Access serial ports with JavaScript. Linux, OSX and Windows. Welcome your robotic JavaScript overlords. Better yet, program them!
Stars: ✭ 5,015 (+16616.67%)
Mutual labels:  serial, serialport
Usbserial
Usb serial controller for Android
Stars: ✭ 1,301 (+4236.67%)
Mutual labels:  serial, serialport
Qtswissarmyknife
QSAK (Qt Swiss Army Knife) is a multi-functional, cross-platform debugging tool based on Qt.
Stars: ✭ 196 (+553.33%)
Mutual labels:  serial, serialport
P5.serialport
Serial Port API and Server for p5.js
Stars: ✭ 120 (+300%)
Mutual labels:  serial, serialport
serial2mqtt
Serial to MQTT adapter serivce
Stars: ✭ 21 (-30%)
Mutual labels:  serial, serialport
Quad-Serial
Quad serial project with FTDI CI's, Isolation and 1.8~5.5v UART port.
Stars: ✭ 17 (-43.33%)
Mutual labels:  serial
gba-remote-play
Stream Raspberry Pi games to a GBA via Link Cable
Stars: ✭ 356 (+1086.67%)
Mutual labels:  serial
TrialLicensing
Swift framework to deal with licensing and time-based trial periods in macOS apps.
Stars: ✭ 36 (+20%)
Mutual labels:  serial
SVisual
Monitoring and record(save) of data for Arduino and STM32
Stars: ✭ 21 (-30%)
Mutual labels:  serial
micronova controller
Allows you to easily control via MQTT any Micronova equiped pellet stove. (MCZ, Extraflame, Laminox, and many others brands!)
Stars: ✭ 30 (+0%)
Mutual labels:  serial
ESP8266
ESP8266 WiFi module Library for Arduino
Stars: ✭ 31 (+3.33%)
Mutual labels:  serial
CanSat-Ground-station
Code for a CanSat or OBCs GUI ground station where different sensor data are displayed in real time. No sensors needed to try it.
Stars: ✭ 55 (+83.33%)
Mutual labels:  serial
ckwin
C-Kermit for Windows - scriptable internet and serial communications with terminal emulation
Stars: ✭ 35 (+16.67%)
Mutual labels:  serial
uPy-rosserial
An implementation of rosserial for uPy.
Stars: ✭ 19 (-36.67%)
Mutual labels:  serial
Simulink-Arduino-Serial
How to connect Arduino and Simulink
Stars: ✭ 54 (+80%)
Mutual labels:  serial
serialTool
一个简单的web串口工具
Stars: ✭ 30 (+0%)
Mutual labels:  serial
tabby
A terminal for a more modern age
Stars: ✭ 40,910 (+136266.67%)
Mutual labels:  serial

netty-transport-purejavacomm

A netty serial pipeline using JNA and PureJavaComm

#Intro Typically when interacting with serial ports from Java you have three options:

All are actually mature solutions but SerialIO is a commercial product and JSS and RxTx either require the native libraries to be intalled/compiled for the host platform. Personally, I've had issues with RxTx and the C++ source code can be a bit difficult to understand when a problem arrises.

#Solution PureJavaComm is a solution which I've had the privilege to work with extensively. What's nice about PureJavaComm is that it is entirely written in Java except for specific calls to platform functions which leverage JNA. In their own words:

PJC is written 100% in Java so it is easy for Java programmers to develop and debug and it requires no native libraries. Native access to the underlaying operating system's serial port programming interface is provided by the wonderful JNA library which takes away all the pain of compiling and deploying native code.

In my own use, I've found PureJavaComm to be extremely easy to use and extend to serial devices with their own platform libraries by leveraging JNAerator to generate JNA wrappers to library code.

##Netty And Serial Netty already provides an excellent wrapper to interacting with a serial port at the application level via the RxTx transport. However, as mentioned above you still need the native libraries installed. To alleviate this, I've created Netty Transport PureJavaComm Here's a quick sample based on the existing Netty RxTx code:

package com.beauhinks.example.purejavacomm;

import com.beauhinks.purejavacomm.PureJavaCommChannel;
import com.beauhinks.purejavacomm.PureJavaCommDeviceAddress;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.oio.OioEventLoopGroup;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;
import purejavacomm.CommPortIdentifier;

import java.util.Enumeration;


/**
 * Sends one message to a serial device
 */
public final class PureJavaCommClient {

    public static void main(String[] args) throws Exception {
        CommPortIdentifier portid = null;
        Enumeration e = CommPortIdentifier.getPortIdentifiers();
        while (e.hasMoreElements()) {
            portid = (CommPortIdentifier) e.nextElement();
            System.out.println("found " + portid.getName());
        }
        EventLoopGroup group = new OioEventLoopGroup();
        try {
            Bootstrap b = new Bootstrap();
            b.group(group)
                    .channel(PureJavaCommChannel.class)
                    .handler(new ChannelInitializer<PureJavaCommChannel>() {
                        @Override
                        public void initChannel(PureJavaCommChannel ch) throws Exception {
                            ch.pipeline().addLast(
                                    new LineBasedFrameDecoder(32768),
                                    new StringEncoder(),
                                    new StringDecoder(),
                                    new PureJavaCommClientHandler()
                            );
                        }
                    });

            ChannelFuture f = b.connect(new PureJavaCommDeviceAddress("/dev/ttyS0")).sync();
            f.channel().write()
            f.channel().closeFuture().sync();
        } finally {
            group.shutdownGracefully();
        }
    }

    private PureJavaCommClient() {
    }
}

To get up and running and test the code there are two VM's in the develop branch, master and slave. Start the master with vagrant up and then cd into the slave directory and start the slave with vagrant up. cd to /Vagrant and run mvn exec:java to run the samples. The master and slave VM's will then exchange messages over a simulated serialport via a host named pipe. The great thing about using Netty to interact with a serial port is that you can easily integrate Kryo, MsgPack, or JSON into your pipeline to handle serialization and pass arbitrary POJOS or commands over a serial port without writing a bunch of one-off parsing logic typically seen when dealing with serial ports.

Fork and enjoy.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].