USB Human Interface Devices

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

USB Human Interface Devices

Zaaphod

Does Freepascal have support for USB Human Interface devices?   I am attempting to interface to an WHB04B-4 https://www.amazon.com/gp/product/B07M5ZY1P2

I have an example of how to do it that was written in Python, so I’m trying to figure out how to get it to work with my FPC console application.   Figuring out how to interface with the device at all is what is holding me up, I don’t have any experience with direct interfacing to any USB devices.

 

Any suggestions?

 

 

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

Free Pascal - General mailing list

Hi,

Στις 26/7/2019 1:04 π.μ., ο James Richters έγραψε:

Does Freepascal have support for USB Human Interface devices?   I am attempting to interface to an WHB04B-4 https://www.amazon.com/gp/product/B07M5ZY1P2

I have an example of how to do it that was written in Python, so I’m trying to figure out how to get it to work with my FPC console application.   Figuring out how to interface with the device at all is what is holding me up, I don’t have any experience with direct interfacing to any USB devices.

 

Any suggestions?

you could try Alfred's HID library ( works in windows and linux ) .

https://github.com/LongDirtyAnimAlf/FPC-USB-HID.

regards,

--

Dimitrios Chr. Ioannidis


_______________________________________________
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'm not an expert, but a few years ago I made small project to read data from an Arduino through USB port. The project was running on Raspberry Pi, on Windows it can be more tricky( I'm not sure, but I think a device driver is needed):
https://github.com/jsuzineau/pascal_o_r_mapping/tree/master/electronic/Arduino/HeartRate ,  see Arduino_Special_Raspberry_Pi.lpi
It seems I used TLazSerial component.

Le 26/07/2019 à 00:04, James Richters a écrit :

Does Freepascal have support for USB Human Interface devices?   I am attempting to interface to an WHB04B-4 https://www.amazon.com/gp/product/B07M5ZY1P2

I have an example of how to do it that was written in Python, so I’m trying to figure out how to get it to work with my FPC console application.   Figuring out how to interface with the device at all is what is holding me up, I don’t have any experience with direct interfacing to any USB devices.

 

Any suggestions?

 

 

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

Brian
In reply to this post by Zaaphod
If you can find a controller with an Ethernet input , the Synapse is simple
to use and works well.

http://www.ararat.cz/synapse/doku.php/start

It also works well for RS-232.

It also claims to work with USB but I haven't tried it on USB.



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
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

Brian
In reply to this post by Zaaphod
If you can find a controller with an Ethernet input then Synapse is simple
and works well.

I have used it for RS-232 and Ethernet , but it claims to work with USB

http://www.ararat.cz/synapse/doku.php/start



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
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 am using synapse for RS-232 and I have played with ethernet with it with good results.  This device I am trying to use now is only available in USB and it's NOT a USB-Serial device..   The sample program I am referencing accesses it thorough an HID interface

James
-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of Brian
Sent: Thursday, July 25, 2019 8:00 PM
To: [hidden email]
Subject: Re: [fpc-pascal] USB Human Interface Devices

If you can find a controller with an Ethernet input then Synapse is simple and works well.

I have used it for RS-232 and Ethernet , but it claims to work with USB

http://www.ararat.cz/synapse/doku.php/start



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
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

Brian
Try the libusb library Free Pascal interface .. but be aware of his license
requirements. It works well.

http://johann-glaser.blogspot.com/2012/07/libusb-for-pascal.html



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
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've been trying to get some of these suggestions to work, but they all seem to require Lazarus, which I don't have and don't even know how to use.  I'm looking for a solution that will work in a pure FPC console application in Windows, without Lazarus.    I started trying to convert the demo programs into FPC only demos but there are just too many units I don't have and I don't know how to get around that.   The project I am trying to integrate this into is huge and several hundred thousand lines of code, and has been in development for 30 years, starting back with Turbo Pascal it would be completely impossible to port it all over to Lazarus.   I've tried just compiling my project with Lazarus before and just ran into issue after issue with it.  I’m currently using FPC 3.0.4RC1

