Hallo,
ich versuche das Protokoll KW1281 in C zu realisieren.
OS: Windows XP 32bit
Die Verbindung mit dem OBD-Kabel steht und das VWTool sowie VCDS können eine Verbindung herstellen, allerdings gelingt mir dies nicht in C.
Hier der Code den ich bis jetzt habe:
Code:
#include <windows.h>
int main(int argc, char* argv[])
{
    char INBUFFER[2]; // Create Input Buffer
    char PacketOne = '\x00';
    char PacketTwo = '\xf0';
    char PacketThree = '\x75';
    char PacketFour = '\x75';
    /* Komplement berechnen
    char Komplement = '\xd5' ^ '\xff';
    printf("%d\r\n",Komplement);
    */
    DWORD        bytes_read    = 0;    // Number of bytes read from port
    DWORD        bytes_written = 0;    // Number of bytes written to the port
    HANDLE       comport      = NULL;  // Handle COM port
    int          bStatus;              // Status indicator
    DCB          comSettings;          // Contains various port settings
    COMMTIMEOUTS CommTimeouts;         // Contains various COM timeouts
    // Open COM port
    if ((comport =
         CreateFile("\\\\.\\COM4",                // open com4:
                    GENERIC_READ | GENERIC_WRITE, // for reading and writing
                    0,                            // exclusive access
                    NULL,                         // no security attributes
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL,
                    NULL)) == INVALID_HANDLE_VALUE)
    {
        printf("CreateFile() funktioniert nicht\r\n"); // error processing code goes here
    }
    CommTimeouts.ReadIntervalTimeout         = 0;     // Timeout in ms
    CommTimeouts.ReadTotalTimeoutMultiplier  = 0;     // Timeout in ms
    CommTimeouts.ReadTotalTimeoutConstant    = 100;   // Timeout in ms
    CommTimeouts.WriteTotalTimeoutMultiplier = 0;     // Timeout in ms
    CommTimeouts.WriteTotalTimeoutConstant   = 100;   // Timeout in ms
    bStatus = SetCommTimeouts(comport,&CommTimeouts); // Set COM timeouts
    if (bStatus != 0)
    {
        printf("SetCommTimeouts() funktioniert nicht\r\n"); // error processing code goes here
    }
    GetCommState(comport, &comSettings); // Getting COM state
    comSettings.BaudRate = 1;           // COM setting
    comSettings.StopBits = ONESTOPBIT;  // COM setting
    comSettings.ByteSize = 8;           // COM setting
    comSettings.Parity   = NOPARITY;    // COM setting
    comSettings.fParity  = FALSE;       // COM setting
    bStatus = SetCommState(comport, &comSettings); // Setting COM state
    if (bStatus == 0)
    {
        printf("SetCommState() funktioniert nicht.\r\n"); // error processing code goes here
    }
    while(!kbhit()) // Solange keine Taste gedrückt wird
    {
        bStatus = ReadFile(comport,&INBUFFER,2,&bytes_read,NULL);
        printf("Receiving: %d <-> %d\r\n", INBUFFER[0]+169, INBUFFER[1]+169);
        /////
        bStatus = WriteFile(comport,&PacketOne,1,&bytes_written,NULL);
        printf("Sending: %d\r\n", PacketOne+169);
        bStatus = ReadFile(comport,&INBUFFER,2,&bytes_read,NULL);
        printf("Receiving: %d <-> %d\r\n", INBUFFER[0]+169, INBUFFER[1]+169);
        /////
        PacketTwo = INBUFFER[1] ^ '\xFF';
        bStatus = WriteFile(comport,&PacketTwo,1,&bytes_written,NULL);
        printf("Sending: %d\r\n", PacketTwo+169);
        bStatus = ReadFile(comport,&INBUFFER,2,&bytes_read,NULL);
        printf("Receiving: %d <-> %d\r\n", INBUFFER[0]+169, INBUFFER[1]+169);
        /////
        PacketThree = '\xFE';
        bStatus = WriteFile(comport,&PacketThree,1,&bytes_written,NULL);
        printf("Sending: %d\r\n", PacketThree+169);
        bStatus = ReadFile(comport,&INBUFFER,2,&bytes_read,NULL);
        printf("Receiving: %d <-> %d\r\n", INBUFFER[0]+169, INBUFFER[1]+169);
        system("pause");
    }
    CloseHandle(comport);
 return 0;
}
Hier bekomme ich immer genau das zurück, was ich abschicke und keine "reale Antwort".
Das OBD Kabel ist mit USB als COM4 gemappt und wird daher auch über COM4 angesprochen.
Die Baudrate ist im Skript auf 5 gesetzt.
Allerdings ist der COM-Adapter auf 96 Baud eingestellt.
Woran kann das liegen, dass ich keine realen Antworten bekomme?
Hoffentlich kann mir jemand helfen, vielen Dank.
Gruß COMedy