So also an den DeviceDescriptor komme ich mittlerweile ran. Dies funktioniert über ein DeviceIOControl mit Control_Transfer. Beim StringDescriptor bin ich noch am testen.
Könnte es sein, dass dies der Standard-Weg ist an den Descriptor ranzukommen?
Ich kopiere mal die interessanten Zeilen aus meinem Testquellcode raus, evtl hat ja irgendjemand mal Nutzen davon:
Habe den Quellcode mit dem CyPress-Driver (CyUSB.sys Version 1.07.0000.0 Release) aus dem USBDevStudio benutzt, welches es auf cypress.com zum download gibt.
Delphi-Quellcode:
type
SETUP_PACKET = packed record
bmRequest : UChar;
bRequest : UChar;
wValue : WORD;
wIndex : WORD;
wLength : WORD;
ulTimeOut : ULong;
end;
SINGLE_TRANSFER = packed record
SetupPacket : SETUP_PACKET;
WaitForever : UChar;
ucEndpointAddress : UChar;
NtStatus : ULong;
UsbdStatus : ULong;
IsoPacketOffset : ULong;
IsoPacketLength : ULong;
BufferOffset : ULong;
BufferLength : ULong;
end;
Delphi-Quellcode:
const
METHOD_BUFFERED = 0;
METHOD_IN_DIRECT = 1;
METHOD_OUT_DIRECT = 2;
METHOD_NEITHER = 3;
FILE_ANY_ACCESS = 0;
FILE_READ_ACCESS = $0001;
FILW_WRITE_ACCESS = $0002;
FILE_DEVICE_UNKNOWN: DEVICE_TYPE = $0C0000022;
Delphi-Quellcode:
var
DeviceHandle : THandle;
Success : Boolean;
nBytes: LongWord;
IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER : DWord;
Buffer : Array[0..1023] of Byte; // hier kleineren Buffer wählen
SingleTransfer : SINGLE_TRANSFER;
BufferLen : Integer;
Delphi-Quellcode:
BufferLen := SizeOf(USB_DEVICE_DESCRIPTOR);
SingleTransfer.SetupPacket.bmRequest := $00;
SingleTransfer.SetupPacket.bRequest := 6;
SingleTransfer.SetupPacket.wValue := $0100;
SingleTransfer.SetupPacket.wIndex := $0000;
SingleTransfer.SetupPacket.wLength := BufferLen;
SingleTransfer.SetupPacket.ulTimeOut := 1000;
SingleTransfer.WaitForever := 0;
SingleTransfer.ucEndpointAddress := $00;
SingleTransfer.IsoPacketLength := 0;
SingleTransfer.BufferOffset := SizeOf(SINGLE_TRANSFER);
SingleTransfer.BufferLength := BufferLen;
Delphi-Quellcode:
IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER := CTL_CODE(FILE_DEVICE_UNKNOWN,
8,
METHOD_BUFFERED,
FILE_ANY_ACCESS);
//DeviceHandle bekommt man über ein CreateFile des Devices
success := DeviceIoControl(DeviceHandle,
IOCTL_ADAPT_SEND_EP0_CONTROL_TRANSFER,
@SingleTransfer,
SizeOf(SINGLE_TRANSFER) + BufferLen,
@Buffer,
SizeOf(Buffer),
nBytes,
NIL);
// in die DescriptorStruktur kopieren
Move(Buffer[38],
DC, SizeOf(
DC));
Delphi-Quellcode:
function TForm1.CTL_CODE (Devicetype: DWord; Func, Method,
Access: Word) : DWord;
begin
CTL_CODE := (Devicetype
shl 16)
OR (
Access shl 14)
Or (Func
shl 2)
Or Method;
end;