[Lazarus] Communication USB, Lazarus et MAC OS X

Mattias Gaertner nc-gaertnma at netcologne.de
Tue May 26 14:15:43 CEST 2009


On Tue, 26 May 2009 13:58:14 +0200
Sébastien FLOURETTE <sebastien.flourette at gmail.com> wrote:

> Hi,
> 
> I need again help !!
> 
> I have create a simple library in C compiled with GCC in mylibusb.o
> 
> The code is :
> #include <usb.h>
> 
> 
> myusb_open(usb_dev_handle *udev)
> {
>    struct usb_bus *bus;
>    struct usb_device *dev;
>    char buff[64];
>    int i;
> 
>    //Initialisation du bus USB
>    usb_init();
>    usb_find_busses();
>    usb_find_devices();
> 
>    for (bus = usb_busses; bus; bus = bus->next)
>    {
>       for (dev = bus->devices; dev; dev = dev->next)
>       {
>          if ((dev->descriptor.idVendor == 0x04D8) &&
> (dev->descriptor.idProduct == 0x1985))
>          {
>             udev = usb_open(dev);
>          }
> 
>            }
> 
>        }
> }
> 
> 
> myusb_close(usb_dev_handle *udev)
> {
>    usb_close(udev);
> }
> 
> 
> myusb_write(usb_dev_handle *udev)
> {
>    usb_bulk_write(udev, 0x01, 0x01, 64, 1000);
> }
> 
> 
> I link this myusblib.o with my lazarus program :
> 
> 
> unit usb_api;
> 
> 
> 
> interface
> 
> 
>      function myusb_open(udev : thandle);cdecl;
>      procedure myusb_close(udev : thandle) ; cdecl;
>      procedure myusb_write(udev : thandle); cdecl;

Maybe you forgot the 'var':
  function myusb_open(var udev : thandle);cdecl;
?

I don't know your C macros (who knows?), but are you sure myusb_open is
a function (or maybe a procedure)?


> implementation
> 
> {$link myusblib.o}
> {$linklib usb}
> {$linklib c}
> {$linklib gcc}
> 
> 
> uses CTypes;
> 
> function myusb_open; cdecl; external;
> procedure myusb_close; cdecl; external;
> procedure myusb_write; cdecl; external;
> end.
> 
> 
> 
> and when I do
> 
> var
> myhost : thandle;
> 
> begin
> myusb_open(myhost);
> myusb_write(myhost);
> myusb_close(myhost);
> end;
> 
> I have no communication with my usb board. My libusb.o work with the
> same program in C.
> 
> Have you got an idea on my problem or can you tell me if you have
> another solutions.
> 
> Is it possible to create a library Dll for windows and MAC OS and How
> can I do it with the libusb library?


Mattias




More information about the Lazarus mailing list