[fpc-pascal] USB Human Interface Devices

James Richters james at productionautomation.net
Fri Aug 9 11:31:34 CEST 2019


I had "Use STATIC in objects" turned on in compiler setings.. once I turned that off I was able to compile libusbutil.pas successfully.

Now when I try to run it though, I am getting :    Couldn't connect to device: Access violation

I don't know why.  
I don't really know what I am doing.. but here is what I did so far... 

I ran test1library (which also has the line Write('->',PortPath[J]); in it... I changed the J to an I again)
I got the list of devices,  then I plugged in the one I am trying to access and ran Test1library once again... then I saw the new device in the list, which was this one:
	Bus   2 Device  62: ID 10CE:EB93,  port:   2, port path from HCD: 0->1, Speed: 12 Mbit/s (USB FullSpeed)

So I changed the lines in testcontrolsync.pas as follow:
Const
     WHB04B_VID= $10CE;
     WHB04B_PID= $EB93;

Const DevVID = WHB04B_VID;
      DevPID = WHB04B_PID;

Then I get this output:
Running "i:\programming\pas-libusb_test_dll\src\examples\test2controlsync.exe "
Bus 002 Device 062: ID 10CE:EB93
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor            $10CE
  idProduct           $EB93
  bcdDevice            1.00
  iManufacturer           1 KTURT.LTD
  iProduct                0
  iSerialNumber           0
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           27
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes          $80
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           0
      bInterfaceClass         3
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
Unknown descriptor type $21 with length 9

So that looks promising... I don't know about the unknown descriptor, but at least I have some information that seems reasonable.
With the same modifications to test3controlasync.pas I get this:

Running "i:\programming\pas-libusb_test_dll\src\examples\test3controlasync.exe "
Submitting control transfer
Finished Transfer, Data = 38, Status = 0, ActualLength = 18
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor            $10CE
  idProduct           $EB93
  bcdDevice            1.00
  iManufacturer           1
  iProduct                0
  iSerialNumber           0
  bNumConfigurations      1
Done.

So I again put my device VID and PID into test_arduino_with_bmp280.pas and got this:

Running "i:\programming\pas-libusb_test_dll\src\examples\test_arduino_with_bmp280.exe "
No unconfigured devices found.
Couldn't connect to device: No configured devices found.

I suspect it has something to do with the firmware.ihx file mentioned in the comments, but I do not understand how to get that file.  It says to compile EZ-USB,  but I don't know what to do with it..   When I say I compiled it, I am referring to EZUSB.PAS that is included in pas-libusb... but that is just a unit,  and I don't know how I could use that to create this firmware.ihx file.  

What is the correct procedure to obtain firmware.ihx?    Is there something else I need besides the EZUSB unit that would use that unit to create this file?


James

-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of James Richters
Sent: Thursday, August 8, 2019 9:37 PM
To: 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Subject: Re: [fpc-pascal] USB Human Interface Devices

I changed the VID and PID to match the device I am trying to use and I was able to successfully compile and run test2controlsync.pas and test3controlasync.pas, but when I tried to use my VID and PID in test_arduino_with_bmp280.pas I can't even compile it.. using the x86_64-win64 Text IDE I get the following:

Warning: PIC directive or switch ignored                                                 
Hint: End of reading config file I:\Programming\FPC\W64_Trunk\Bin\x86_64-win64\fp.cfg    
libusbutil.pas(35,63) Error: Constructor name must be INIT                               
libusbutil.pas(45,78) Error: Constructor name must be INIT                               
libusbutil.pas(58,50) Error: Constructor name must be INIT                               
libusbutil.pas(73,108) Error: Constructor name must be INIT                              
libusbutil.pas(76,1) Fatal: There were 4 errors compiling module, stopping               
libusbutil.pas(0) Fatal: Compilation aborted  

Anyone know what this means and how I might fix it?


James