Anyone have any suggestions for an FPC only console application method or demo I could use to access this USB HID device?

James

-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of Brian
Sent: Thursday, July 25, 2019 10:41 PM
To: [hidden email]
Subject: Re: [fpc-pascal] USB Human Interface Devices

Try the libusb library Free Pascal interface .. but be aware of his license requirements. It works well.

http://johann-glaser.blogspot.com/2012/07/libusb-for-pascal.html



--
Sent from: http://free-pascal-general.1045716.n5.nabble.com/
_______________________________________________
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

Free Pascal - General mailing list
Hi,

On 2019-07-26 13:39, James Richters wrote:
< snip >

> Anyone have any suggestions for an FPC only console application method
> or demo I could use to access this USB HID device?

< snip >

   As I suggested in my previous mail You can use the fpc-usb-hid library
from Alfred. I don't see any dependency for Lazarus in the
usbcontroller.pas which is, AFAIU, the main unit.

   If you're not in a hurry, I could try to make a simple console demo
this weekend.

regards,

--
Dimitrios Chr. Ioannidis
_______________________________________________
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

José Mejuto
In reply to this post by Zaaphod
El 26/07/2019 a las 12:39, James Richters escribió:

> Anyone have any suggestions for an FPC only console application method or demo I could use to access this USB HID device?

Hello,

This is not a complete HID interface but it can help you to start
working with them. It has been designed to handle USB Relays which are
managed using HID interface. Demos with and without GUI.

https://github.com/JoshyFun/VUSBRelayPascal

--

_______________________________________________
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

Marc Santhoff-2
In reply to this post by Brian
On Thu, 2019-07-25 at 19:40 -0700, Brian wrote:
> Try the libusb library Free Pascal interface .. but be aware of his license
> requirements. It works well.
>
> http://johann-glaser.blogspot.com/2012/07/libusb-for-pascal.html

http://johann-glaser.blogspot.com/2012/09/libusb-10-for-pascal.html


--
Marc Santhoff <[hidden email]>
_______________________________________________
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 Free Pascal - General mailing list
I did try fpc-usb-hid,  it uses units: BaseUnix and Unix which I don't have, and don't know what they are.   I tried commenting them out thinking maybe they were needed for Linux, but then it just can't find a lot of other things...   I am on Windows and using FPX 3.0.4RC1,  if the units I need are in a later version of FPC I can update it.  

A console demo would be a great help and very much appreciated, I am not in a huge hurry.

-----Original Message-----
From: fpc-pascal <[hidden email]> On Behalf Of Dimitrios Chr. Ioannidis via fpc-pascal
Sent: Friday, July 26, 2019 6:51 AM
To: FPC-Pascal users discussions <[hidden email]>
Cc: Dimitrios Chr. Ioannidis <[hidden email]>
Subject: Re: [fpc-pascal] USB Human Interface Devices

Hi,

On 2019-07-26 13:39, James Richters wrote:
< snip >

> Anyone have any suggestions for an FPC only console application method
> or demo I could use to access this USB HID device?

< snip >

   As I suggested in my previous mail You can use the fpc-usb-hid library from Alfred. I don't see any dependency for Lazarus in the usbcontroller.pas which is, AFAIU, the main unit.

   If you're not in a hurry, I could try to make a simple console demo this weekend.

regards,

--
Dimitrios Chr. Ioannidis
_______________________________________________
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

Marc Santhoff-2
On Fri, 2019-07-26 at 11:44 -0400, James Richters wrote:
> I did try fpc-usb-hid,  it uses units: BaseUnix and Unix which I don't have,
> and don't know what they are.   I tried commenting them out thinking maybe
> they were needed for Linux, but then it just can't find a lot of other
> things...   I am on Windows and using FPX 3.0.4RC1,  if the units I need are
> in a later version of FPC I can update it.

