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.
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>
Javadoc for this package can be found at the following location: https://dscheerens.github.io/docs/ikbus-jssc-connector/latest/javadoc/
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.
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.