One bundle project – Serial connection over RS-485 using Eclipse Kura

RS-485 standard (TIA/EIA-485) specifies a communication interface that uses differential signal lines to establish communication between devices. Majority of application consists of half-duplex transmission mode with a twisted pair copper wire as a physical medium. Each device turns its line driver only when transmitting. During remaining time the driver is kept turned off in order to allow other devices on network to operate by avoiding the data collision. It is the responsibility of the application-layer protocol to supervise data being exchanged.

In order to connect RS-485 to Raspberry Pi or BeagelBone Black we need to use appropriate HW converter. There are adapters that handle direction control automatically and ones that need external control. I’m using RS485 Board (3.3V version) from Wavesare.

Below is an example that that utilizes RS-485 Transceiver (like SP3485 or MAX3485). Converter that I’m using has RSE pin that control internal line drivers (it is connected to  DE and RE pins of SP3485). More information can be found in the datasheet.

Example code uses RSE line in order to turn on/off transmission driver. It is based on Eclipse Kura Serial Example and Device I/O example (from Kura Documentation and JavaDoc). I’m using Bndtools to develop OSGi bundles under Eclipse, that’s why the Bnd annotations are visible in the code.

Later, I will write post about how to use Bndtools to create bundles for Eclipse Kura.

Below is simple example that sets direction to transmit and sends some string to uart. You can implement reading using InputStream and direction pin.

package io.github.tobidi.obp.kura.comm.serialRS485;


import jdk.dio.DeviceConfig;
import jdk.dio.DeviceManager;
import jdk.dio.gpio.GPIOPin;
import jdk.dio.gpio.GPIOPinConfig;

import org.eclipse.kura.comm.CommConnection;
import org.eclipse.kura.comm.CommURI;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import aQute.bnd.annotation.component.Activate;
import aQute.bnd.annotation.component.Component;
import aQute.bnd.annotation.component.Reference;

public class SerialRS485Example {

	private static final Logger log = LoggerFactory

	ConnectionFactory connectionFactory;

	private CommConnection connOne;

	private InputStream isOne;

	private OutputStream osOne;

	public void setConnectionFactory(ConnectionFactory connectionFactory) {
		this.connectionFactory = connectionFactory;

	public void unsetConnectionFactory(ConnectionFactory connectionFactory) {
		this.connectionFactory = null;

	public void activate() {

		GPIOPinConfig pinConfig = new GPIOPinConfig(DeviceConfig.DEFAULT, 22,

		GPIOPin directionPin = null;

		try {
			directionPin = (GPIOPin),

		} catch (IOException e1) {
			log.error(e1.getMessage(), e1);

		if (connectionFactory != null) {

			try {
				String uri = new CommURI.Builder("/dev/ttyAMA0")

				connOne = (CommConnection) connectionFactory.createConnection(
						uri, 1, false);

				isOne = connOne.openInputStream();
				osOne = connOne.openOutputStream();

				byte[] array = "ping\n\r".getBytes();


				isOne = null;
				osOne = null;

				connOne = null;


			} catch (Exception e) {
				log.error(e.getMessage(), e);
		} else {
			log.warn("No ConnectionFactory");



One thought on “One bundle project – Serial connection over RS-485 using Eclipse Kura

  1. “Later, I will write post about how to use Bndtools to create bundles for Eclipse Kura.” – yes please! in lue of a blog, some tips would be useful!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s