If baseUnix ans Unix are in use, the code is for unixoid OS. Linux, *BSD, etc.
The current LibUSB does support Windows, as you can see here:

https://libusb.info/

But I _think_ the Pascal header adaption will need to be ported to Windows.
Maybe someone else knows better?

> A console demo would be a great help and very much appreciated, I am not in
> a huge hurry.
>
> -----Original Message-----
> From: fpc-pascal <[hidden email]> On Behalf Of
> Dimitrios Chr. Ioannidis via fpc-pascal
> Sent: Friday, July 26, 2019 6:51 AM
> To: FPC-Pascal users discussions <[hidden email]>
> Cc: Dimitrios Chr. Ioannidis <[hidden email]>
> Subject: Re: [fpc-pascal] USB Human Interface Devices
>
> Hi,
>
> On 2019-07-26 13:39, James Richters wrote:
> < snip >
>
> > Anyone have any suggestions for an FPC only console application method
> > or demo I could use to access this USB HID device?
>
> < snip >
>
>    As I suggested in my previous mail You can use the fpc-usb-hid library
> from Alfred. I don't see any dependency for Lazarus in the usbcontroller.pas
> which is, AFAIU, the main unit.
>
>    If you're not in a hurry, I could try to make a simple console demo this
> weekend.
>
> regards,
>
> --
> Dimitrios Chr. Ioannidis
> _______________________________________________
> fpc-pascal maillist  -  [hidden email] https://lists.freepa
> scal.org/cgi-bin/mailman/listinfo/fpc-pascal
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
--
Marc Santhoff <[hidden email]>
_______________________________________________
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 Marc Santhoff-2
Hi!

Am Freitag, den 26.07.2019, 15:56 +0200 schrieb Marc Santhoff:
> On Thu, 2019-07-25 at 19:40 -0700, Brian wrote:
> > Try the libusb library Free Pascal interface .. but be aware of his
> > license
> > requirements. It works well.
> >
> > http://johann-glaser.blogspot.com/2012/07/libusb-for-pascal.html
>
> http://johann-glaser.blogspot.com/2012/09/libusb-10-for-pascal.html

Thanks for referring to my translation!

@Brian: I wasn't even aware of a license topic, but when checking back
now, the wrapper for the "old" libusb 0.1 states GPL in the README. I
think this was a bad idea.

Thanks to Marc to point to the newer wrapper for libusb 1.0, which uses
the same license as libusb, and for all stuff from me the same as the
FPC units. Just use the branch "libusb-1.0".

Anyhow, I would recommend to use libusb 1.0.

If you need any support, feel free to contact 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

Jean SUZINEAU
In reply to this post by Zaaphod
You can compile console projects with Lazarus, and even use non visual
components and datamodules. I've coded a dll (several hundred thousand
lines of code too) which is used by console programs on web servers. I
compile the dll with the same lazarus project in Lazarus for Windows 
and in Lazarus for Linux. The dll include datamodules with dataset
components.

_______________________________________________
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

Marc Santhoff-2
In reply to this post by Johann Glaser
On Fri, 2019-07-26 at 22:37 +0200, Johann Glaser wrote:

> Hi!
>
> Am Freitag, den 26.07.2019, 15:56 +0200 schrieb Marc Santhoff:
> > On Thu, 2019-07-25 at 19:40 -0700, Brian wrote:
> > > Try the libusb library Free Pascal interface .. but be aware of his
> > > license
> > > requirements. It works well.
> > >
> > > http://johann-glaser.blogspot.com/2012/07/libusb-for-pascal.html
> >
> > http://johann-glaser.blogspot.com/2012/09/libusb-10-for-pascal.html
>
> Thanks for referring to my translation!
>
> @Brian: I wasn't even aware of a license topic, but when checking back
> now, the wrapper for the "old" libusb 0.1 states GPL in the README. I
> think this was a bad idea.
>
> Thanks to Marc to point to the newer wrapper for libusb 1.0, which uses
> the same license as libusb, and for all stuff from me the same as the
> FPC units. Just use the branch "libusb-1.0".
>
> Anyhow, I would recommend to use libusb 1.0.

