Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Obtain ALDL Stream With CreateFile API

  1. #1
    Variable Bitrate mayhembdm666's Avatar
    Join Date
    Mar 2008
    Location
    Adelaide, Australia
    Posts
    233

    Obtain ALDL Stream With CreateFile API

    Good afternoon Fellow Carputer Users,

    I have been trying to play around with a basic ALDL stream for the last few days and are slowling getting closer to having cracked the learning curve on it... But still need a little help in understanding a few things.


    Currently i am using the windows API CreateFile to access the serial port as this will allow me to directly set the baud rate to 160... Which reads in the correct stream

    Using this method i can run a simple timer/loop that will provide me the stream when it sent from the car. Now for a start i have abit of programming experience but have never been a fan of bytes/hex/dec and so on.... Give me int/long/float ne day...

    The stream i receive will be the format of: XX XX XX XX XX XX XX XX XX XX XX
    in hex... and these will repeat in the pattern of 11 XX's

    I can convert these and obtain the 0 to 255 value as i need and so forth. decimal

    But more to my question now....
    I currently am doing this with my VP Commodore which uses a 1227808 ECU.
    No going by the following and massive resource of TechEdge
    they advise that i should have 20 bytes of information... i only see 11 as far as i know?

    But i can see every where else that the 11 bytes or the 11 XX's is what looks to be correct.

    Is anyone able to advise me if this is a correct stream and if so how in pseudo how i can convert this into the 20 parameters available from this ECU?

    *** Also i have tried to compair the decimal value to the RAW output of winaldl and this does not match but when i turn of my car or apply rpm's this stream will change...?

    Also i am using the 2 Transistor circuit that uses the RXD/TXD method list on the above site... as this works with EFILive & WinALDL but **NOT** the ALDLLOG on the above site..

    I WOULD BE MOST GRATEFUL TO ANYONE WHO CAN HELP ME WITH THIS LAST LITTLE BIT... As we are still lacking a good simple serial port stream code...

    Regards, Brad
    2004 Holden WL Caprice Auto GENIII
    Base System = Raspberry Pi
    Everything else is pending for now as switched from a Mini-ITX setup

  2. #2
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    Interesting read:

    http://www.diy-efi.org/gmecm/ecm_info/1227808/

    Something that should be noted, the stream format varies per ecu as per these documents:
    ftp://ftp.diy-efi.org/pub/gmecm/ALDLstuff.zip

    Look in there, see if you can locate your specific ECU/Car combonation (A028 and A059 look promising).

    However, it also looks like there should be 25 parameters returned, not 11. Are you sure you are able to open the serial port at 160baud, and it's not just erroring out?

    It's unfortunate, your ECU is the Australian version of the one my car has (the '165), but without 8192 baud. The 8192 is so much more useful than 160 :/

  3. #3
    Variable Bitrate mayhembdm666's Avatar
    Join Date
    Mar 2008
    Location
    Adelaide, Australia
    Posts
    233
    Thanks for the reply malcom2073,

    I have had a good read over both these resources but still am missing something... Im not sure what as i dont know what it is.

    Is someone able to show an example code on how to handle the output and read for example just one variable like say the battery voltage?

    I will re-look over everything tomorrow as its 2am here atm and i should get some sleep.

    Thanks again malcom
    2004 Holden WL Caprice Auto GENIII
    Base System = Raspberry Pi
    Everything else is pending for now as switched from a Mini-ITX setup

  4. #4
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    Quote Originally Posted by mayhembdm666 View Post
    Thanks for the reply malcom2073,

    I have had a good read over both these resources but still am missing something... Im not sure what as i dont know what it is.

    Is someone able to show an example code on how to handle the output and read for example just one variable like say the battery voltage?

    I will re-look over everything tomorrow as its 2am here atm and i should get some sleep.

    Thanks again malcom

    Assuming that your 11 bytes match what is on the first page you linked, I can give you an example in c# or c++, which would you prefer?
    "stop with the REINSTALLS, what do you think we got some lame-o installer!!!" - mitchjs
    RevFE
    My Shop

  5. #5
    Variable Bitrate mayhembdm666's Avatar
    Join Date
    Mar 2008
    Location
    Adelaide, Australia
    Posts
    233
    Malcom, that would be awesome... ! C++ i would prefer best but either is fine by me.
    So many thanks in advance.
    2004 Holden WL Caprice Auto GENIII
    Base System = Raspberry Pi
    Everything else is pending for now as switched from a Mini-ITX setup

  6. #6
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    I just freehanded most of this, so there may be some errors. It should give you a basic idea though. It of course is by no means complete, but should provide a start for you. The first part you should already be familiar with.

    Code:
    int getBytes()
    {
    	HANDLE portHandle;
    	const char *portName = "\\\\.\\COM1";
    
    	//Open the port
    	portHandle=CreateFileA(portName, GENERIC_READ|GENERIC_WRITE,0, NULL, OPEN_EXISTING, 0, NULL);
    
    	if (portHandle == INVALID_HANDLE_VALUE)
    
    	{
    
    		return -1;
    
    	}
    
       	COMMCONFIG Win_CommConfig;
    
    	COMMTIMEOUTS Win_CommTimeouts;
    
    	unsigned long confSize = sizeof(COMMCONFIG);
    
    	Win_CommConfig.dwSize = confSize;
    
    	GetCommConfig(portHandle, &Win_CommConfig, &confSize);
    
    	Win_CommConfig.dcb.Parity = 0;
    
    	Win_CommConfig.dcb.fRtsControl = RTS_CONTROL_DISABLE;
    
    	Win_CommConfig.dcb.fOutxCtsFlow = FALSE;
    
    	Win_CommConfig.dcb.fOutxDsrFlow = FALSE;
    
    	Win_CommConfig.dcb.fDtrControl = DTR_CONTROL_DISABLE;
    
    	Win_CommConfig.dcb.fDsrSensitivity = FALSE;
    
    	Win_CommConfig.dcb.fNull=FALSE;
    
    	Win_CommConfig.dcb.fTXContinueOnXoff = FALSE;
    
    	Win_CommConfig.dcb.fInX=FALSE;
    
    	Win_CommConfig.dcb.fOutX=FALSE;
    
    	Win_CommConfig.dcb.fBinary=TRUE;
    
    	Win_CommConfig.dcb.DCBlength = sizeof(DCB);
    
    	//Set the baud rate to 160, I THINK this works....
    
    	Win_CommConfig.dcb.BaudRate = 160;
    
    
    	Win_CommConfig.dcb.ByteSize = 8;
    
    	Win_CommTimeouts.ReadIntervalTimeout = 50;
    
    	Win_CommTimeouts.ReadTotalTimeoutMultiplier = 0;
    
    	Win_CommTimeouts.ReadTotalTimeoutConstant = 110;
    
    	Win_CommTimeouts.WriteTotalTimeoutMultiplier = 0;
    
    	Win_CommTimeouts.WriteTotalTimeoutConstant = 110;
    
    	SetCommConfig(portHandle, &Win_CommConfig, sizeof(COMMCONFIG));
    
    	SetCommTimeouts(portHandle,&Win_CommTimeouts);
    
    
    
    
    	//This is the part you should pay attention to right here.
    
    	unsigned char *tmp = new unsigned char[1024];
    	int bufferSize = 0;
    
    	//Read a chunk from the serial port buffer assuming there is something there. You may need to send something before receiving data back.
    	if (!ReadFile(portHandle,(void*)&tmp,1024,(LPDWORD)&bufferSize,NULL))
    	{
    		printf("Error\n");
    		return -1;
    	}
    	if (bufferSize <= 0)
    	{
    		printf("No bytes read\n");
    		return -1;
    	}
    
    	//At this point, we assume that tmp has in it your 11 bytes, from byte 0-10. You should check to make sure, as to avoid segfaults or faulty data.
    	//Byte 7 is engine speed, RPM = n x 25 according to the techedge page
    	int rpm = tmp[7] * 25;
    	printf("Engine RPM is: %i\n",rpm);
    	//Byte 5 is vehicle speed directly
    	int mph = tmp[5];
    	printf("Vehicle Speed is %i\n",mph);
    	return 0;	
    }
    "stop with the REINSTALLS, what do you think we got some lame-o installer!!!" - mitchjs
    RevFE
    My Shop

  7. #7
    Variable Bitrate mayhembdm666's Avatar
    Join Date
    Mar 2008
    Location
    Adelaide, Australia
    Posts
    233
    ah that is easy as to read... i just gotta now try it tomorrow with the car.... or setup my remote control so i can do it from the house.

    also this part....
    //Set the baud rate to 160, I THINK this works....
    Win_CommConfig.dcb.BaudRate = 160;

    Does work... You are able to define a custom baud rate other then the standards... The MSComm control allows only standards.

    For example if you change the baud rate to something other then what your hardware uses you will see the changes. I tested this with the 160/170 type.

    thats why i have used the createfile method.
    2004 Holden WL Caprice Auto GENIII
    Base System = Raspberry Pi
    Everything else is pending for now as switched from a Mini-ITX setup

  8. #8
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    Good to hear, I haven't actually tried custom baud rates since I took my car off the road for an engine swap a year ago... so I didn't quite recall

    Let me know how it goes
    "stop with the REINSTALLS, what do you think we got some lame-o installer!!!" - mitchjs
    RevFE
    My Shop

  9. #9
    Variable Bitrate mayhembdm666's Avatar
    Join Date
    Mar 2008
    Location
    Adelaide, Australia
    Posts
    233
    Hey, just thought i would update as to why i have not posted a reply on here yet...
    First of.... I bad flashed my bios, using all the provided instructions and the board can not be recovered with a boot floppy method even tho it searches and access the floppy... HMMMM

    Second, the board i have had a revision above the public release... So curious now as to why that was.. As to why i flashed it, started to get a lot of CRC errors and could not play and video files and after hours n hours of google it had seem to come down to a network card issue and being that i used the onboard card... Well yea you get the idea.

    So anyway in the mean time i'm just waiting a few weeks to upgrade the whole system to something a little more beefy that will run win7 ultimate and then start all over again.

    But in short, Once i have this cracked i do want to do a little write up for people on some basic examples for vb/c/c#/c++/qbasic that will show how to access all of these with the simplest circuit and code. As there seems to be a small lacking of code on the web.
    2004 Holden WL Caprice Auto GENIII
    Base System = Raspberry Pi
    Everything else is pending for now as switched from a Mini-ITX setup

  10. #10
    North of the land of Hey Huns
    Auto Apps:loading...

    Join Date
    Jun 2004
    Location
    Westminster, MD
    Posts
    2,127
    I can't wait to hear how the project goes, I've just made a huge step towards getting my car back on the road (bought injectors and fuel lines) so with any luck I'll soon be ready to start writing ALDL code again.
    "stop with the REINSTALLS, what do you think we got some lame-o installer!!!" - mitchjs
    RevFE
    My Shop

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •