_IOWWrite <- Funktioniert super == aber Hilfe bei _IOWRead

  • Hey, also ich habe nun 1 Monat mit der Schreib Funktion meines Warriors vertraut gemacht. Nun möchte ich gerne noch Daten Auslesen. Ich habe ein kleines Problem, weil ich nicht weiß welchen Wert der &Report bekomme. Mein Script sieht wie folgt aus, und schreibt auch die Daten an meinen Warrior. Doch ab dem Lesen, geht es nicht mehr weiter. Ich bin mir ziemlich sicher, das bei dem lesen etwa snicht stimmt. Aber ich begreife nicht weis bei dem Report rein soll. Beimn Schreiben ist es der Wert. OK. aber beim Lesen ?

    lg Tim

    Spoiler anzeigen
    [autoit]

    #include "iowkit.au3"
    #Include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $ahIOW[$IOWKIT_MAX_DEVICES]

    [/autoit] [autoit][/autoit] [autoit]

    If Not _IowKitStartUp() Then ; Die Dll wird geladen
    ConsoleWrite("Failed to load iowkit dll" & @CRLF)
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    ; Open device
    Global $devHandle = _IowKitOpenDevice() ; Die Verbindung zum Warrior wird hergestellt
    If Not $devHandle Then
    ConsoleWrite("Failed to open device" & @CRLF)
    _IowKitCloseDevice($devHandle);
    Exit
    EndIf
    ConsoleWrite("Device Opened" & @CRLF)

    [/autoit] [autoit][/autoit] [autoit]

    ; Get number of IOWs in system
    $numIows = _IowKitGetNumDevs() ; Gibt die Anzahl an IOW´s im System wider
    ConsoleWrite(StringFormat("%d IOWs in system\n", $numIows))
    ; Get all IOW handles
    Dim $serial ; Variable wird deklariert

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $numIows
    ;~ ConsoleWrite("+Loop " & $i & '/' & $numIows & @CRLF)
    ; Get device handle and init object
    $ahIOW[$i-1] = _IowKitGetDeviceHandle($i) ; Gibt ein Handle für einen der IOW´s zurück
    ;~ ConsoleWrite("-after _IowKitGetDeviceHandle" & @CRLF)
    ; Get serial number
    _IowKitGetSerialNumber($ahIOW[$i-1], $serial); Schreibt die Seriennummer in einen buffer ( serial )
    ;~ ConsoleWrite("-after _IowKitGetSerialNumber" & @CRLF)
    $pid = _IowKitGetProductId($ahIOW[$i-1]) ; Gibt die Produkt ID des IOW´s zurück. Bei den 40ern ist es meist die 1500
    ConsoleWrite(StringFormat('%d PID %x, S/N "%s"\n', $i, $pid, $serial));

    [/autoit] [autoit][/autoit] [autoit]

    $tIOWKIT40_IO_REPORT = DLLStructCreate($tagIOWKIT40_IO_REPORT) ; korrekt
    DLLStructSetData($tIOWKIT40_IO_REPORT, "Value", 0x0FFFFFFF ) ; hier war was falsch
    $write = _IowKitWrite($ahIOW[$i-1], $IOW_PIPE_IO_PINS, DLLStructGetPtr($tIOWKIT40_IO_REPORT) , $IOWKIT40_IO_REPORT_SIZE) ; Würde ich so machen, die UDF sollte aber auch deine Version erlauben

    [/autoit] [autoit][/autoit] [autoit]

    If Not ($write = $IOWKIT40_IO_REPORT_SIZE) Then ; Klammern nicht vergessen. Not bindet stärker als der Vergleich
    ConsoleWrite("Fail to send Data to IOW " & $serial & @CRLF)
    ;~ _IowKitCloseDevice($devHandle);
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $numIows
    ;~ ConsoleWrite("+Loop " & $i & '/' & $numIows & @CRLF)
    ; Get device handle and init object
    $ahIOW[$i-1] = _IowKitGetDeviceHandle($i) ; Gibt ein Handle für einen der IOW´s zurück
    ;~ ConsoleWrite("-after _IowKitGetDeviceHandle" & @CRLF)
    ; Get serial number
    _IowKitGetSerialNumber($ahIOW[$i-1], $serial); Schreibt die Seriennummer in einen buffer ( serial )
    ;~ ConsoleWrite("-after _IowKitGetSerialNumber" & @CRLF)
    $pid = _IowKitGetProductId($ahIOW[$i-1]) ; Gibt die Produkt ID des IOW´s zurück. Bei den 40ern ist es meist die 1500
    ConsoleWrite(StringFormat('%d PID %x, S/N "%s"\n', $i, $pid, $serial));

    [/autoit] [autoit][/autoit] [autoit]

    ; Hier muss irgendetwas fehlen...
    $res = _IowKitRead($ahIOW[$i-1], $IOW_PIPE_IO_PINS, $IOWKIT40_IO_REPORT, $IOWKIT40_IO_REPORT_SIZE)
    ConsoleWrite($res, $IOWKIT40_IO_REPORT)

    [/autoit] [autoit][/autoit] [autoit]

    If Not ($res = $IOWKIT40_IO_REPORT_SIZE) Then ; Klammern nicht vergessen. Not bindet stärker als der Vergleich
    ConsoleWrite("Fail to read Data from IOW " & $serial & @CRLF)
    ;~ _IowKitCloseDevice($devHandle);
    Exit
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; Close device
    _IowKitCloseDevice($devHandle);
    ConsoleWrite("Device closed" & @CRLF)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit]

    Hier noch der Ausschnitt aus der .pdf :

    Spoiler anzeigen

    IowKitRead
    Declaration:
    ULONG IOWKIT_API IowKitRead(IOWKIT_HANDLE devHandle, ULONG numPipe,
    PCHAR buffer, ULONG length);
    function IowKitRead(devHandle: IOWKIT_HANDLE; numPipe: ULONG;
    buffer: PChar; length: ULONG): ULONG; stdcall;
    Read data from IO-Warrior.
    This function reads length bytes from IO-Warrior and returns the number of bytes read if successful.
    Note that you must specify the number of the pipe (see IO-Warrior specs) to read from. numPipe ranges
    from 0 to IOWKIT_MAX_PIPES-1.
    Since the IO-Warriors are HID devices, you can only read the data in chunks called reports. Each report is
    preceded by a ReportID byte. The "IOWarriorDatasheet.pdf" elaborates about that.
    The function returns the number of bytes read, so you should always check if it reads the correct number
    of bytes, you can use GetLastError() to get error details. Keep in mind that data is always returned
    in report chunks, so reading 5 bytes from the IO-pins of an IO-Warrior 24 would only return 3 bytes of
    data because the IO-Warrior 24 has a 3 byte report whereas an IO-Warrior 40 has a 5 byte report.
    The Special Mode pipe has a report size of 8 bytes for all IO-Warriors.
    Linux does not have a ReportID byte of 0 for pipe 0 (I/O pins). To be completely compatible with
    Windows libiowkit.so adds that ReportID to the data.
    As of dynamic library version 1.4 and later the function correctly reads several reports at once.
    ATTENTION!
    This function blocks the current thread until something changes on IO-Warrior (i.e. until user presses a
    button connected to an input pin, or until IIC data arrives), so if you do not want your program to be
    blocked you should use a separate thread for reading from IO-Warrior. If you do not want a blocking read
    use IowKitReadNonBlocking().
    Alternatively you can set the read timeout with IowKitSetTimeout() to force IowKitRead() to
    fail when the timeout elapsed.
    Sample usage C:
    IOWKIT40_IO_REPORT report;
    ULONG res;
    // Read IO pins of IO-Warrior 40
    res = IowKitRead(ioHandle, IOW_PIPE_IO_PINS,
    &report, IOWKIT40_IO_REPORT_SIZE);
    if (res != IOWKIT40_IO_REPORT_SIZE)
    {
    // Didn't read, handle error
    ...
    }

    Ich habe gelesen, das man may_pipes auf -1 setzten muss zum lesen. Aber bitte wo geht das, oder wo finde ich wie es geht ?

    lg Tim