USB Human Interface Devices

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

Re: USB Human Interface Devices

Zaaphod
Thanks for removing the un-needed units.  I have been trying to compile as-is without any modifications.   I was not aware that this was dependent on LibC and Lib-USB.  I am not really clear on how to install these, maybe I just need to download the correct files and have them in the same directory I am trying to compile Pas-LibUSB from?
I quite literally have a stock installation of FPC3.0.4RC1 and that is all.. nothing else, no Lazarus, no LibC or LibUSB anything development or otherwise.   So it seems the first step will be to install the prerequisite packages.  I'll see if I can figure that out.

James


-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of Johann Glaser
Sent: Tuesday, July 30, 2019 4:54 PM
To: [hidden email]
Subject: Re: [fpc-pascal] USB Human Interface Devices

Hi James!

Am Dienstag, den 30.07.2019, 13:52 -0400 schrieb James Richters:

> > > Due to my lack of understanding of Windows, I've not yet taken
> > > over his changes, because I wanted to wait for confirmation from
> > > other users. So if James had some feedback, I'd appreciate it
> > > greatly.
>
> I'm trying to get this to work on windows,  I'm having a lot of units
> not found errors when I try to compile anything at all.. I'm not sure
> what I need here to get the examples to work.    Here is a list of
> units I can't find when I try to compile with FPC 3.0.4RC1 on
> Windows:
>
> ezusb.pas(42,15) Fatal: Can't find unit Errors used by EZUSB I have no
> idea what Unit Errors is or what it might be for.

Thanks for pointing this out. This is a Unix unit, but it is obviously not used in Ezusb. I've removed it now.

> libusb.pas(1350) Warning: Library c.dll not found, Linking may fail !                                                ■
> libusb.pas(1350) Warning: Library usb-1.0 not found, Linking may fail !
> I'm not really following where c.dll and usb1.0 are supposed to come
> from

It seems you didn't install the development stuff for libc and lib-usb?
At least in Linux, I always have to install these additionally (e.g.,
libusb-1.0-0-dev) to the "productive" libraries (e.g., libusb-1.0-0).

> usb.pas(31,22) Fatal: Can't find unit Baseunix used by USB

Same as above for Errors. However, this file is unused.

> mydevice.pas(27,20) Fatal: Can't find unit BaseUnix used by MyDevice I
> have no idea what BaseUnix does or if I can do something windows
> compatible instead somehow.

Same as above for Errors.

> Test1Library.pas:
> ║ (0) Error: Import library not found for c ║ (0) Error: Import
> library not found for usb-1.0

This seems to be again a problem because of the missing development stuff for libc anc libusb.

> To be honest this is quite a bit over my head.  I'm trying to follow
> https://github.com/hansiglaser/pas-libusb/issues/4 but I'm just lost.

I would recommend, first to just compile the pristine pas-libusb without any hints from that Github issue. Only if you get the same errors, please try them and let me know.

As stated above, I've now removed all references to the units Errors and Baseunix. Please "git pull" to the newest state on Github and compile again. If you still face problems, please don't hesitate to ask again.

Thanks
  Hansi


_______________________________________________
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

Johann Glaser
Hi!

Am Dienstag, den 30.07.2019, 19:57 -0400 schrieb James Richters:

> Thanks for removing the un-needed units.  I have been trying to
> compile as-is without any modifications.   I was not aware that this
> was dependent on LibC and Lib-USB.  I am not really clear on how to
> install these, maybe I just need to download the correct files and
> have them in the same directory I am trying to compile Pas-LibUSB
> from?
> I quite literally have a stock installation of FPC3.0.4RC1 and that
> is all.. nothing else, no Lazarus, no LibC or LibUSB anything
> development or otherwise.   So it seems the first step will be to
> install the prerequisite packages.  I'll see if I can figure that
> out.

Yes, pas-libusb is a Pascal wrapper for the Linux library libusb. That
library itself further depends on libc. Thats why you have to install
them, and including their respective development packages.

Was the message of Jean helpful for you?

Thanks
  Hansi

