USB Human Interface Devices

classic Classic list List threaded Threaded
165 messages Options
123456 ... 9
Reply | Threaded
Open this post in threaded view
|

Re: *** SPAM *** Re: USB Human Interface Devices

Jean SUZINEAU
Hi James,
Le 05/08/2019 à 13:00, James Richters a écrit :

Hi Jean,

 

Thank you very much for posting the zip, I’ll download it and see if I can figure it out.  Also thank you very much for your efforts and help with this.   It is VERY much appreciated!

 

James

With pleasure. It's  a good occasion for me to learn a bit more on USB.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
In reply to this post by Zaaphod

Or for me to learn anything at all about it…. As you probably can guess I haver zero USB experience.

James

 

>With pleasure. It's  a good occasion for me to learn a bit more on USB.


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
In reply to this post by Johann Glaser

I am trying to compile this with a stock installation of FPC 3.0.4 for windows… which does not have 64bit.. it only installs i386-win32 and then there is a cross compiler for x86_64-win64

 

I started with the zip file at:

https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/pas-libusb_convenience_release_2

 

then I created an lib\i386-win32 subdirectory

then from this subdirectory:  I:\Programming\pas-libusb_test_dll\src\examples>

I used this command line:

I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.exe -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Filib\i386-win32\ -Fu.. -Fu. -FUlib\i386-win32\ -FE. -otest1library.exe test1library.pas

 

Here is the output:

 

Hint: (11030) Start of reading config file I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.cfg

Hint: (11031) End of reading config file I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.cfg

Free Pascal Compiler version 3.0.4 [2017/10/06] for i386

Copyright (c) 1993-2017 by Florian Klaempfl and others

(1002) Target OS: Win32 for i386

(3104) Compiling test1library.pas

(3104) Compiling I:\Programming\pas-libusb_test_dll\src\libusb.pas

I:\Programming\pas-libusb_test_dll\src\libusb.pas(1315,13) Hint: (4035) Mixing signed expressions and longwords gives a 64bit result

I:\Programming\pas-libusb_test_dll\src\libusb.pas(1333,13) Hint: (4035) Mixing signed expressions and longwords gives a 64bit result

libusb.pas(1355) Error: Invalid DLL libusb-1.0.dll, invalid header size

I:\Programming\pas-libusb_test_dll\src\libusb.pas(1351,1) Fatal: (10026) There were 1 errors compiling module, stopping

Fatal: (1018) Compilation aborted

Error: I:\Programming\FPC\3.0.4\bin\i386-win32\ppc386.exe returned an error exitcode

 

Any ideas?  Is this just from using i386-win32? Maybe the DLL is only for 64bit? Maybe some completely unrelated issue?  If 64bit is needed, what’s the best way to install FPC3.0.4 for x86_64-win64?  It seems like I tried to do that before and it wasn’t really very easy to try to learn how to compile it.

 

James

I verified, test1library can be build with this command line:

C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Filib\ x86_64-win64 -Fu.. -Fu. -FUlib\x86_64-win64 -FE. -otest1library.exe test1library.pas

(eventually you need to create subdirectory lib\x86_64-win64 by hand)


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU

Le 06/08/2019 à 17:18, James Richters a écrit :

Any ideas?  Is this just from using i386-win32? Maybe the DLL is only for 64bit? Maybe some completely unrelated issue?  If 64bit is needed, what’s the best way to install FPC3.0.4 for x86_64-win64?  It seems like I tried to do that before and it wasn’t really very easy to try to learn how to compile it.

I'm going to have a look at that. Actually, it seems there's no package for fpc windows 64 bits.