-----Original Message-----
From: fpc-pascal <fpc-pascal-bounces at lists.freepascal.org> On Behalf Of James Richters
Sent: Thursday, August 8, 2019 8:20 PM
To: Jean.Suzineau at wanadoo.fr; 'FPC-Pascal users discussions' <fpc-pascal at lists.freepascal.org>
Subject: Re: [fpc-pascal] USB Human Interface Devices

I finally got the text IDE working with x86_64-Win64!   I was thinking of making a bug report on the problem with the Text IDE but before I did that I thought I would test the current Trunk, and surprisingly that worked just fine!  so I got my settings all put in it and I was able to compile my project with it.

So the next thing I thought I would do is use the IDE to compile the pas-libusb_test_dll examples.  With the IDE it was easier to just copy the units into the same directory as the files.  I started with test1library.pas... it compiled fine so I ran it, and here's what I got.... 


Running "i:\programming\pas-libusb_test_dll\src\examples\test1library.exe "
Using libusb(x) v1.0.22.11312
Found 23 devices:
  Bus   3 Device   0: ID 1B21:2142,  port:   0, Speed: Unknown
  Bus   1 Device   0: ID 1B21:2142,  port:   0, Speed: Unknown
  Bus   2 Device  14: ID 1B1C:0C10,  port:   3, port path from HCD: 0An unhandled exception occurred at $0000000100001DC8:
ERangeError: Range check error
  $0000000100001DC8  main,  line 82 of ../../pas-libusb_test_dll/src/examples/test1library.pas

->

so this was strange... it was working before

line 81            For J := 1 to Length(PortPath)-1 do
line 82              Write('->',PortPath[I]);

Line 82 is using variable I but it's in a loop that uses J, I didn't think that made a lot of sense.. so without really analyzing how any of this was supposed to work.. I just changed the I to a J and then I got this:
              
->Running "i:\programming\pas-libusb_test_dll\src\examples\test1library.exe "
Using libusb(x) v1.0.22.11312
Found 23 devices:
  Bus   3 Device   0: ID 1B21:2142,  port:   0, Speed: Unknown
  Bus   1 Device   0: ID 1B21:2142,  port:   0, Speed: Unknown
  Bus   2 Device  14: ID 1B1C:0C10,  port:   3, port path from HCD: 0->7, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   8: ID 1B1C:0C12,  port:  10, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   1: ID 1D50:6015,  port:   3, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device  58: ID 0424:274C,  port:   5, port path from HCD: 0->5->1, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device  62: ID 10CE:EB93,  port:   2, port path from HCD: 0->1, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device  57: ID 047D:1020,  port:   3, port path from HCD: 0->5->1, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   2 Device  44: ID 0C45:7403,  port:   2, port path from HCD: 0->5, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   6: ID 051D:0002,  port:   3, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device  36: ID 04E8:61F5,  port:   1, port path from HCD: 0->17, Speed: unknown (4)
  Bus   2 Device  59: ID 1B1C:1B4F,  port:   4, port path from HCD: 0->5->1, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   5: ID 05E3:0608,  port:   7, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device   7: ID 05E3:0608,  port:   8, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device  13: ID 1B1C:1C08,  port:   2, port path from HCD: 0->7, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   1: ID 0BDA:0411,  port:  17, port path from HCD: 0, Speed: unknown (4)
  Bus   2 Device  42: ID 1A40:0101,  port:   5, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device   0: ID 8086:A2AF,  port:   0, Speed: Unknown
  Bus   2 Device  56: ID 0424:2734,  port:   1, port path from HCD: 0->5, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device  15: ID 05E3:0610,  port:   4, port path from HCD: 0->7, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device  61: ID 0E50:0002,  port:   4, port path from HCD: 0, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   2 Device  41: ID 0A5F:0006,  port:   2, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   2: ID 0BDA:5411,  port:   1, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)              
  
Looks like it worked fine with line 82 reading:  Write('->',PortPath[J]);   
I'm perplexed at how this could have possibly worked before...

So is it supposed to be Write('->',PortPath[J]); and the I was just a typo, or is something else going on here?
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


More information about the fpc-pascal mailing list