> -----Original Message-----
> From: fpc-pascal <[hidden email]> On Behalf
> Of Johann Glaser
> Sent: Tuesday, July 30, 2019 4:54 PM
> To: [hidden email]
> Subject: Re: [fpc-pascal] USB Human Interface Devices
>
> Hi James!
>
> Am Dienstag, den 30.07.2019, 13:52 -0400 schrieb James Richters:
> > > > Due to my lack of understanding of Windows, I've not yet taken
> > > > over his changes, because I wanted to wait for confirmation
> > > > from
> > > > other users. So if James had some feedback, I'd appreciate it
> > > > greatly.
> >
> > I'm trying to get this to work on windows,  I'm having a lot of
> > units
> > not found errors when I try to compile anything at all.. I'm not
> > sure
> > what I need here to get the examples to work.    Here is a list of
> > units I can't find when I try to compile with FPC 3.0.4RC1 on
> > Windows:
> >
> > ezusb.pas(42,15) Fatal: Can't find unit Errors used by EZUSB I have
> > no
> > idea what Unit Errors is or what it might be for.
>
> Thanks for pointing this out. This is a Unix unit, but it is
> obviously not used in Ezusb. I've removed it now.
>
> > libusb.pas(1350) Warning: Library c.dll not found, Linking may fail
> > !                                                ■
> > libusb.pas(1350) Warning: Library usb-1.0 not found, Linking may
> > fail !
> > I'm not really following where c.dll and usb1.0 are supposed to
> > come
> > from
>
> It seems you didn't install the development stuff for libc and lib-
> usb?
> At least in Linux, I always have to install these additionally (e.g.,
> libusb-1.0-0-dev) to the "productive" libraries (e.g., libusb-1.0-0).
>
> > usb.pas(31,22) Fatal: Can't find unit Baseunix used by USB
>
> Same as above for Errors. However, this file is unused.
>
> > mydevice.pas(27,20) Fatal: Can't find unit BaseUnix used by
> > MyDevice I
> > have no idea what BaseUnix does or if I can do something windows
> > compatible instead somehow.
>
> Same as above for Errors.
>
> > Test1Library.pas:
> > ║ (0) Error: Import library not found for c ║ (0) Error: Import
> > library not found for usb-1.0
>
> This seems to be again a problem because of the missing development
> stuff for libc anc libusb.
>
> > To be honest this is quite a bit over my head.  I'm trying to
> > follow
> > https://github.com/hansiglaser/pas-libusb/issues/4 but I'm just
> > lost.
>
> I would recommend, first to just compile the pristine pas-libusb
> without any hints from that Github issue. Only if you get the same
> errors, please try them and let me know.
>
> As stated above, I've now removed all references to the units Errors
> and Baseunix. Please "git pull" to the newest state on Github and
> compile again. If you still face problems, please don't hesitate to
> ask again.
>
> Thanks
>   Hansi
>
>
> _______________________________________________
> 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
I understand it better now, but I've been out of town and haven't been able to work on it.   I'm not sure what is meant by installing development packages though.. I see libusb at https://libusb.info/ I see where to download that.. but I don't know about development packages?  As for LibC,   I'm not really sure where to find the proper package for that.  I found http://gnuwin32.sourceforge.net/packages/libc.htm.bak but I'm not sure that is right, and again not sure about development package for that.  I would really appreciate links to the exact packages I will need to use for Windows.

James

>Yes, pas-libusb is a Pascal wrapper for the Linux library libusb. That library itself further depends on libc. Thats why you have to install them, and including their respective development packages.