The short answer would be to advise you to download and install lazarus ( https://www.lazarus-ide.org/ ) from https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Lazarus%202.0.4/lazarus-2.0.4-fpc-3.0.4-win64.exe/download

If you install it in C:\lazarus\, you'll end up with a 64 bits fpc in C:\lazarus\fpc\3.0.4\bin\x86_64-win64 . You can run it from command line as usual.

You can also try to replace the libusb-1.0.dll with the one from libusb-1.0.22\MinGW32\dll from https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z .




_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: *** SPAM *** Re: USB Human Interface Devices

Jean SUZINEAU
In reply to this post by Zaaphod
Le 06/08/2019 à 17:18, James Richters a écrit :
I used this command line:

I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.exe -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Filib\i386-win32\ -Fu.. -Fu. -FUlib\i386-win32\ -FE. -otest1library.exe test1library.pas

Usually, if lazarus is installed, you just need to locate and double click on I:\Programming\pas-libusb_test_dll\src\examples\test1library.lpi in Windows Explorer, and when the project is open, just press Ctr F9 to compile or F9 to execute, just as in the good old Turbo Pascal 5.5 from 1989 ...

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
In reply to this post by Jean SUZINEAU

I’m trying to avoid using Lazarus because the last few times I tried to compile the rest of my project with it, I had all kinds of issues.  I can’t remember what all the problems were but it was significant enough for me to stick with the FPC blue screen text mode IDE, and that has been working fine.  I’m not sure if it’s because I have a lot of $Mode TP units mixed with FPC units, or if it’s that some of the Lazarus procedures and functions have the same name as other procedures and functions but don’t work the same way… I would have to just try it again to see what was up.    I may make another try with Lazarus, but I’m hoping to find a solution that works with just FPC, as I know for a fact the rest of my project has no problems with that. 

 

I tried just replacing libusb-1.0.dll with the one from libusb-1.0.22\MinGW32\dll from https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z as suggested, but now I get this:

 

I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.exe -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Filib\i386-win32\ -Fu.. -Fu. -FUlib\i386-win32\ -FE. -otest1library.exe test1library.pas

 

Hint: (11030) Start of reading config file I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.cfg

Hint: (11031) End of reading config file I:\Programming\FPC\3.0.4\bin\i386-win32\fpc.cfg

Free Pascal Compiler version 3.0.4 [2017/10/06] for i386

Copyright (c) 1993-2017 by Florian Klaempfl and others

(1002) Target OS: Win32 for i386

(3104) Compiling test1library.pas

(3104) Compiling I:\Programming\pas-libusb_test_dll\src\libusb.pas

I:\Programming\pas-libusb_test_dll\src\libusb.pas(1315,13) Hint: (4035) Mixing signed expressions and longwords gives a 64bit result

I:\Programming\pas-libusb_test_dll\src\libusb.pas(1333,13) Hint: (4035) Mixing signed expressions and longwords gives a 64bit result

(3104) Compiling I:\Programming\pas-libusb_test_dll\src\libusboop.pas

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(275,5) Warning: (3018) Constructor should be public

(3104) Compiling I:\Programming\pas-libusb_test_dll\src\paslibusbutils.pas

I:\Programming\pas-libusb_test_dll\src\paslibusbutils.pas(45,30) Hint: (4080) Converting the operands to "Int64" before doing the subtract could prevent overflow errors.

I:\Programming\pas-libusb_test_dll\src\paslibusbutils.pas(65,44) Hint: (5057) Local variable "PerfCount" does not seem to be initialized

I:\Programming\pas-libusb_test_dll\src\paslibusbutils.pas(70,45) Hint: (5058) Variable "PerfFreq" does not seem to be initialized

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(545,11) Hint: (4055) Conversion between ordinals and pointers is not portable

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(546,11) Hint: (4055) Conversion between ordinals and pointers is not portable

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(564,72) Hint: (4055) Conversion between ordinals and pointers is not portable

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(852,29) Hint: (5057) Local variable "Status" does not seem to be initialized

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(922,18) Hint: (4055) Conversion between ordinals and pointers is not portable

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(923,18) Hint: (4055) Conversion between ordinals and pointers is not portable

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(937,45) Hint: (4055) Conversion between ordinals and pointers is not portable

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(1046,24) Hint: (4055) Conversion between ordinals and pointers is not portable

I:\Programming\pas-libusb_test_dll\src\libusboop.pas(1059,43) Warning: (4056) Conversion between ordinals and pointers is not portable

(9015) Linking .\test1library.exe

Error: Import library not found for libusb-1.0

Fatal: (10026) There were 1 errors compiling module, stopping

Fatal: (1018) Compilation aborted

Error: I:\Programming\FPC\3.0.4\bin\i386-win32\ppc386.exe returned an error exitcode

 

Not sure why it can’t find it now, I renamed libusb-1.0.dll and the new one is right under the one I renamed.

 

James

 

From: fpc-pascal <[hidden email]> On Behalf Of Jean SUZINEAU
Sent: Tuesday, August 6, 2019 11:51 AM
To: [hidden email]
Subject: Re: [fpc-pascal] USB Human Interface Devices

 

 

Le 06/08/2019 à 17:18, James Richters a écrit :

 

Any ideas?  Is this just from using i386-win32? Maybe the DLL is only for 64bit? Maybe some completely unrelated issue?  If 64bit is needed, what’s the best way to install FPC3.0.4 for x86_64-win64?  It seems like I tried to do that before and it wasn’t really very easy to try to learn how to compile it.

I'm going to have a look at that. Actually, it seems there's no package for fpc windows 64 bits.

The short answer would be to advise you to download and install lazarus ( https://www.lazarus-ide.org/ ) from https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Lazarus%202.0.4/lazarus-2.0.4-fpc-3.0.4-win64.exe/download

If you install it in C:\lazarus\, you'll end up with a 64 bits fpc in C:\lazarus\fpc\3.0.4\bin\x86_64-win64 . You can run it from command line as usual.

You can also try to replace the libusb-1.0.dll with the one from libusb-1.0.22\MinGW32\dll from https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z .

 

 


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Johann Glaser
In reply to this post by Jean SUZINEAU
Hi!

Am Dienstag, den 06.08.2019, 01:35 +0200 schrieb Jean SUZINEAU:
Hello
I haven't had time yet to read everything but I join below a few more tests.
Le 05/08/2019 à 21:38, Johann Glaser a écrit :
Yay! That looks great!

As a next step you can try test2controlsync.pas which uses control transfers to query the device descriptors. Just change the constants DevVID and DevPID at the top to the values of a device connected to your PC. I'd recommend to use a device you don't depend on during testing, i.e., don't use your primary keyboard and mouse. :-) There shouldn't be a problem, but better safe than sorry. And I hope that Windows doesn't cross your plans and already has allocated that device to a certain driver.

You can also try test3controlasync.pas, which does a very similar test, just using the asynchronous interface to libusb (and it is less verbose and estensive).

I tested successfully test2controlsync and test3controlasync on Windows 10 and Ubuntu 19.04 with a Seeeduino lotus (recognized as manufacturer Silicon Labs, Product CP2102N USB to UART Bridge Controller).

I've zipped the code in a new "convenience release" at :

https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/pas-libusb_convenience_release_2

This is the output on Windows:

E:\03_travail\libusb\pas-libusb_test_dll\src\examples>test2controlsync.exe
Bus 001 Device 010: ID 10C4:EA60
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            0
  bDeviceSubClass         0
  bDeviceProtocol         0
  bMaxPacketSize0        64
  idVendor            $10C4
  idProduct           $EA60
  bcdDevice            1.00
  iManufacturer           1 Silicon Labs
  iProduct                2 CP2102N USB to UART Bridge Controller
  iSerialNumber           3 0001
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength           32
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0
    bmAttributes          $80
    MaxPower              100mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255
      bInterfaceSubClass      0
      bInterfaceProtocol      0
      iInterface              0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress      $02  EP 2 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize      $0040  1x 64 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress      $82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize      $0040  1x 64 bytes
        bInterval               0

E:\03_travail\libusb\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            $10C4
  idProduct           $EA60
  bcdDevice            1.00
  iManufacturer           1
  iProduct                2
  iSerialNumber           3
  bNumConfigurations      1
Done.

E:\03_travail\libusb\pas-libusb_test_dll\src\examples>

Thats great, it works! Then have fun with all further experiments. If you need help, just ping me.

Bye
  Hansi



_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
In reply to this post by Jean SUZINEAU

>I'm going to have a look at that. Actually, it seems there's no package for fpc windows 64 bits.

 

No there isn’t , which is odd because 64bit computers vastly outnumber 32bit computers… but I guess since 32bit code runs on both if you needed to pick one then 32 would be the one to pick… I do see that the reason some platforms aren't available is that more builders and testers are needed.. this is not the first time I've wanted the full FPC package for Win64,  I'd be happy to volunteer to build and test the x86_64-win64 versions.... if someone can teach me how to build it... I've managed to get previous versions of FPC win x86_64-win64 but I remember it wasn't easy for me to build and someone was kind enough to give me a copy that they built.

 

>The short answer would be to advise you to download and install lazarus ( https://www.lazarus-ide.org/  ) from https://sourceforge.net/projects/lazarus/files/Lazarus%20Windows%2064%20bits/Lazarus%202.0.4/lazarus-2.0.4-fpc-3.0.4-win64.exe/download

 

I gave this a try and…. Success!!  I was able to compile it! 

 

>If you install it in C:\lazarus\, you'll end up with a 64 bits fpc in C:\lazarus\fpc\3.0.4\bin\x86_64-win64 . You can run it from command line as usual.

 

Yes the command line works, but the Lazarus copy of FPC 3.0.4 is incomplete, mainly it is missing FP.Exe…  The Text IDE, which I actually really like and prefer.  It is also missing a lot of other things.. I didn’t investigate fully but there are 81 files in the bin directory of FPC3.0.4 and only 68 in the Lazarus version.

Does anyone know how I can get the full FPC3.0.4 package compiled for X86_64-win64?  I can try to figure out how to build it again..  I seem to recall there was some issue with the text IDE and I just ended up going back to i386-Win32 when 3.0.4RC1 came out.

 

>You can also try to replace the libusb-1.0.dll with the one from libusb-1.0.22\MinGW32\dll from https://github.com/libusb/libusb/releases/download/v1.0.22/libusb-1.0.22.7z .

 

I could not get i386-win32 to work no matter what I did.  It would be nice to be able to use 32bit windows, but for my purposes, 64bit would be fine, I’ll have to just figure out how to compile everything else 64bit… I can use the command line of course with what I have, but I really like to have an IDE to take me to the source code of any compiler errors.  I may try to compile the rest of my project with Lazarus again and see what the exact problems are… maybe I’m just missing something simple.  I think part of the problem is that I have the FPC text IDE already set up with all my options and I don’t know how to put what is needed into Lazarus… and the default settings won’t work.  I have a lot of {$mode TP} units mixed with other types of units but I don’t have everything defined in my source, it depends on the compiler settings being the way I have them in the text IDE

 

Here’s my output from using FPC3.0.4 x86_64-win64 included with Lazarus:

 

I:\Programming\Lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Filib\x86_64-win64\ -Fu.. -Fu. -FUlib\x86_64-win64\ -FE. -o.\test1library.exe .\test1library.pas

 

Hint: (11030) Start of reading config file I:\Programming\Lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg

Hint: (11031) End of reading config file I:\Programming\Lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg

Free Pascal Compiler version 3.0.4 [2019/08/04] for x86_64

Copyright (c) 1993-2017 by Florian Klaempfl and others

(1002) Target OS: Win64 for x64

(3104) Compiling .\test1library.pas

(9015) Linking .\test1library.exe

(1008) 96 lines compiled, 0.2 sec, 166944 bytes code, 6612 bytes data

(1022) 2 hint(s) issued

 

I:\Programming\pas-libusb_test_dll\src\examples>test1library

Using libusb(x) v1.0.22.11312

Found 21 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->3, 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   2 Device  10: ID 0E50:0002,  port:   2, port path from HCD: 0->0, Speed: 1.5 Mbit/s (USB LowSpeed)

  Bus   2 Device  39: ID 0424:274C,  port:   5, port path from HCD: 0->5->5, Speed: 480 Mbit/s (USB HighSpeed)

  Bus   2 Device  38: ID 047D:1020,  port:   3, port path from HCD: 0->1->1, Speed: 1.5 Mbit/s (USB LowSpeed)

  Bus   2 Device  12: ID 0C45:7403,  port:   2, port path from HCD: 0->2, 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->128, Speed: unknown (4)

  Bus   2 Device  40: ID 1B1C:1B4F,  port:   4, port path from HCD: 0->19->19, 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->0, 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   4: 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  37: ID 0424:2734,  port:   1, port path from HCD: 0->38, Speed: 480 Mbit/s (USB HighSpeed)

  Bus   2 Device  15: ID 05E3:0610,  port:   4, port path from HCD: 0->16, Speed: 480 Mbit/s (USB HighSpeed)

  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)

 

YAY!  I have no idea what this means yet.. but I can see these are the USB devices on my system!

 

I’m going to figure out how to compile the rest of my project with x86_64-win64 and switch to some IDE that works with that,  and then I can continue trying to figure this usb stuff out.

 

James


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
In reply to this post by Johann Glaser
Static linking :

Le 05/08/2019 à 21:38, Johann Glaser a écrit :
Referring to your EMail to James, it seems that Vitaly even got it working with static linking. Especially "$LINKLIB msvcrt" and "$LINKLIB usb-1.0.dll.a" look promising. Hmm, OTOH he writes of dynamically linked, I don't know.

Could you please also have a look at his comments in that Github issue?

For now I couldn't achieve static linking.

I couldn't find a reliable way to find the dependencies of libusb-1.0 on other libraries, may be I would have to dig into the makefile and autoconf files of libusb sources, but it seems difficult.

I used MSYS2 (https://www.msys2.org/) in which I installed the following packages:

 pacman -S mingw64/mingw-w64-x86_64-libusb
 pacman -S mingw-w64-x86_64-headers-git
 pacman -S mingw-w64-x86_64-crt-git
 pacman -S mingw-w64-x86_64-gcc

In LibUsb.pas I changed the $LINKLIBs to (the errors removed by a particular $LINKLIB are after //Error: ) :  
{$LINKLIB usb-1.0}
{$ifdef windows}
  {$LINKLIB mingwex} //Error: Undefined symbol: __mingw_vsnprintf, __mingw_vsprintf, __mingw_vsscanf
  //{$LINKLIB mingw32} //doesn't improve anything
  {$LINKLIB kernel32} // Error: Undefined symbol: __imp_TlsGetValue,  __imp_EnterCriticalSection, __imp_LeaveCriticalSection, ... +41 others
  {$LINKLIB advapi32}   // Error: Undefined symbol: __imp_OpenSCManagerA, __imp_OpenServiceA, __imp_CloseServiceHandle
  //{$LINKLIB winpthread} //doesn't improve anything
  //{$LINKLIB stdc++} //doesn't improve anything
  {$LINKLIB gcc} //Error: Undefined symbol: ___chkstk_ms
  {$LINKLIB crtdll} //Error: malloc, memcpy, ... + 37 others
  //{$LINKLIB msvcrt} //same as crtdll, Error: malloc, memcpy, ... + 37 others{$else}
  {$LINKLIB c}
{$endif}

Here are the errors of the compilation, it's the minimu I could obtain:

Hint: (11030) Start of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Hint: (11031) End of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Free Pascal Compiler version 3.0.4 [2019/02/03] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
(1002) Target OS: Win64 for x64
(3104) Compiling test1library.pas
(9015) Linking E:\03_travail\libusb\pas-libusb\src\examples\test1library.exe
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_default_context
Error: Multiple defined symbol .refptr.INVALID_WINFD
Error: Multiple defined symbol .refptr.pCancelIoEx
Error: Multiple defined symbol .refptr.__tens_D2A
Error: Multiple defined symbol .refptr.__hexdig_D2A
Error: Undefined symbol: atexit
Fatal: (10026) There were 8 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: C:\lazarus\fpc\3.0.4\bin\x86_64-win64\ppcx64.exe returned an error exitcode


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod

Is the static linking issue just with Windows, and it works on Linux, or it isn’t working with FPC at all on either?

 

James

 

From: fpc-pascal <[hidden email]> On Behalf Of Jean SUZINEAU
Sent: Thursday, August 8, 2019 5:40 AM
To: [hidden email]
Subject: Re: [fpc-pascal] USB Human Interface Devices

 

Static linking :

 

Le 05/08/2019 à 21:38, Johann Glaser a écrit :

Referring to your EMail to James, it seems that Vitaly even got it working with static linking. Especially "$LINKLIB msvcrt" and "$LINKLIB usb-1.0.dll.a" look promising. Hmm, OTOH he writes of dynamically linked, I don't know.

 

Could you please also have a look at his comments in that Github issue?

For now I couldn't achieve static linking.

I couldn't find a reliable way to find the dependencies of libusb-1.0 on other libraries, may be I would have to dig into the makefile and autoconf files of libusb sources, but it seems difficult.

I used MSYS2 (https://www.msys2.org/) in which I installed the following packages:

 pacman -S mingw64/mingw-w64-x86_64-libusb
 pacman -S mingw-w64-x86_64-headers-git
 pacman -S mingw-w64-x86_64-crt-git
 pacman -S mingw-w64-x86_64-gcc
 
In LibUsb.pas I changed the $LINKLIBs to (the errors removed by a particular $LINKLIB are after //Error: ) :  
{$LINKLIB usb-1.0}
{$ifdef windows}
  {$LINKLIB mingwex} //Error: Undefined symbol: __mingw_vsnprintf, __mingw_vsprintf, __mingw_vsscanf
  //{$LINKLIB mingw32} //doesn't improve anything
  {$LINKLIB kernel32} // Error: Undefined symbol: __imp_TlsGetValue,  __imp_EnterCriticalSection, __imp_LeaveCriticalSection, ... +41 others
  {$LINKLIB advapi32}   // Error: Undefined symbol: __imp_OpenSCManagerA, __imp_OpenServiceA, __imp_CloseServiceHandle
  //{$LINKLIB winpthread} //doesn't improve anything
  //{$LINKLIB stdc++} //doesn't improve anything
  {$LINKLIB gcc} //Error: Undefined symbol: ___chkstk_ms
  {$LINKLIB crtdll} //Error: malloc, memcpy, ... + 37 others
  //{$LINKLIB msvcrt} //same as crtdll, Error: malloc, memcpy, ... + 37 others{$else}
  {$LINKLIB c}
{$endif}
 
Here are the errors of the compilation, it's the minimu I could obtain:
 
Hint: (11030) Start of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Hint: (11031) End of reading config file C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Free Pascal Compiler version 3.0.4 [2019/02/03] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
(1002) Target OS: Win64 for x64
(3104) Compiling test1library.pas
(9015) Linking E:\03_travail\libusb\pas-libusb\src\examples\test1library.exe
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_backend
Error: Multiple defined symbol .refptr.usbi_default_context
Error: Multiple defined symbol .refptr.INVALID_WINFD
Error: Multiple defined symbol .refptr.pCancelIoEx
Error: Multiple defined symbol .refptr.__tens_D2A
Error: Multiple defined symbol .refptr.__hexdig_D2A
Error: Undefined symbol: atexit
Fatal: (10026) There were 8 errors compiling module, stopping
Fatal: (1018) Compilation aborted
Error: C:\lazarus\fpc\3.0.4\bin\x86_64-win64\ppcx64.exe returned an error exitcode

 


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
Le 08/08/2019 à 12:07, James Richters a écrit :

Is the static linking issue just with Windows, and it works on Linux, or it isn’t working with FPC at all on either?

 

James

It seems that right out of the box pas-libusb uses static linking for me.
It works right out of the box on Ubuntu 64 bits / Lazarus 2.0.0 x86_64-linux fpc 3.0.4 with

{$LINKLIB c}
{$LINKLIB usb-1.0}

In a terminal:

git clone https://github.com/hansiglaser/pas-libusb.git
git checkout libusb-1.0
git pull

startlazarus , open test1library.lpi, Compile
launch in terminal:

jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ ./test1library 
Using libusb(x) v1.0.22.11312
Found 12 devices:
  Bus   4 Device   3: ID 0480:0200,  port:   2, port path from HCD: 0, Speed: unknown (4)
  Bus   4 Device   2: ID 0781:5581,  port:   1, port path from HCD: 0, Speed: unknown (4)
  Bus   4 Device   1: ID 1D6B:0003,  port:   0, Speed: unknown (4)
  Bus   3 Device   2: ID 2109:0811,  port:   1, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   3 Device   1: ID 1D6B:0002,  port:   0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   1: ID 1D6B:0002,  port:   0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   2 Device   4: ID 04A9:2220,  port:   4, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   6: ID 046D:C077,  port:   4, port path from HCD: 0->4->4, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   2 Device   5: ID 0566:3002,  port:   1, port path from HCD: 0->33->33, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   2 Device   3: ID 05E3:0606,  port:   4, port path from HCD: 0->128, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   2: ID 0451:2046,  port:   1, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   2 Device   1: ID 1D6B:0001,  port:   0, Speed: 12 Mbit/s (USB FullSpeed)
jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ 

Test dependencies:

jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ ldd ./test1library 
    linux-vdso.so.1 (0x00007fffe2b8a000)
    libusb-1.0.so.0 => /lib/x86_64-linux-gnu/libusb-1.0.so.0 (0x00007fae647d1000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fae645e6000)
    libudev.so.1 => /lib/x86_64-linux-gnu/libudev.so.1 (0x00007fae645c0000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fae6459f000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fae64a51000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fae64594000)

jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ objdump -p ./test1library | grep NEEDED 
  NEEDED               libusb-1.0.so.0
  NEEDED               libc.so.6
jean@First-Boss:~/03_travail/libusb/pas-libusb/src/examples$ 


    




_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Johann Glaser
Hi!

Am Donnerstag, den 08.08.2019, 13:14 +0200 schrieb Jean SUZINEAU:
> Le 08/08/2019 à 12:07, James Richters a écrit :
>
> > Is the static linking issue just with Windows, and it works on
> > Linux, or it isn’t working with FPC at all on either?
> >
> > James
>
> It seems that right out of the box pas-libusb uses static linking for
> me.

I think you meant to write "dynamic linking" here. :-) When I use the
Makefile, it also uses dynamic linking. Actually, I've never tried to
do static linking with libusb, because dynamic linking works so
flawlessly on Linux.

Bye
  Hansi


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
Ooops, sorry. Of course I meant dynamic linking ...
Le 08/08/2019 à 23:32, Johann Glaser a écrit :

> Am Donnerstag, den 08.08.2019, 13:14 +0200 schrieb Jean SUZINEAU:
>> It seems that right out of the box pas-libusb uses static linking for
>> me.
> I think you meant to write "dynamic linking" here. :-) When I use the
> Makefile, it also uses dynamic linking. Actually, I've never tried to
> do static linking with libusb, because dynamic linking works so
> flawlessly on Linux.
>
> Bye
>    Hansi

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
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  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
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 <[hidden email]> On Behalf Of James Richters
Sent: Thursday, August 8, 2019 8:20 PM
To: [hidden email]; 'FPC-Pascal users discussions' <[hidden email]>
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  -  [hidden email] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
In reply to this post by Zaaphod
Hi James,

Le 09/08/2019 à 02:19, James Richters a écrit :
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:

I think it's a typo.

I think we didn't saw it before because Range type checking was disabled ( {$RANGECHECKS OFF} or {$R-} ). 

It seems it's the default value for the compiler: https://www.freepascal.org/docs-html/prog/progsu65.html . Very often in Windows system functions you have to deal with records with declared with a length of 1 and the real length stored a few bytes before in the record. This could not work with {$R+}

But it's seems that for some reason it's enabled for your compiler (may be a different default value when your recompiled with fpcupdeluxe, or more likely a different default value in your settings for fp.exe ?).

I'm not an expert in memory allocation, but I think that while a certain amount of memory is allocated after the memory pointed to by PortPath and you're in {$R-} mode, you can happily read several bytes after the actual end of PortPath without any segmentation fault or memory access exception.



  


_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
Le 09/08/2019 à 06:33, Jean SUZINEAU a écrit :
Very often in Windows system functions you have to deal with records with declared with a length of 1 and the real length stored a few bytes before in the record.

Oops, not with records, with  arrays, like "Array[0..0] of libusb_endpoint_descriptor;" line 409 of libusb.pas

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
In reply to this post by Jean SUZINEAU

I am compiling with the Text IDE, and I set it up with the same settings I was using with the 32bit version…  and yes I did turn on Range checking, so that explains why we didn’t notice it before.

 

James

 

From: fpc-pascal <[hidden email]> On Behalf Of Jean SUZINEAU
Sent: Friday, August 9, 2019 12:34 AM
To: James Richters <[hidden email]>; 'FPC-Pascal users discussions' <[hidden email]>
Subject: Re: [fpc-pascal] USB Human Interface Devices

 

Hi James,

 

Le 09/08/2019 à 02:19, James Richters a écrit :

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:

I think it's a typo.

I think we didn't saw it before because Range type checking was disabled ( {$RANGECHECKS OFF} or {$R-} ). 

It seems it's the default value for the compiler: https://www.freepascal.org/docs-html/prog/progsu65.html . Very often in Windows system functions you have to deal with records with declared with a length of 1 and the real length stored a few bytes before in the record. This could not work with {$R+}

But it's seems that for some reason it's enabled for your compiler (may be a different default value when your recompiled with fpcupdeluxe, or more likely a different default value in your settings for fp.exe ?).

I'm not an expert in memory allocation, but I think that while a certain amount of memory is allocated after the memory pointed to by PortPath and you're in {$R-} mode, you can happily read several bytes after the actual end of PortPath without any segmentation fault or memory access exception.

 

 

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
In reply to this post by Zaaphod
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 <[hidden email]> On Behalf Of James Richters
Sent: Thursday, August 8, 2019 9:37 PM
To: 'FPC-Pascal users discussions' <[hidden email]>
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 <[hidden email]> On Behalf Of James Richters
Sent: Thursday, August 8, 2019 8:20 PM
To: [hidden email]; 'FPC-Pascal users discussions' <[hidden email]>
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  -  [hidden email] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email] https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod
Maybe I am going down the wrong path trying to get test_arduino_with_bmp280.pas to work with my device...  I think I am confusing easyusb with easyhid which is what is used to communicate with the device in the python code I am trying to use.  It looks like easyusb is to send firmware to a specific usb device that has no rom in it... and that's not exactly what I'm trying to do...

I'm trying to figure out how to open the device and read data and write data to this device.  Is there an example of how to do that with pas-libusb?

Sorry I am so confused by all this.  I feel like I'm almost to where I will understand things again but I'm just missing something.

James
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
123456 ... 9