Menu

Thandle Devicename

Help
Rob Rietow
2019-01-21
2019-01-24
  • Rob Rietow

    Rob Rietow - 2019-01-21

    In this code, it asks for a devicename when trying to open the device. Where do I get the device name? What form does it take?

    procedure OpenWinUSBDevice(deviceName: String);
    var hDevice: THandle;
    begin
    Info('Trying to open '+deviceName);
    hDevice := CreateFile(
    PChar(deviceName),
    GENERIC_WRITE or GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE,
    nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED, 0);

    if hDevice = INVALID_HANDLE_VALUE then begin
      Info('Cannot get a handle for the device. Perhaps it''s not attached.');
      Exit;
    end else begin
      Info('Device opened. Device handle is $'+inttohex(Integer(hDevice),8));
    end;
    
    Info('Obtaining WinUSB handle based on the device handle...');
    if WinUsb_Initialize(hDevice, hWinUsbHandle) then begin
      Info('WinUSB Init Ok. WinUSB handle is $'+inttohex(Integer(hWinUsbHandle),8));
    end else begin
      Info('WinUSB Init Failed.');
      Exit;
    end;
    
     
  • Rob Rietow

    Rob Rietow - 2019-01-24

    Here are some of the device names I have tried, The 'information' is from the device manager for the USB device - Properties/Event screen

    2:30:07 PM: Trying to open \.\USB\VID_04B8&PID_112A\583444513131343572
    2:30:07 PM: Cannot get a handle for the device. Perhaps it's not attached.
    2:30:22 PM: Trying to open \.\VID_04B8&PID_112A\583444513131343572
    2:30:22 PM: Cannot get a handle for the device. Perhaps it's not attached.
    2:30:39 PM: Trying to open \.\VID_04B8&PID_112A\
    2:30:39 PM: Cannot get a handle for the device. Perhaps it's not attached.
    2:31:25 PM: Trying to open \.\USB\VID_04B8&PID_112A\
    2:31:25 PM: Cannot get a handle for the device. Perhaps it's not attached.
    2:31:42 PM: Trying to open \?\USB\VID_04B8&PID_112A\
    2:31:42 PM: Cannot get a handle for the device. Perhaps it's not attached.
    2:32:07 PM: Trying to open \?\USB\VID_04B8&PID_112A\583444513131343572
    2:32:08 PM: Cannot get a handle for the device. Perhaps it's not attached.
    2:32:18 PM: Trying to open \?\VID_04B8&PID_112A\583444513131343572
    2:32:18 PM: Cannot get a handle for the device. Perhaps it's not attached.

     

Log in to post a comment.