I've seen "$ifdef Windows" in the Code, so it does support Windows without any
change?

If so, that would be James' solution.

--
Marc Santhoff <[hidden email]>
_______________________________________________
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 Samstag, den 27.07.2019, 14:27 +0200 schrieb Marc Santhoff:

> On Fri, 2019-07-26 at 22:37 +0200, Johann Glaser wrote:
> > Hi!
> >
> > Am Freitag, den 26.07.2019, 15:56 +0200 schrieb Marc Santhoff:
> > > On Thu, 2019-07-25 at 19:40 -0700, Brian wrote:
> > > > Try the libusb library Free Pascal interface .. but be aware of his
> > > > license
> > > > requirements. It works well.
> > > >
> > > > http://johann-glaser.blogspot.com/2012/07/libusb-for-pascal.html
> > >
> > > http://johann-glaser.blogspot.com/2012/09/libusb-10-for-pascal.html
> >
> > Thanks for referring to my translation!
> >
> > @Brian: I wasn't even aware of a license topic, but when checking back
> > now, the wrapper for the "old" libusb 0.1 states GPL in the README. I
> > think this was a bad idea.
> >
> > Thanks to Marc to point to the newer wrapper for libusb 1.0, which uses
> > the same license as libusb, and for all stuff from me the same as the
> > FPC units. Just use the branch "libusb-1.0".
> >
> > Anyhow, I would recommend to use libusb 1.0.
>
> I've seen "$ifdef Windows" in the Code, so it does support Windows without any
> change?
>
> If so, that would be James' solution.

I've never tested it on Windows myself, but I integrated some changes
provided by other users quite some time ago.

BTW: A few weeks ago I was contacted on Github regarding Windows
support. The user had some issues, but then he found a solution.

https://github.com/hansiglaser/pas-libusb/issues/4

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.

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

Zaaphod

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

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

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

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.

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


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.

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

Johann Glaser
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
Reply | Threaded
Open this post in threaded view
|

Re: USB Human Interface Devices

Jean SUZINEAU
In reply to this post by Zaaphod
Le 30/07/2019 à 19:52, James Richters a écrit :
libusb.pas(1350) Warning: Library c.dll not found, Linking may fail ! ■

As stated in https://github.com/hansiglaser/pas-libusb/issues/4

it's very likely you'll have to change

{$LINKLIB c}

into

  {$linklib msvcrt}
(and you'll need to have a msvcrt.dll in your path, there are different versions of msvcrt, like msvcrt20.dll, I don't know exactly which one you will need)

Under linux, when the compiler finds {$LINKLIB c}, it will look for something like "libc.so" (the runtime dll) and "libc.a" (file with infos for compilation and link).

Le 30/07/2019 à 19:52, James Richters a écrit :
libusb.pas(1350) Warning: Library usb-1.0 not found, Linking may fail !

Did you install the windows version of libusb ?

It seems to be at https://libusb.info/

I think you'll have to change 

{$LINKLIB usb-1.0}
into something like
{$LINKLIB libusb-1.0}
and libusb-1.0.dll and libusb-1.0.lib should be accessible on your path.

Some unix libraries are available through distributions such MinGW (http://www.mingw.org/)
It seems libusb is available under windows (libusb-1.0.22.7z) with four different compilations:
-MinGW 32 bits (I imagine it uses the libc from mingw, the glibc I suppose)
-MinGW 64 bits
-MS32 I think it's compiled with Microsoft Visual Studio/ Microsoft Visual C++ and use the MSVCRT dll
-MS64 the same in 64 bits architecture.


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