libusb

Share your advanced PureBasic knowledge/code with the community.
infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

libusb

Post by infratec »

Since it was needed I wrote a wrapper for libusb, the original one:

https://libusb.info/

https://github.com/libusb/libusb/releases

For windows, choose the 7z file and copy the dll from VS2022 in the directory of your code.

I think in linux it is installed by default.

For windows there are some things which should be noted:

The basic stuff works out of the box, but if you want to access a device, this device needs to have a driver installed which is compatible to libusb.

To manage this, the easiest way is to use zardig:

https://zadig.akeo.ie/

With this tool you can install the WinUSB driver for your device of interrest.

Then you can 'open' the device with libusb.

For macOS you have to install libusb via

brew install libusb


I provide a zip file with:

libcurl.pbi (the wrapper)
listdevs.pb
testlibusb.pb
rbtarm.pb (a basic test for 1267:0000)

https://www.von-der-salierburg.de/downl ... eBasic.zip
infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libusb

Post by infratec »

Added support for macOS
PeDe
Enthusiast
Enthusiast
Posts: 281
Joined: Sun Nov 26, 2017 3:13 pm

Re: libusb

Post by PeDe »

Just a small correction that I noticed. The function 'libusb_strerror' returns a pointer to a UTF8 string.

Peter

Code: Select all

EnableExplicit

IncludeFile "libusb.pbi"

If libusb_init(#Null) >= 0

	Debug libusb_strerror(-1)

	libusb_setlocale("fr")
	Debug libusb_strerror(-1) ; ASCII
	Debug PeekS(_libusb_strerror(-1), -1, #PB_UTF8)
	
	libusb_exit(#Null)
EndIf

; [Debug] Input/Output Error
; [Debug] Erreur d'entrée/sortie
; [Debug] Erreur d'entrée/sortie
infratec
Always Here
Always Here
Posts: 7613
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: libusb

Post by infratec »

PeDe wrote: Mon Jan 20, 2025 5:23 pm The function 'libusb_strerror' returns a pointer to a UTF8 string.
Fixed.
Post Reply