Skip to content

MacFJA/OBD2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

8 Commits

Repository files navigation

OBD for JAVA

Supported commands

Although any commands can be send with this lib, the list of pure object command does not cover all existing commands.

Some commands are missing, because I didn't find documentation about it or because my car is pretty old and doesn't support many OBD-II commands.

Here are the list of all known command and there status (implemented or not):

Usage

Basic example

importio.github.macfja.obd2.elm327.Commander;
importio.github.macfja.obd2.elm327.command.*;
importio.github.macfja.obd2.command.livedata.*;

publicclassExample{
Commandercommander=newCommander();

publicstaticvoidmain(String[]args) {
newExample();
}

publicExample() {
commander.setCommunicationInterface(OBD2.getOutputStream(),OBD2.getInputStream());
System.out.println(commander.sendCommand(newDeviceDescription()));
// Should print something like "OBDII to RS232 Interpreter"
System.out.println(commander.sendCommand(newEngineRPM()));
// Should print something like "875rpm"
}
}

Sending custom command

importio.github.macfja.obd2.response.RawResponse;
importio.github.macfja.obd2.Commander;
importio.github.macfja.obd2.Command;
importio.github.macfja.obd2.Response;
importio.github.macfja.obd2.Unit;
importio.github.macfja.obd2.SimpleCommands;

Commandercommander;

// Setup the `commander`
// [...]

CommandcustomCommand=newCommand() {
@Override
publicStringgetRequest() {
return"MyCode";
}

@Override
publicResponsegetResponse(byte[]rawResult)throwsScriptException{
returnnewRawResponse(rawResult) {};
}
};
commander.sendCommand(customCommand);

// OR

CommandcustomCommand2=SimpleCommands.create("My Code");
commander.sendCommand(customCommand2);

Installation

From the sources

Clone the project:

git clone https://github /MacFJA/OBD2.git

Install the project into your local Maven repository:

cd OBD2/
mvn clean
mvn install

Remove the source:

cd..
rm -r OBD2/

Add the dependency in your Maven project:

<project>
<!--...-->
<dependencies>
<!--...-->
<dependency>
<groupId>io.github.macfja</groupId>
<artifactId>obd2</artifactId>
<version>1.1.0</version>
</dependency>
<!--...-->
</dependencies>
<!--...-->
</project>

From a release

Go to therealase page,and download thejar.

Next add thejarin your project classpath.

With JitPack

The library is available online for Gradle, Maven, Sbt and Leiningen with the help ofJitPack.

See installation instruction here:(Spoiler: it's easy)