0

I am trying to create a Java obd2 scanner app for my mitsubishi lancer mx 1997 which use MUTII protocol over OBD2. Can anybody help me to read MUT request codes using jd2xx library. I have tried the below program, but it didn read engine RPM.

package lancerscan;

import jd2xx.JD2XX;

public class Test2 {

    public static void main(String[] args) throws Exception {

    JD2XX jd = new JD2XX();
    jd.open(0);
    jd.setBaudRate(38400);
    jd.setDataCharacteristics(
            8, JD2XX.STOP_BITS_1, JD2XX.PARITY_NONE);
    jd.setFlowControl(
            JD2XX.FLOW_NONE, 0, 0);
    jd.setTimeouts(1000, 1000);

    String msg = "21";
    int ret = jd.write(msg.getBytes());
    System.out.println(ret + " bytes sent.");

    int rd = jd.read();
    System.out.println(">>>" + rd);

    int status = jd.getQueueStatus();
    byte[] data = new byte[(int) status];
    long lngBytesReturned = jd.read(data, 0, data.length);

    System.out.println("======= " + lngBytesReturned);
    }
}

MUT request code for Engine RPM is 0x21 more MUT request codes can be found here

similar C programs which works fine is here; main prjct files are here

Thanks, harsha

harshadura
  • 234
  • 1
  • 2
  • 11

2 Answers2

2

First your using a different baud rate to that in the example. The example uses 15625 baud but you are using 38400 baud.

Secondly you are missing some of the setup commands. I am not sure if this will make a difference but its something that is different between your code and the example.

Mitsubishi require you to set the car ECU into diagnostic mode by sending 0x00 at a rate of 5 baud on one of the pins. On the OpenPort 1.3D cable this translates to setting the break to on for 1800 ms and then turning it off. You can see this is done with the ftdimut_init() command from the libftdimut.c file.

      printf("Sending 0x00 at 5 baud\n");

      printf("Break on......\n");
      ftStatus = FT_SetBreakOn(ftdimut_ftHandle);
      if(ftStatus != FT_OK) return ftStatus;
      ftdimut_msleep(1800);
      printf("Break off......\n");
      ftStatus = FT_SetBreakOff(ftdimut_ftHandle);
      if(ftStatus != FT_OK) return ftStatus;

The car ECU will then send you 4 bytes containing the ECU ID. This can then be used to check the ECU correctly entered diagnostic mode. You can see this in libftdimut.c.

      ftStatus = FT_Read(ftdimut_ftHandle, buf, 4, &bytesRead);
      if(ftStatus != FT_OK) return ftStatus;

      if(bytesRead == 4) {
        return FT_OK;
      }

Now assuming that you got the 4 bytes back you can start to send the diagnostic codes such as 0x17 or 0x21.

niallm90
  • 41
  • 5
1

I just saw your post on my blog, niallm answer is correct, you need to do a 5 baud init first which involves driving the KLine, you can use something like the 5 baud init posted in that answer, more info about the protocol:

http://evoecu.logic.net/wiki/MUT_Protocol

After getting a 4 byte response you can start sending requests at 15625 baud (I'm communicating with a 94 3000GT so the CEL light stops blinking), also in my case I send the converted values (0x21 = 33 decimal) as a byte array.

Reses
  • 31
  • 3
  • seems like setting baud to 5 isnt possible with jd2xx, it gives me a IOexpection saying. `Exception in thread "main" java.io.IOException: other error (-1) at jd2xx.JD2XX.setBaudRate(Native Method) at lancerscan.Test.main(Test.java:11) Java Result: ` Javadoc: http://home.arcor.de/mbussi/Sim-Doc/jd2xx/JD2XX.html#setBaudRate%28int%29 could you please provide me a working example of this kind of program? thank you. – harshadura May 31 '14 at 14:41
  • 1
    Sure, drive the K-line with breaks: jd.setBreakOn(); try { Thread.sleep(1800); } catch(InterruptedException ex) { Thread.currentThread().interrupt(); } jd.setBreakOff(); int bytesAvailable = jd.getQueueStatus(); if(bytesAvailable == 4){ System.out.println("INIT complete"); } – Reses Jun 01 '14 at 04:38
  • Thanks, But how can i use baud 5 with this code to init. using baud 5 for is not possible with jd2xx ? can u suggest an equivalent baud to use. – harshadura Jun 01 '14 at 06:50
  • 1
    You can't set that baud rate, that's why you use the above code, to drive the K line as the MUT protocol init requires, sending 0x00 at 5 baud (200ms interval), 0000 0000 1 <-- stop bit, the first 8 bits are the 0x00, sent at 200ms intervals (1800ms with the k-line low), after the 1800ms break the last bit is the stop bit. – Reses Jun 01 '14 at 21:24
  • Hi Reses, Could you please tell me what I am doing wrong here. I have written this program now: https://gist.github.com/harshadura/0ec66ff67064d653060b i get a reply saying: `1 2 3 4 INIT complete 2 bytes sent. Engine RPM : >>> 6` – harshadura Jun 02 '14 at 15:47
  • I think that you should read the queue before sending another INIT: byte[] rd = jd.read(bytesAvailable); If it was a 4 byte read, switch to 15625 and start sending requests: int available= jd.getQueueStatus(); if(available==2){ byte[] response = jd.read(available); System.out.println("Engine RPM : >>> " + response[1]); } – Reses Jun 04 '14 at 23:39
  • hi Reses, it doesn't work. Could you please provide me a working code sample, thanks lot. – harshadura Jun 05 '14 at 03:05