Pages: [1]
Author Topic: newbie - first question - dumb k-line interface init  (Read 13050 times)
Dakta
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 6


« on: October 18, 2012, 06:11:32 PM »

Hi everyone, been lurking on here for about a week or two, i've never seen a board like it, jam packed with information. Good stuff.

Just wondering if anyone could offer some quick advice regarding the old vag com (or dumb k-line) interface - i'm using it as a level shifter allowing me to send frames through the k-line to the ecu, and receive responses straight to my serial port.

It's good for monitoring (or hijacking even) existing connections, but I'm not sure how to initialise a connection.

I need to emulate a kwp-fast init for my particular ecu, i'm not sure how to do the initial 25ms low and 25ms high k-line activity before transmitting any necessary wakeup messages.

Is it possible with these interfaces (probably a simple answer but it's got me foxxed!).

cheers
Kris
Logged
prj
Hero Member
*****

Karma: +1072/-485
Offline Offline

Posts: 6041


« Reply #1 on: October 19, 2012, 01:56:00 AM »

Hi,

I have not done fast init, but slow init goes like this:
Code:
	void initcomms() {
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_CLR_DTR, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_OFF, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_CLR_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_RTS, NULL, 0, NULL, 0, &len, NULL);
Sleep(200);
DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_OFF, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_CLR_RTS, NULL, 0, NULL, 0, &len, NULL);
DeviceIoControl(comport, IOCTL_SERIAL_SET_DTR, NULL, 0, NULL, 0, &len, NULL);
}

I imagine you can do fast init the same way via bit banging.
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
Dakta
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 6


« Reply #2 on: October 19, 2012, 09:16:32 AM »

You know what, that is a REALLY good idea!

I use vb.net myself (do a bit of microcontroller coding in c, but i'm no great shakes at it yet) -  I didn't realise we could bit bang from this high a level, but it looks like we can use the break 'feature' - this is brilliant stuff.

Thank you. What a forum.
Logged
Dakta
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 6


« Reply #3 on: January 06, 2013, 05:11:13 PM »

Just wondering if there is anything else I could try?

I've tried the breakstate technique - but the ecu doesn't respond, i've monitored diagnostic tools that perform the init with a k-line serial converter and the same start communication message is sent as my own, so I can only conclude the problem is in the wake up signal (25ms low, 25ms high) timing.

I do a breakstate then sleep the program for 25ms each. I write the software in vb.net so i first tried a timer, later learnt this isn't very accurate so used the stopwatch which is considered very accurate - however no improvement.

I also read that sending 0x00 at 360 baud can also simulate the fast-init 25ms low signal but that didn't help either Sad

I'm sure i'm sending the right data, but i don't have an oscilloscope to see whats happening at a signal level think ill have to get one, won't give me an answer but might confirm if it is a timing issue which it has to be really because I get a positive response if i set my elmscan to the same headers and send a start communication message exactly the same contents as my own.
Logged
prj
Hero Member
*****

Karma: +1072/-485
Offline Offline

Posts: 6041


« Reply #4 on: January 07, 2013, 01:32:49 AM »

Well, you answered your own question.

The only thing I do is use timeBeginPeriod as well.
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
Dakta
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 6


« Reply #5 on: January 07, 2013, 03:27:44 AM »

Unfortunately I think I did!

I'm being tight, it's the wrong month to spend on a scope! but i see no alternative
Logged
prj
Hero Member
*****

Karma: +1072/-485
Offline Offline

Posts: 6041


« Reply #6 on: January 07, 2013, 03:36:43 AM »

Yeah, I guess not...

I was luckier and the code I wrote worked the first time Smiley
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
Dakta
Newbie
*

Karma: +0/-0
Offline Offline

Posts: 6


« Reply #7 on: January 07, 2013, 04:11:47 AM »

I can't see anything else anyway, i'm using the most accurate timer I can find in the vb.net arsenal, the right startcommunication request and I do let the kline idle 300ms before trying to start a connection so looks like it's time to be poor Tongue

do appreciate the guidance
Logged
prj
Hero Member
*****

Karma: +1072/-485
Offline Offline

Posts: 6041


« Reply #8 on: January 20, 2013, 01:34:47 PM »

Well, I did not try fast init, but slow init goes like this:

void slowInit(unsigned char address) {
   unsigned long len = 128;
   // The K-Line must be high for at least 300ms
   DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_OFF, NULL, 0, NULL, 0, &len, NULL);
   Sleep(300);

   DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL); // Start bit (low)
   Sleep(200);

   for (UINT i = 0; i < 8; i++) {
      if (((0x01 << i) & address) > 0) {
         DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_OFF, NULL, 0, NULL, 0, &len, NULL); // 1   
      } else {
         DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_ON, NULL, 0, NULL, 0, &len, NULL); // 0
      }
      Sleep(200);
   }

   DeviceIoControl(comport, IOCTL_SERIAL_SET_BREAK_OFF, NULL, 0, NULL, 0, &len, NULL);
}

Works just fine for KWP2000 too, use address 0x11.
Logged

PM's will not be answered, so don't even try.
Log your car properly - WinOLS database - Tools/patches
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Page created in 0.016 seconds with 17 queries. (Pretty URLs adds 0s, 0q)