Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-05

Communication USB, Lazarus et MAC OS X

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Sébastien FLOURETTE

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;
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?
Thanks you

Bonne journ?e S?bastien -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20090526/500798c0/attachment.html>

Reply by email

Mattias Gaertner
to Sébastien FLOURETTE
Show quoted text 63 lines
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)?

Show quoted text 36 lines
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

Reply by email

Yan Chengyuan
to Mattias Gaertner

I'm sorry,but what does 'cdecl' mean?
in fact i know nothing about how to import functions from external compiled library.
? 2009-05-26?? 14:15 +0200?Mattias Gaertner???

Show quoted text 119 lines
On Tue, 26 May 2009 13:58:14 +0200 S?bastien FLOURETTE 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 _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

Sébastien FLOURETTE

I'm going to try to add 'Var' in the declaration of my procedure. myusb_open is a procedure and not a fonction I have do an error of cut and paste..

I have always use 'cdecl' to declare external function but I'm not a pascal expert.

If you need more details to help me don't hesitate to ask me.

I thanks you.

I'm sorry,but what does 'cdecl' mean?
in fact i know nothing about how to import functions from external compiled library.
? 2009-05-26?? 14:15 +0200?Mattias Gaertner???

Show quoted text 119 lines
On Tue, 26 May 2009 13:58:14 +0200 S?bastien FLOURETTE 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 _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20090526/158b09b3/attachment-0001.html>

Reply by email