>Was the message of Jean helpful for you?
_______________________________________________
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
@Johann: Is the Readme.rst at https://github.com/hansiglaser/pas-libusb 
up to date ?
It states that only the legacy version 0.1 of libusb is supported, but
the binary package for Windows on libusb.info is in version 1.0.22.
You can get source code for old versions of libusb on github but it
seems at first glance that there are no release of windows version
before 1.0.20 (14 sep 2015) (
https://github.com/libusb/libusb/releases?after=v1.0.21-rc4 ).

I tried to compile TestFirmware.pas on windows, I made a few
modifications. I join the diff files.
In ezusb.pas I replaced the dependency to Errors unit by a quick and
dirty rewrite of StrError function, just to allow compilation.
In paslibusbutils.pas I replace the call to fpGetTimeOfDay by a call to
DateTimeToUnix(Now),  I'm not sure may be the result of DateTimeToUnix
is truncated to seconds where fpGetTimeOfDay gives a result in microseconds.
In usb.pas I duplicated some constant definitions from errno.inc
included in unit BaseUnix: ESysETIMEDOUT, ESysEAGAIN...
I also replaced the call to fpSelect(0,Nil,Nil,Nil,100) by Sleep(100)
which should do the same thing, waiting for 100 milliseconds.

@James: Now, I just get the two final errors "Import library not found
for c" and "Import library not found for usb".
For now I haven't found which library to use for c.
I'm preparing another mail for this.


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

ezusb.diff (786 bytes) Download Attachment
paslibusbutils.diff (817 bytes) Download Attachment
usb.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
In reply to this post by Zaaphod
I've tried to link to ucrt.lib from Windows 10 SDK but I got this error
libusb.pas(359,0) Error: Invalid DLL C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17134.0\ucrt\x64\ucrt.lib, Dos Header invalid
it seems that static libraries produced by Microsoft tools cannot be used by the freepascal linker,
so you need a static library produced by mingw.




_______________________________________________
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
It seems that you can just remove {$LINKLIB c} in libusb.pas.

The libusb from libusb.info cannot be used because the functions it provides are different, and if you try to recompile a version before 1.0 like 0.9.4, it fails because Windows target was not yet supported by the library.
But on  https://sourceforge.net/projects/libusb-win32/  you find a port to Windows of libusb-0.1 to Windows.
I downloaded libusb-win32-bin-1.2.6.0.zip and extracted it. From the subdirectory libusb-win32-bin-1.2.6.0\bin\amd64 I copied libusb0.dll to the directory of TestFirmware.pas.
In LibUSB.pas I changed {$LINKLIB usb} to {$LINKLIB libusb0.dll}.
I got a few errors on compilation because of some changes in libusb.
The variables usb_error_errno and usb_error_type doesn't exist anymore in the library, for now I just comment them out:
    usb_error_errno : LongInt; //cvar; external; { from libusb }
    usb_error_type  : LongInt; //cvar; external; { from libusb }

Two functions are not available any more, I commented them too:
 //Function usb_get_driver_np          (dev:PUSBDevHandle; TheInterface:Longint; Var name; namelen:LongInt) : Longint; cdecl; external;
 //Function usb_detach_kernel_driver_np(dev:PUSBDevHandle; TheInterface:Longint) : LongInt; cdecl; external;

This breaks in USB.pas the function USBGetDriver and the method TUSBInterface.Claim. For now I just made a small modification to comment the calls.
I join the diffs for libusb.pas and usb.pas .

With this modifications, I could compile successfully TestFirmware.pas. On execution I got this error:
E:\03_travail\libusb\test>TestFirmware.exe
Couldn't connect to device: Couldn't find firmware file "firmware.ihx" in search path ".:~/.testfirmware:(my path variable here):/etc/testfirmware". You might try to set the environment variable "TESTFIRMWAREFIRMWAREPATH".
which is normal because I don't have any test case with a firmware file for now.


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

libusb.diff (1K) Download Attachment
usb.diff (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
In reply to this post by Zaaphod

With libusb-win32 I tried to make a small program to list the usb devices.
I discovered that the constant PATH_MAX had changed from 4096 in pas-libusb to 512 in libusb-win32-bin-1.2.6.0\include\lusb0_usb.h line 21 . This was causing an exception.

Now the program works but just output "Bus: bus-0" with no devices.
libusb-win32 comes with two test programs testlibusb-win.exe and testlibusb.exe but don't find any devices too. I think that for some reason libusb-win32 doesn't work with recent Windows (I'm testing on Windows 10).

If you want to test, I've put temporarily a zip of my test directory at http://mars42.com/test_libusb-win32.zip .

I've seen https://sourceforge.net/p/libusb-win32/wiki/Home/ that they advice to migrate to the libusb-1.0 form http://libusb.info.



_______________________________________________
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

I tried to make an import for libusb-1.0.22.7z from https://libusb.info/ .
The import unit is very buggy but I could make a small program to list the usb devices.
On my machine, it gives the same results that the example program libusb-1.0.22\examples\bin64\testlibusb.exe

I've published this program and the import at https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/tools/lsusb
You can get the corresponding binaries in this release https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_08_03_lsusb .

I used lazarus to generate and compile the console app, but I verified, you can compile it from the command line, you'll just have to change the path to you freepascal installation.

I converted the libusb.h to libusb.pas with h2pas from the lazarus plugin H2Paswizard ( https://wiki.freepascal.org/H2Paswizard ).

You'll find the project for H2Paswizard at https://github.com/jsuzineau/pascal_o_r_mapping/tree/TjsDataContexte/tools/lsusb/include/libusb-1.0/project1.h2p

It's a very quick an dirty conversion. In h2paswizard I added  a rename from LIBUSB_CALL to WINAPI.

I got some problems with var parameters in functions for example I needed to change
     function libusb_open(dev: Plibusb_device; var dev_handle:Plibusb_device_handle):longint;cdecl;external name 'libusb_open';
into
    function libusb_open(dev: Plibusb_device; dev_handle:PPlibusb_device_handle):longint;cdecl;external name 'libusb_open';

I think this can be fixed by tuning some details of the import.


_______________________________________________
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

I've made another (unsuccessful) test, using libusb-compat ( https://github.com/libusb/libusb-compat-0.1/wiki ).

It's a compatibility layer which allows to use the new libusb 1.xx through the old API of libusb 0.1

I get nearly the same results as with libusb-win32 (just "Bus: 001" instead "Bus: bus-0"), maybe there's an error in my code.

If you want to test, I've put temporarily a zip of my test directory at http://mars42.com/test_libusb-compat.zip .

I got the dlls  through msys2 in this way:

You can download MSYS2 (http://www.msys2.org/ ) by
http://repo.msys2.org/distrib/x86_64/msys2-x86_64-20190524.exe

After complete installation, to install libusb type on the command line:
 pacman -S mingw64/mingw-w64-x86_64-libusb

and to install libusb-compat type :

 pacman -S mingw64/mingw-w64-x86_64-libusb-compat-git

In subdirectory mingw64\bin of your installation you get:
   libusb-1.0.dll    the libusb dll from https://libusb.info/
   libusb-0-1-4.dll  the libusb-compat dll with version 0.1 functions names, and which call libusb-1.0.dll

I'm not sure of the value of PATH_MAX to define in libusb.pas because  in the dll PATH_MAX is taken from limits.h ( mingw64\x86_64-w64-mingw32\include\limits.h) where it's first defined to PATH_MAX=260 but if _POSIX_ is defined then it's redefined to 512. Of course this can create havoc in the definition of USBDevice if the pointer "bus : PUSBBus;" isn't defined at the right place in memory...

For getting limits.h in subdirectory mingw64\x86_64-w64-mingw32\include , type :
 pacman -S mingw-w64-x86_64-headers-git


_______________________________________________
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
I've forgotten to give the command line to compile (change
"C:\lazarus\fpc\3.0.4\bin\x86_64-win64" to your fpc installation):

C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe -MObjFPC -Scghi -O1 -g -gl
-l -vewnhibq -Filib\x86_64-win64 -Fu..\pas-libusb\src -Fu.
-FUlib\x86_64-win64 -FE. -olsusb.exe lsusb.lpr


_______________________________________________
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
Zadig

I found a way to make  my test with libusb-win32 work. You just need to install a specific driver for the usb device you want to see.
This can be done using Zadig ( https://zadig.akeo.ie/ ). If you change the driver to "libusbK" or "libusb-win32" for a certain device with Zadig, it will appear with lsusb_libusb-win32\lsusb.exe .
But it doesn't change anything for the version with libusb-compat, lsusb_libusb-compat-msys2_mingw64\lsusb.exe wich shows nothing.
And it doesn't change anything either to the version with libusb, https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_08_03_lsusb which continue to show all the usb devices.
 
I have also tried libusbK ( http://libusbk.sourceforge.net/UsbK3/index.html ).
You can download it at  https://sourceforge.net/projects/libusbk/

There are delphi examples in the subdirectory bindings\examples_delphi .

They can be compiled easily with freepascal, you just need to compile in delphi mode.
For "bindings\examples_delphi\enumerate.dpr" you can use this command line ( from a cmd in the directory examples_delphi)
   C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe -MDelphi -Scghi -O1 -g -gl -l -vewnhibq -Filib\x86_64-win64 -Fu. -FUlib\x86_64-win64 -FE. -oenumerate.exe enumerate.dpr

For "bindings\examples_delphi\opendevice.dpr" it didn't found unit UExampleHelpers. I didn't investigated further but it seems you can find the unit at :
https://github.com/SimaWB/libusbkDelphi/blob/master/UExampleHelpers.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

Johann Glaser
Hi Jean!

Thanks for your effort and please excuse my late reply, I was busy the
last few days.

Please note that for pas-libusb there is a dedicated Git branch for the
newer LibUSB 1.0. The branch is called "libusb-1.0". Marc pointed to
that in his EMail from Fri, 26 Jul 2019 15:56:17 +0200.

I'm sorry for the confusion! I've now updated the Readme.rst in the
branch "master" to point that out.

In the branch "libusb-1.0" I've lately changed a few things (see my
EMail from Tue, 30 Jul 2019 22:54:07 +0200) so that all dependencies to
Linux units should be gone.

Actually, with the branch "libusb-1.0" you should not need any "compat"
stuff any more.

Could you please give that a try and see whether you are more
successful with it?

Regarding "lsusb": The "test1library.pas" example should be just that.

Regarding the testfirmware example: This is specifically for devices
with the EZUSB Chip (e.g., Cypress AN2131). It is included to
demonstrate, how you could implement your own interface to your own
device with other chips with SRAM firmware (e.g. Cypress FX2 or FX3).

Bye
  Hansi

Am Sonntag, den 04.08.2019, 08:54 +0200 schrieb Jean SUZINEAU:

> Zadig
>
> I found a way to make  my test with libusb-win32 work. You just need
> to install a specific driver for the usb device you want to see.
> This can be done using Zadig ( https://zadig.akeo.ie/ ). If you
> change the driver to "libusbK" or "libusb-win32" for a certain device
> with Zadig, it will appear with lsusb_libusb-win32\lsusb.exe .
> But it doesn't change anything for the version with libusb-compat,
> lsusb_libusb-compat-msys2_mingw64\lsusb.exe wich shows nothing.
> And it doesn't change anything either to the version with libusb,
> https://github.com/jsuzineau/pascal_o_r_mapping/releases/tag/2019_08_03_lsusb
> which continue to show all the usb devices.
>
> I have also tried libusbK (
> http://libusbk.sourceforge.net/UsbK3/index.html ).
> You can download it at  https://sourceforge.net/projects/libusbk/
>
> There are delphi examples in the subdirectory
> bindings\examples_delphi .
>
> They can be compiled easily with freepascal, you just need to compile
> in delphi mode.
> For "bindings\examples_delphi\enumerate.dpr" you can use this command
> line ( from a cmd in the directory examples_delphi)
>    C:\lazarus\fpc\3.0.4\bin\x86_64-win64\fpc.exe -MDelphi -Scghi -O1
> -g -gl -l -vewnhibq -Filib\x86_64-win64 -Fu. -FUlib\x86_64-win64 -FE.
> -oenumerate.exe enumerate.dpr
>
> For "bindings\examples_delphi\opendevice.dpr" it didn't found unit
> UExampleHelpers. I didn't investigated further but it seems you can
> find the unit at :
> https://github.com/SimaWB/libusbkDelphi/blob/master/UExampleHelpers.pas
> _______________________________________________
> 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

Johann Glaser
In reply to this post by Zaaphod
Hi James!

Am Donnerstag, den 01.08.2019, 22:45 -0400 schrieb James Richters:

> I understand it better now, but I've been out of town and haven't
> been able to work on it.   I'm not sure what is meant by installing
> development packages though.. I see libusb at https://libusb.info/ I
> see where to download that.. but I don't know about development
> packages?  As for LibC,   I'm not really sure where to find the
> proper package for that.  I found
> http://gnuwin32.sourceforge.net/packages/libc.htm.bak but I'm not
> sure that is right, and again not sure about development package for
> that.  I would really appreciate links to the exact packages I will
> need to use for Windows.

I'm sorry that I can't help you here with these Windows-specific
questions.

Could somebody else please help out here?

Thanks
  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
In reply to this post by Johann Glaser
Hi Hansi,
Le 04/08/2019 à 14:05, Johann Glaser a écrit :
Thanks for your effort and please excuse my late reply, I was busy the
last few days.

With pleasure.

test1library.pas from branch "libusb-1.0" worked nearly out of the box.

I nearly just needed to redefine extdecl from stdcall to cdecl as in Linux.

I copied (libusb-1.0.22)\MinGW64\dll\libusb-1.0.dll of 274 Ko to (pas-libusb branch libusb-1.0)\src\examples.
In libusb.pas I removed {$LINKLIB c} and changed {$LINKLIB usb-1.0} to {$LINKLIB libusb-1.0.dll}
I join my diff files. Lazarus made a few changes to test1library.lpi but I don't think they are important.
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)

Upon execution, I got this results:

:\03_travail\libusb\pas-libusb\src\examples>test1library.exe
Using libusb(x) v1.0.22.11312
Found 13 devices:
  Bus   1 Device  15: ID 10C4:EA60,  port:  14, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device  12: ID 28DE:2101,  port:   7, port path from HCD: 0->11->11, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   0: ID 8086:A2AF,  port:   0, Speed: Unknown
  Bus   1 Device  10: ID 0BB4:2C87,  port:   5, port path from HCD: 0->5->5, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   9: ID 0BB4:2C87,  port:   2, port path from HCD: 0->0->0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   4: ID 1C4F:0002,  port:   7, port path from HCD: 0, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   1 Device   2: ID 046D:C077,  port:   8, port path from HCD: 0, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   1 Device   8: ID 28DE:2000,  port:   1, port path from HCD: 0->1->1, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   7: ID 0BB4:0306,  port:   2, port path from HCD: 0->33, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device  11: ID 28DE:2101,  port:   6, port path from HCD: 0->128->128, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   5: ID 07CA:A110,  port:   5, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   6: ID 0BB4:2134,  port:   1, port path from HCD: 0->0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   1: ID 0BB4:2210,  port:  11, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)

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


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

libusboop.pas.diff (426 bytes) Download Attachment
libusb.pas.diff (609 bytes) Download Attachment
test1library.lpi.diff (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
In reply to this post by Johann Glaser
Le 04/08/2019 à 14:07, Johann Glaser a écrit :
Hi James!

Am Donnerstag, den 01.08.2019, 22:45 -0400 schrieb James Richters:
I understand it better now, but I've been out of town and haven't
been able to work on it.   I'm not sure what is meant by installing
development packages though.. I see libusb at https://libusb.info/ I
see where to download that.. but I don't know about development
packages?  As for LibC,   I'm not really sure where to find the
proper package for that.  I found
http://gnuwin32.sourceforge.net/packages/libc.htm.bak but I'm not
sure that is right, and again not sure about development package for
that.  I would really appreciate links to the exact packages I will
need to use for Windows.
I'm sorry that I can't help you here with these Windows-specific
questions.

Could somebody else please help out here?

When you link to the dll, you can remove the {$LINKLIB c}.
But for now I haven't been able to make it work with a static link.

I added to project library search path in lazarus: E:\03_travail\libusb\libusb-1.0.22\MinGW64\static\ wich contains libusb-1.0.a
Then I changed {$LINKLIB usb-1.0} to {$LINKLIB libusb-1.0}, and removed {$LINKLIB c}
(I join the diff files)

In this way, libusb-1.0.a is found by the compiler, but the dependencies  of libusb-1.0.a on C runtime and several Windows system function are not fullfilled and you get these errors (I join them in file Compiler_output.txt)

Some of them like WaitForSingleObject are provided by Kernel32.dll but I don't know which lib from MinGW64 to use to provide __imp_WaitForSingleObject. 
Some others like atoi seem to be from the c runtime, but I haven't found  yet where are its libs (interesting link: https://stackoverflow.com/questions/52376724/mingw-w64-c-versions-support )





    

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

static_test_test1library.lpi.diff (8K) Download Attachment
static_test_libusboop.pas.diff (426 bytes) Download Attachment
static_test_libusb.pas.diff (674 bytes) Download Attachment
Compiler_output.txt (6K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Zaaphod

Hi Jean,  Thank you very much for your help getting this to work. I’ve been out of town on a business trip but I’m finally back now, and trying to follow all this.  I’ve been trying to follow along the conversation with Email but I did not have a very reliable internet connection. I did see a zip file you posted, but then it seems you made more changes since then, I’m not sure how to apply .diff files. 

 

Would it be possible to get an update zip file of the current files? 

 

I’m afraid a lot of this is just way over my head, I did not expect it to be anywhere near this complicated to get this to work, they python code I am trying to duplicate in my FPC application is so simple, but without access to the packages it uses, it’s turning out to be very complicated indeed..  ironically,  the unit I am trying to get to work is called EasyHID, but it seem to be anything but easy.

 

Here is the python code that I am trying to implement in my FPC program:

https://github.com/wolfmanjm/kivy-smoothie-host/blob/master/modules/hb04.py

 

 

James

 

From: fpc-pascal <[hidden email]> On Behalf Of Jean SUZINEAU
Sent: Sunday, August 4, 2019 12:39 PM
To: [hidden email]
Subject: Re: [fpc-pascal] USB Human Interface Devices

 

Le 04/08/2019 à 14:07, Johann Glaser a écrit :

Hi James!
 
Am Donnerstag, den 01.08.2019, 22:45 -0400 schrieb James Richters:
I understand it better now, but I've been out of town and haven't
been able to work on it.   I'm not sure what is meant by installing
development packages though.. I see libusb at https://libusb.info/ I
see where to download that.. but I don't know about development
packages?  As for LibC,   I'm not really sure where to find the
proper package for that.  I found
http://gnuwin32.sourceforge.net/packages/libc.htm.bak but I'm not
sure that is right, and again not sure about development package for
that.  I would really appreciate links to the exact packages I will
need to use for Windows.
 
I'm sorry that I can't help you here with these Windows-specific
questions.
 
Could somebody else please help out here?

 

When you link to the dll, you can remove the {$LINKLIB c}.

But for now I haven't been able to make it work with a static link.

 

I added to project library search path in lazarus: E:\03_travail\libusb\libusb-1.0.22\MinGW64\static\ wich contains libusb-1.0.a
Then I changed {$LINKLIB usb-1.0} to {$LINKLIB libusb-1.0}, and removed {$LINKLIB c}
(I join the diff files)

In this way, libusb-1.0.a is found by the compiler, but the dependencies  of libusb-1.0.a on C runtime and several Windows system function are not fullfilled and you get these errors (I join them in file Compiler_output.txt)

Some of them like WaitForSingleObject are provided by Kernel32.dll but I don't know which lib from MinGW64 to use to provide __imp_WaitForSingleObject. 
Some others like atoi seem to be from the c runtime, but I haven't found  yet where are its libs (interesting link: https://stackoverflow.com/questions/52376724/mingw-w64-c-versions-support )

 

 

 

 

_______________________________________________
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
Hi James,

Le 05/08/2019 à 04:40, James Richters a écrit :

Hi Jean,  Thank you very much for your help getting this to work. I’ve been out of town on a business trip but I’m finally back now, and trying to follow all this.  I’ve been trying to follow along the conversation with Email but I did not have a very reliable internet connection. I did see a zip file you posted, but then it seems you made more changes since then, I’m not sure how to apply .diff files. 

 

Would it be possible to get an update zip file of the current files? 


I put a zip of my working directory of pas-libusb as a pseudo "convenience" release on my github repository :
You should find every thing needed in it, you can even see my modifications with Tortoise Git, the .git subdirectory is included.
Let me know if I forgot something or if you get a problem.

 

I’m afraid a lot of this is just way over my head, I did not expect it to be anywhere near this complicated to get this to work, they python code I am trying to duplicate in my FPC application is so simple, but without access to the packages it uses, it’s turning out to be very complicated indeed..  ironically,  the unit I am trying to get to work is called EasyHID, but it seem to be anything but easy.

 

Here is the python code that I am trying to implement in my FPC program:

https://github.com/wolfmanjm/kivy-smoothie-host/blob/master/modules/hb04.py

I'm busy today, I had a quick look at hb04.py, I haven't yet tried to open a device with pas-usb but I don't think it would be too much difficult.



_______________________________________________
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

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

 

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

 

Hi James,

 

Le 05/08/2019 à 04:40, James Richters a écrit :

Hi Jean,  Thank you very much for your help getting this to work. I’ve been out of town on a business trip but I’m finally back now, and trying to follow all this.  I’ve been trying to follow along the conversation with Email but I did not have a very reliable internet connection. I did see a zip file you posted, but then it seems you made more changes since then, I’m not sure how to apply .diff files. 

 

Would it be possible to get an update zip file of the current files? 

 

I put a zip of my working directory of pas-libusb as a pseudo "convenience" release on my github repository :

You should find every thing needed in it, you can even see my modifications with Tortoise Git, the .git subdirectory is included.

Let me know if I forgot something or if you get a problem.

 

 

I’m afraid a lot of this is just way over my head, I did not expect it to be anywhere near this complicated to get this to work, they python code I am trying to duplicate in my FPC application is so simple, but without access to the packages it uses, it’s turning out to be very complicated indeed..  ironically,  the unit I am trying to get to work is called EasyHID, but it seem to be anything but easy.

 

Here is the python code that I am trying to implement in my FPC program:

https://github.com/wolfmanjm/kivy-smoothie-host/blob/master/modules/hb04.py

I'm busy today, I had a quick look at hb04.py, I haven't yet tried to open a device with pas-usb but I don't think it would be too much difficult.

 


_______________________________________________
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 Jean!

Am Sonntag, den 04.08.2019, 17:20 +0200 schrieb Jean SUZINEAU:
Hi Hansi,
Le 04/08/2019 à 14:05, Johann Glaser a écrit :
Thanks for your effort and please excuse my late reply, I was busy the
last few days.

With pleasure.

test1library.pas from branch "libusb-1.0" worked nearly out of the box.

I nearly just needed to redefine extdecl from stdcall to cdecl as in Linux.

I copied (libusb-1.0.22)\MinGW64\dll\libusb-1.0.dll of 274 Ko to (pas-libusb branch libusb-1.0)\src\examples.
In libusb.pas I removed {$LINKLIB c} and changed {$LINKLIB usb-1.0} to {$LINKLIB libusb-1.0.dll}
I join my diff files. Lazarus made a few changes to test1library.lpi but I don't think they are important.


Amazing, thanks for trying and giving feedback!

So, from my perspective, your results and modifications are the same as those of Vitaly at

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?

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)

Upon execution, I got this results:

:\03_travail\libusb\pas-libusb\src\examples>test1library.exe
Using libusb(x) v1.0.22.11312
Found 13 devices:
  Bus   1 Device  15: ID 10C4:EA60,  port:  14, port path from HCD: 0, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device  12: ID 28DE:2101,  port:   7, port path from HCD: 0->11->11, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   0: ID 8086:A2AF,  port:   0, Speed: Unknown
  Bus   1 Device  10: ID 0BB4:2C87,  port:   5, port path from HCD: 0->5->5, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   9: ID 0BB4:2C87,  port:   2, port path from HCD: 0->0->0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   4: ID 1C4F:0002,  port:   7, port path from HCD: 0, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   1 Device   2: ID 046D:C077,  port:   8, port path from HCD: 0, Speed: 1.5 Mbit/s (USB LowSpeed)
  Bus   1 Device   8: ID 28DE:2000,  port:   1, port path from HCD: 0->1->1, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   7: ID 0BB4:0306,  port:   2, port path from HCD: 0->33, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device  11: ID 28DE:2101,  port:   6, port path from HCD: 0->128->128, Speed: 12 Mbit/s (USB FullSpeed)
  Bus   1 Device   5: ID 07CA:A110,  port:   5, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   6: ID 0BB4:2134,  port:   1, port path from HCD: 0->0, Speed: 480 Mbit/s (USB HighSpeed)
  Bus   1 Device   1: ID 0BB4:2210,  port:  11, port path from HCD: 0, Speed: 480 Mbit/s (USB HighSpeed)

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

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).

For trying real custom communication (e.g., to bulk endpoints) you would need an appropriate USB device. For example at
I've implemented communication with electrical measurement devices (GPIB via USB). Somewhere on my harddisk I should have a driver for a barcode reader. And also drivers for a few devices built by myself. If you are interested or have questions, I can provide some sources too.

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
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>

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