After two days of experimenting I can't get beyond an error on Libusb_open.
I have simplified as much as possible and it all hinges on "dev" returned by libusb_get_device_descriptor(dev,@desc)
The number returned in dev is a rather large number , but different each time. (29346192)
The large number puzzles me as, if it is an address, then the content prints as 0.
Worth noting that if I print all the other usb devices it finds, the numbers are in the same range.
Playing around with dev either returns an error of -4 (LIBUSB_ERROR_NO_DEVICE) or the program hangs with a segment violation.
Running it as Root from the terminal produces the same result.
By changing the Vendor & Product to your device, this program will run in Linux if someone can test it for me.
Couldn't include the .bi file as it exceeded the char count for this post, but it is in the previous thread.
One thing I simply can't get my head around is the multiple Ptr statements , like "libusb_device Ptr Ptr dev" and that probably contributes
to my lack of understanding the problem.
Code: Select all
#include once "libusb-1.0.bi"
Dim shared as libusb_device_descriptor desc
Dim shared as libusb_device Ptr Ptr dev
Dim shared as libusb_device_handle Ptr Ptr dev_handle
Dim shared as libusb_device Ptr Ptr devs
Dim shared as Long i = 0, j = 0, r = 0
Dim shared as UByte path(8)
Dim shared as ssize_t cnt
Sub print_devs(devs As libusb_device Ptr Ptr)
dev = devs[0]
'--------Look for one of two -----------------
While dev <> NULL
r = libusb_get_device_descriptor(dev, @desc)
Print r,dev
If r < 0 Then
Print "failed to get device descriptor"
Return
EndIf
If Hex(desc.idVendor,4) = "0A07" And Hex(desc.idProduct,4) = "0046" Then
Print "Found one ;";dev
Print Hex(desc.idVendor,4);":";Hex(desc.idProduct,4)
Print "bcdDevice ;"; desc.bcdDevice
Print "Serial Nbr ;"; desc.iSerialNumber
r = libusb_open(@dev, dev_handle)
Print "dev_handle ;"; dev_handle
Print "Error Detail ;";r
Print *(libusb_error_name(r))
Print
EndIf
i += 1
dev = devs[i]
Wend
'---------------------------------------------
End Sub
r = libusb_init(NULL)
If r < 0 Then
End r
EndIf
cnt = libusb_get_device_list(NULL, @devs)
If cnt < 0 Then
End cnt
EndIf
print_devs(devs)
libusb_free_device_list(devs, 1)
libusb_exit(NULL)
? "OK"
Sleep
Code: Select all
Sub usbInitialize
With usbOntrak
.Found = libusb_init(0)
If .Found = 0 Then
.usbFlag = 1
Else
Print "libusb_Init =; Failed"
Exit Sub
EndIf
If .Found = 0 Then
.HandlePtr = libusb_open_device_with_vid_pid(0, &H0a07, &H0046)
If .HandlePtr < 1 Then
Print "Open Handle Ptr =; Failed"
EndIf
If .HandlePtr > 0 Then
.usbFlag += 1
.CValue = libusb_kernel_driver_active(.HandlePtr,0) ''check if kernel has attached a driver
If .CValue > 0 Then ''if so
.Detach = libusb_detach_kernel_driver(.HandlePtr, 0) ''detach it
Endif
.Claim = libusb_claim_interface(.HandlePtr, 0) ''now we can claim the interface
If .Claim = 0 Then
.usbFlag += 1 ''This allows usbThread to proceed
Else
Print "Claiming I/F Failed "
EndIf
Endif
Buffer = Allocate(64)
.RetValue = libusb_get_string_descriptor_ascii(.HandlePtr,3,Buffer,64)
If .RetValue > 0 Then
Dim i as Ushort
For i = 0 to .RetValue
.SerialNbr(1) += Chr(Buffer[i])
Next
EndIf
Print .SerialNbr(1)
.Handle(1) = .HandlePtr
EndIf
End With
End Sub
I have tried to find other ways to open the port to no avail, so getting Libusb_open to work is crucial.
Hopefully someone here has experience with this and sees the problem.
Much appreciated.
Regards