Git Product home page Git Product logo

ikbus-jssc-connector's Introduction

I/K-bus jSSC connector

A package that enables I/K-bus communication links for serial ports by providing an IKBusConnection implementation using jSSC (Java Simple Serial Connector). With this package it is possible to read and write I/K-bus packets from/to your vehicle using an I/K-bus interface device, for example Rolf Resler's IBUS interface.

This package is to be used in conjunction with the ibus-core package.

Usage

NOTE: This package is currently not yet available on Maven. I will fix this a.s.a.p.

To use this package in your application add the following Maven dependency:

<dependency>
	<groupId>net.novazero.ikbus</groupId>
	<artifactId>ikbus-jssc-connector</artifactId>
	<version>1.0.0</version>
</dependency>

API

Javadoc for this package can be found at the following location: https://dscheerens.github.io/docs/ikbus-jssc-connector/latest/javadoc/

Reading I/K-bus packets

final String serialPortName = "ttyS0"; // For windows use something like "COM1".

try (IKBusConnection connection = new SerialPortIKBusConnection(serialPortName)) {
	
	IKBusPacketReader reader = connection.getPacketReader();
	
	IKBusPacketStreamElement packetStreamElement;
	while ((packetStreamElement = reader.read()) != null) {
		
		if (packetStreamElement.isValidPacket()) {
			System.out.println("[OK] " + packetStreamElement.getPacket());
		} else {
			System.out.println("[ERR] " + IKBusUtils.bytesToHex(packetStreamElement.getData()));
		}
		
	}
	
} catch (IKBusIOException e) {
	System.err.println("Failed to read from " + serialPortName + " due to: " + e);
}

Note that you can use the SerialPortIKBusConnection.getAvailableSerialPorts() method to find the names of the serial ports which are available on your system.

Writing I/K-bus packets

IKBusPacket packet = new IKBusPacket((byte)0x50, (byte)0x68, new byte[]{(byte)0x32, (byte)0x11});

try (IKBusConnection connection = new SerialPortIKBusConnection(serialPortName)) {
	
	IKBusPacketWriter writer = connection.getPacketWriter();
	
	writer.write(packet);
	
	// Give the interface some time to send/flush the packet.
	try {
		Thread.sleep(1000);
	} catch (InterruptedException e) {
		throw new RuntimeException(e);
	}
	
} catch (IKBusIOException e) {
	System.err.println("Failed to write to " + serialPortName + " due to: " + e);
}

Note that the Thread.sleep() call is required since without it the serial port would be closed immediately. Any data that was not yet physically written to the I/K-bus network will not be transmitted.

ikbus-jssc-connector's People

Contributors

dscheerens avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.