Re: Accessing USB HID from Lazarus programs?

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

Re: Accessing USB HID from Lazarus programs?

Bo Berglund
I posted this on the lazarus list but they suggested to send it to the
FPC list instead in order to possibly get better answers...

On Sun, 20 Mar 2011 10:04:28 -0500, Bo Berglund
<[hidden email]> wrote:

>I need to create a program using Lazarus/FPC to access a data
>collection device built using a PIC24F series microprocessor with
>built-in USB support. The firmware makes the PIC processor register as
>a Human Interface Device (HID) class USB device.
>
>I understand that for the HID class one does not have to provide a USB
>driver, there is already a generic one on Windows and possibly also on
>Linux.
>And the HID interface is not limited to mice and such, for example the
>PicKit3 PIC programmer and ICE uses the HID driver and it can both
>program code into PIC:s and execute PIC code with breakpoints from
>within MPLAB (the PIC develeopment IDE).
>
>My objective is to read the data from the data collection device using
>the USB interface and display the data on screen and also save to the
>PC disk.
>My FPC program should be able to run on Windows and preferably also on
>Linux.
>
>But I can't find any good examples on how to access the USB HID
>device....
>
>Can someone here please provide some help, links to code examples or
>similar?
>
>Or is this OT for this list since it is basically a hardware access
>question?
>


--
Bo Berglund
Developer in Sweden

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

Re: Accessing USB HID from Lazarus programs?

Henry Vermaak
On 20 March 2011 16:35, Bo Berglund <[hidden email]> wrote:

>>I need to create a program using Lazarus/FPC to access a data
>>collection device built using a PIC24F series microprocessor with
>>built-in USB support. The firmware makes the PIC processor register as
>>a Human Interface Device (HID) class USB device.
>>
>>I understand that for the HID class one does not have to provide a USB
>>driver, there is already a generic one on Windows and possibly also on
>>Linux.
>>And the HID interface is not limited to mice and such, for example the
>>PicKit3 PIC programmer and ICE uses the HID driver and it can both
>>program code into PIC:s and execute PIC code with breakpoints from
>>within MPLAB (the PIC develeopment IDE).
>>
>>My objective is to read the data from the data collection device using
>>the USB interface and display the data on screen and also save to the
>>PC disk.
>>My FPC program should be able to run on Windows and preferably also on
>>Linux.
>>
>>But I can't find any good examples on how to access the USB HID
>>device....

What you seen hidapi?

http://www.signal11.us/oss/hidapi/

You will probably have to translate the headers.

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

Re: Accessing USB HID from Lazarus programs?

Bo Berglund
On Sun, 20 Mar 2011 19:47:28 +0000, Henry Vermaak
<[hidden email]> wrote:

>On 20 March 2011 16:35, Bo Berglund <[hidden email]> wrote:
>>I need to create a program using Lazarus/FPC to access a data
>>collection device built using a PIC24F series microprocessor with
>>built-in USB support. The firmware makes the PIC processor register as
>>a Human Interface Device (HID) class USB device.
>>
>>I understand that for the HID class one does not have to provide a USB
>>driver, there is already a generic one on Windows and possibly also on
>>Linux.
>>And the HID interface is not limited to mice and such, for example the
>>PicKit3 PIC programmer and ICE uses the HID driver and it can both
>>program code into PIC:s and execute PIC code with breakpoints from
>>within MPLAB (the PIC develeopment IDE).
>>
>>My objective is to read the data from the data collection device using
>>the USB interface and display the data on screen and also save to the
>>PC disk.
>>My FPC program should be able to run on Windows and preferably also on
>>Linux.
>>
>>But I can't find any good examples on how to access the USB HID
>>device....
>
>What you seen hidapi?
>
>http://www.signal11.us/oss/hidapi/
>
>You will probably have to translate the headers.

Thanks, interesting read. I looked over what I thought would be the
valid items and also tested the included enumeration test project,
which found my keyboard, mouse and Microchip PicKit3 programmer.
So far so good....

