USB hidapi
-
Hallo Leute,
ich habe ein USB-Gerät mit diversen Sensoren und Messfunktionen. Meine Erfahrungen mit USB-Kommunikation liegen bei Null aber ich würde das Gerät gerne von einem Computer aus steuern.
Mir stehen folgende Informationen zur Verfügung
Humidity sensor test READ 0x01 (Group Byte) 0x07 (Command Byte) 0 (Input Bytes) 1 (Output Bytes)
Mit diesem Beispiel kann ich leider nicht viel anfangen.
https://github.com/signal11/hidapi/blob/master/hidtest/hidtest.cpp
Kann mir jemand ein funktionierendes Beispiel geben, wie ich den Sensor auslesen kann?
-
Funktioniert das Beispiel denn nicht?
-
Doch es funktioniert aber alles was nach der Seriennummer kommt passt nicht zu dem Gerät und ich kenne mich mit den Read/Write-Befehlen für USB-Geräte nicht aus.
Feature Report 00 00 00 00 00 00 00 00 waiting... [...] waiting... Unable to read() Data read:
-
Ich habe noch folgende Tabelle
To issue a read command, the host must perform the following steps:
1. Host sends the ID byte, which is set to 0.
2. Host sends the Flags byte, where:
• Bit 6 is set to 0x1 to indicate the host wants a reply from the device.
• Bit 7 is set to 0x1 to indicate a read transaction.
3. Host sends the Sequence byte. When a single command is more than 64 bytes, it is sent as multiple
USB or UART packets and the sequence byte is used to number the packets so the device can
assemble them in the right sequence. Otherwise, this value is irrelevant and generally set to 0.
4. Host sends two bytes with the length of the data packet. This length denotes the number of data bytes
in the packet and excludes the number of bytes in steps 1 through 4. It denotes the total number of
bytes sent in steps 5 (command bytes) and 6 (data bytes).
5. Host sends two Command bytes: Command Byte 0 and Command Byte 1.
6. Host sends data appropriate to command.buf[0] = 0x00; buf[1] = 0x03; <- ?? buf[2] = 0x00; buf[3] = 0x00; <- ?? buf[4] = 0x00; <- ?? buf[5] = 0x00; buf[6] = 0x03; res = hid_write(handle, buf, sizeof(buf));
Wenn ich Command Byte 0x00 und Group Byte 0x03 verwende, würde ich gerne den Sensor auslesen. Dieser gibt 8 Bytes zurück. Wie muss ich denn den Befehl schicken?