Include files for libUSB Linux and Windows.

For issues with communication ports, protocols, etc.
AWPStar
Posts: 47
Joined: May 03, 2009 21:47

Re: Include files for libUSB Linux and Windows.

Post by AWPStar »

Hello, can you help me?
Trying to compile my app with libusb under ubuntu(desktop, x86, 13.07.2016, 4.4.0-31-generic).

1. i have installed libuse by using

Code: Select all

sudo apt-get install libusb-1.0-0-dev
/usr/lib/libusb-1.0.so.0.0.0 linked to /usr/lib/libusb-1.0.so

2. inclusion for linux

Code: Select all

#include "usb.bi"
3. fbc test.bas

Got

Code: Select all

ld.exe: cannot find -lusb
When i trying to do it from C with "libusb.h" i'm getting no errors.
Thank you!
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Include files for libUSB Linux and Windows.

Post by St_W »

When I look into the package contents of "libusb-1.0-0-dev" I only see a library "libusb-1.0.so" (but not "libusb.so"), so try to link "usb-1.0" instead of "usb" (Parameter "-lusb-1.0" or #inclib "usb-1.0").

Alternatively create a symlink "libusb.so" pointing to "libusb-1.0.so"

Which library do you link when using the C code you mentioned?
AWPStar
Posts: 47
Joined: May 03, 2009 21:47

Re: Include files for libUSB Linux and Windows.

Post by AWPStar »

St_W wrote:so try to link "usb-1.0" instead of "usb" (Parameter "-lusb-1.0" or #inclib "usb-1.0").
That works! You saved my day. Thank you!
AWPStar
Posts: 47
Joined: May 03, 2009 21:47

Re: Include files for libUSB Linux and Windows.

Post by AWPStar »

New problem.

Code: Select all

undefined reference to 'usb_init'
St_W
Posts: 1619
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Include files for libUSB Linux and Windows.

Post by St_W »

AWPStar wrote:New problem.

Code: Select all

undefined reference to 'usb_init'
Looks like you are still missing some library(libraries) to link. Again, which libraries did you link when compiling the C code you mentioned? Just use the same with FB your FB code.
Alternatively "pkg-config --libs libusb-1.0" may help to find out the needed libraries.

//edit: OR the method name is just wrong.
When looking at http://libusb.sourceforge.net/api-1.0/api.html this seems to be the case. There's only "libusb_init", but no "usb_init".

//edit2: I just looked at the headers in the first post in this thread: they are outdated and do not match the current version of libusb. I guess they were translated for libusb 0.1, which seemed to use a different API.

You can't use those old headers. I'd suggest recreating the headers from scratch as there are so many differences.
AWPStar
Posts: 47
Joined: May 03, 2009 21:47

Re: Include files for libUSB Linux and Windows.

Post by AWPStar »

Thank you, again!
C command line:

Code: Select all

gcc test.c -o test -lusb-1.0
Well, i think i have to translate C header to .bi. But now i don't have much time, so i will write my app in C. Later i will translate it to .bi and share it.
jdmcbride
Posts: 28
Joined: Aug 06, 2016 16:13

Re: Include files for libUSB Linux and Windows.

Post by jdmcbride »

Hey you guys!

You have my attention and I've got to ask some questions. Why the bother with libusb? I access usb serial devices using "open" and the associated hardware usb-serial port driver...

I'm just curious what you are researching in case I'm missing out on some fun...
caseih
Posts: 2157
Joined: Feb 26, 2007 5:32

Re: Include files for libUSB Linux and Windows.

Post by caseih »

You can only "open" USB devices that present a serial interface or some other file-like interface. And many USB devices have drivers that present a high-level interface that you can work with. Otherwise you need to work with the USB device over usb protocol, which is what libusb is all about. The nice thing about libusb is that it lets you have access to the USB device from user space, which means you can create user-space drivers (instead of having signed code running in the kernel) for many things. The OWFS project uses libusb to talk to various iButton or 1wire devices via USB without needing any special drivers installed into the OS.
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: Include files for libUSB Linux and Windows.

Post by Dinosaur »

Hi All

Did anyone ever create a new .bi file for libusb-1.0 ?
and are they willing to share.

Regards
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Include files for libUSB Linux and Windows.

Post by srvaldez »

@Dinosaur
I am no expert, just a hobby programmer, I fed libusb.h to fbfrog and most of the '' TODO:'s were Windows specific, so if you intend to use libusb on Linux then perhaps the generated bi is good enough.
fbfrog does a lot in the translation of C to FB but it does not handle loops, if there's code in a loop that you would like fbfrog to translate then edit the header commenting-out the loop but leaving the loop body, you will then get a scope -translated-code- end scope
Dinosaur
Posts: 1478
Joined: Jul 24, 2005 1:13
Location: Hervey Bay (.au)

Re: Include files for libUSB Linux and Windows.

Post by Dinosaur »

Hi All

srvaldez, that is just what I did, but the amount of "Todo's" put me off from using it.
On the same hand I don't want to start a new project with an outdated library.
I am actually using the code from D.J Peters to establish a usb_control_msg link with an industrial I/O board
that promises some very fast transactions.

But it has been many years since I played with usb for dos, so I am re-learning everything.

Regards
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Include files for libUSB Linux and Windows.

Post by grindstone »

I actually finished translation of the header file of libusb-1.0.24.7 (the latest version AFAIK).

Not tested yet (not at all) nor cleaned up, but it compiles without errors:
http://users.freebasic-portal.de/grinds ... es/libUSB/
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Include files for libUSB Linux and Windows.

Post by srvaldez »

thank you grindstone, would you be willing to translate listdevs.c to FB ?, I got confused on libusb_device **devs, not sure if ptr ptr is the right FB interpretation.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Include files for libUSB Linux and Windows.

Post by grindstone »

I'm already trying, but I'm struggeling with that pointer stuff myself. defs points to the first member of an array of libusb_device pointers which each points to a device descriptor.

But at the attempt to access the 2nd descriptor, the program crashes. I'll have to figure out why.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Include files for libUSB Linux and Windows.

Post by grindstone »

libusb seems to corrupt the control variable of a FOR..NEXT loop. The loop doesn't terminate.
Post Reply