But it looks like this is C or C++ stuff.... :-(
Is there any FPC translation anywhere?
I don't believe I can translate the C stuff properly myself to FPC.


--
Bo Berglund
Developer in Sweden

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

Re: Accessing USB HID from Lazarus programs?

Mark Morgan Lloyd-5
In reply to this post by Bo Berglund
Bo Berglund wrote:

> I posted this on the lazarus list but they suggested to send it to the
> FPC list instead in order to possibly get better answers...
>
> On Sun, 20 Mar 2011 10:04:28 -0500, Bo Berglund
> <[hidden email]> wrote:
>
>> I need to create a program using Lazarus/FPC to access a data
>> collection device built using a PIC24F series microprocessor with
>> built-in USB support. The firmware makes the PIC processor register as
>> a Human Interface Device (HID) class USB device.
>>
>> I understand that for the HID class one does not have to provide a USB
>> driver, there is already a generic one on Windows and possibly also on
>> Linux.
>> And the HID interface is not limited to mice and such, for example the
>> PicKit3 PIC programmer and ICE uses the HID driver and it can both
>> program code into PIC:s and execute PIC code with breakpoints from
>> within MPLAB (the PIC develeopment IDE).
>>
>> My objective is to read the data from the data collection device using
>> the USB interface and display the data on screen and also save to the
>> PC disk.
>> My FPC program should be able to run on Windows and preferably also on
>> Linux.
>>
>> But I can't find any good examples on how to access the USB HID
>> device....
>>
>> Can someone here please provide some help, links to code examples or
>> similar?

I'm accessing a Velleman K8055, which I think fits your description,
using libusb etc. I used Uwe Zimmerman's port of libusb
http://wiki.lazarus.freepascal.org/Hardware_Access#USB with very minor
changes, I used some C sources as examples but can't remember which-
possibly http://libk8055.sourceforge.net/

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Accessing USB HID from Lazarus programs?

el_es
In reply to this post by Bo Berglund
On 20/03/2011 22:53, Bo Berglund wrote:

> On Sun, 20 Mar 2011 19:47:28 +0000, Henry Vermaak
> <[hidden email]> wrote:
>> What you seen hidapi?
>>
>> http://www.signal11.us/oss/hidapi/
>>
>> You will probably have to translate the headers.
>
> Thanks, interesting read. I looked over what I thought would be the
> valid items and also tested the included enumeration test project,
> which found my keyboard, mouse and Microchip PicKit3 programmer.
> So far so good....
>
> But it looks like this is C or C++ stuff.... :-(
> Is there any FPC translation anywhere?
> I don't believe I can translate the C stuff properly myself to FPC.
>
>

In Turbo Delphi I have successfully used the headers found in JEDI project.
They're very Windows specific thou, as it captures system messages fwd to forms.
Haven't tried to use in Lazarus or multi-platform yet.

L.


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

Re: Accessing USB HID from Lazarus programs?

Sven Barth-2
In reply to this post by Bo Berglund
Am 20.03.2011 23:53, schrieb Bo Berglund:

> On Sun, 20 Mar 2011 19:47:28 +0000, Henry Vermaak
> <[hidden email]>  wrote:
>
>> On 20 March 2011 16:35, Bo Berglund<[hidden email]>  wrote:
>>> I need to create a program using Lazarus/FPC to access a data
>>> collection device built using a PIC24F series microprocessor with
>>> built-in USB support. The firmware makes the PIC processor register as
>>> a Human Interface Device (HID) class USB device.
>>>
>>> I understand that for the HID class one does not have to provide a USB
>>> driver, there is already a generic one on Windows and possibly also on
>>> Linux.
>>> And the HID interface is not limited to mice and such, for example the
>>> PicKit3 PIC programmer and ICE uses the HID driver and it can both
>>> program code into PIC:s and execute PIC code with breakpoints from
>>> within MPLAB (the PIC develeopment IDE).
>>>
>>> My objective is to read the data from the data collection device using
>>> the USB interface and display the data on screen and also save to the
>>> PC disk.
>>> My FPC program should be able to run on Windows and preferably also on
>>> Linux.
>>>
>>> But I can't find any good examples on how to access the USB HID
>>> device....
>>
>> What you seen hidapi?
>>
>> http://www.signal11.us/oss/hidapi/
>>
>> You will probably have to translate the headers.
>
> Thanks, interesting read. I looked over what I thought would be the
> valid items and also tested the included enumeration test project,
> which found my keyboard, mouse and Microchip PicKit3 programmer.
> So far so good....
>
> But it looks like this is C or C++ stuff.... :-(
> Is there any FPC translation anywhere?
> I don't believe I can translate the C stuff properly myself to FPC.
>
>

You can try to use h2pas, a tool which is distributed together with FPC.
It reads a C header file and outputs a Pascal file that contains the
bindings for the C library.

For the manual see here:
http://www.freepascal.org/tools/h2pas.var

For a little how to see here:
http://wiki.lazarus.freepascal.org/Creating_bindings_for_C_libraries

If it reports errors you should report back here as not every C
construct is understood by the tool.

Regards,
Sven
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Accessing USB HID from Lazarus programs?

Marco van de Voort
In reply to this post by Bo Berglund
In our previous episode, Bo Berglund said:
> I posted this on the lazarus list but they suggested to send it to the
> FPC list instead in order to possibly get better answers...

While I use dspic33F now, that is exclusively with serial. (232/422). In the
past I did use USB though with PIC18, and the microchip USB SDK had a delphi
example for that?

So I would check if pic18 and pic24  USB kits use the same dlls on the PC
side, and then use the headers and example from the SDK.
 
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Accessing USB HID from Lazarus programs?

Bo Berglund
In reply to this post by Mark Morgan Lloyd-5
On Mon, 21 Mar 2011 08:55:44 +0000, Mark Morgan Lloyd
<[hidden email]> wrote:

>
>I'm accessing a Velleman K8055, which I think fits your description,
>using libusb etc. I used Uwe Zimmerman's port of libusb
>http://wiki.lazarus.freepascal.org/Hardware_Access#USB with very minor
>changes, I used some C sources as examples but can't remember which-
>possibly http://libk8055.sourceforge.net/

On the page it says:

libusb
A cross platform possibility for Linux, BSDs and Mac OS X is libusb

Does this mean it won't work on Windows?

I can't test right now cause I am travelling today.


--
Bo Berglund
Developer in Sweden

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

Re: Accessing USB HID from Lazarus programs?

Mark Morgan Lloyd-5
Bo Berglund wrote:

> On Mon, 21 Mar 2011 08:55:44 +0000, Mark Morgan Lloyd
> <[hidden email]> wrote:
>
>> I'm accessing a Velleman K8055, which I think fits your description,
>> using libusb etc. I used Uwe Zimmerman's port of libusb
>> http://wiki.lazarus.freepascal.org/Hardware_Access#USB with very minor
>> changes, I used some C sources as examples but can't remember which-
>> possibly http://libk8055.sourceforge.net/
>
> On the page it says:
>
> libusb
> A cross platform possibility for Linux, BSDs and Mac OS X is libusb
>
> Does this mean it won't work on Windows?

There's a port of libusb for Windows. I half-heartedly tried my code a
couple of years ago against NT with the Edgeport USB stack but it failed
due to a missing kernel call, I've not tried it with a newer version of
Windows (i.e. one with the WDM) but I'd suggest it would be worth
investigating.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal