A good translation of that into FB would be:srvaldez wrote:... I got confused on libusb_device **devs, not sure if ptr ptr is the right FB interpretation.
Code: Select all
dim devs as libusb_device ptr ptr
A good translation of that into FB would be:srvaldez wrote:... I got confused on libusb_device **devs, not sure if ptr ptr is the right FB interpretation.
Code: Select all
dim devs as libusb_device ptr ptr
Code: Select all
Type USBPart
HandlePtr As Any Ptr
Buffer As Zstring Ptr
BufferLen As Integer
ReqType As Integer
Req As Integer
size As Integer
End Type
Code: Select all
'--------Next setup mesg and send-------------------
usb_ctrl_setup.bRequestType = 8
usb_ctrl_setup.bRequest = 6
usb_ctrl_setup.wValue = 1
usb_ctrl_setup.wIndex = 0
usb_ctrl_setup.wLength = 18
usbpart.Buffer = Allocate(65)
Dim As Integer RetBytes
RetBytes = usb_control_msg(usbpart.HandlePtr, usb_ctrl_setup.bRequestType, usb_ctrl_setup.bRequest, usb_ctrl_setup.wValue,usb_ctrl_setup.wIndex, usbpart.Buffer, usbpart.BufferLen,500)
Print "Mesg Bytes =;";RetBytes
Code: Select all
type usb_ctrl_setup
as ubyte bRequestType
as ubyte bRequest
as ushort wValue
as ushort wIndex
as ushort wLength
end type
Code: Select all
declare function usb_control_msg (dev as usb_dev_handle ptr, requesttype as integer, request as integer, value as integer, index as integer, bytes as byte ptr, size as integer, timeout as integer) as integer
Code: Select all
Sub usbInitialize
''----Start by init, list busses & devices-------
''1605:0018
Starttime = Timer * 1000
usb_init()
Print "Busses found =;";usb_find_busses() ''prints 3 for Nbr of busses found
Print "Devices found =;";usb_find_devices() ''print 9 for Nbr of devices found
''--------Then see if Vendor:Product exists----------
aBus = usb_get_busses() ''sets aBus as pointer to usb_get_busses
while (aBus) ''gets usb_get_busses Next
aDev = aBus->devices
while aDev
If Hex(aDev->descriptor.idVendor,4) = "1605" And Hex(aDev->descriptor.idProduct,4) = "0018" Then
Found = 1 ''stop looking we found it
Exit While ''exit loop
End If
aDev=aDev->next ''otherwise go for Next device
wend
If Found = 1 Then Exit While ''exit loop
aBus = aBus->next ''otherwise go for Next Bus
wend
''--------If Vendor:Product found then get handle and claim port----
If Found = 1 Then
Dim As usb_device Ptr AccessIO = aDev ''save the Ptr for device.
handlePtr = usb_open(AccessIO) ''use it to open, which returns a handle
Print "AccessIO Handle =;";handlePtr
Detach = usb_detach_kernel_driver_np(handlePtr, 0) ''This fails
Print "Detach success =;";Detach ''0 if success
Print "Claim Success =;";usb_claim_interface(handlePtr, 0) ''This succeeds
Endif
''--------Set Digital I/O bits using Control Transfer--
usb_ctrl_setup.bRequestType = &H80
usb_ctrl_setup.bRequest = &H10 '
usb_ctrl_setup.wValue = &H00
usb_ctrl_setup.wIndex = &H00
usb_ctrl_setup.wLength = &H08
Buffer = Allocate(8)
Buffer[0] = 255 ''O/P 0-7 output bits
Buffer[1] = 127 ''O/P 8-15
Buffer[2] = &HFF ''I/P 0-7 ignored when setting O/P's
Buffer[3] = &HFF ''I/P 8-15
RetBytes = usb_control_msg(HandlePtr, usb_ctrl_setup.bRequestType,usb_ctrl_setup.bRequest,usb_ctrl_setup.wValue,usb_ctrl_setup.wIndex, Buffer,usb_ctrl_setup.wLength,5000)
Print "RetBytes =;";RetBytes
Print "Values in Buffer=;";(Buffer[3]),(Buffer[2]),(Buffer[1]),(Buffer[0])
End Sub
Code: Select all
declare function usb_control_msg( _
ByVal dev as usb_dev_handle ptr, _
ByVal requesttype as Long, _
ByVal request as Long, _
ByVal value as Long, _
ByVal index as Long, _
ByVal bytes as byte ptr, _
ByVal size as Long, _
ByVal timeout as Long _
) as Long
My problem is two fold:VENDOR REQUEST 10 H : DIO W RITE
This request writes DO data to all bytes. (DO data for input bytes will be ignored.)
Value: Reserved, use 0000h.
Index: Reserved, use 0000h.
Data Written: 4 bytes, written to the corresponding DO bytes.
VENDOR REQUEST 11 H : DIO READ
This request reads all DIO bytes. For output bytes, this will read back the output values.
Value: Reserved, use 0000h.
Index: Reserved, use 0000h.
Data Read: 4 bytes, read from the corresponding DIO bytes
Code: Select all
#ifndef __USB_BI__
#define __USB_BI__
#inclib "usb"
#define USB_MAXENDPOINTS 32
#ifndef PATH_MAX
#define PATH_MAX 4096
#endif
type usb_endpoint_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ubyte bEndpointAddress
as ubyte bmAttributes
as ushort wMaxPacketSize
as ubyte bInterval
as ubyte bRefresh
as ubyte bSynchAddress
as ubyte ptr extra /' Extra descriptors '/
as Long extralen
end type
type usb_interface_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ubyte bInterfaceNumber
as ubyte bAlternateSetting
as ubyte bNumEndpoints
as ubyte bInterfaceClass
as ubyte bInterfaceSubClass
as ubyte bInterfaceProtocol
as ubyte iInterface
as usb_endpoint_descriptor ptr endpoint
as ubyte ptr extra /' Extra descriptors '/
as Long extralen
end type
type usb_interface
as usb_interface_descriptor ptr altsetting
as Long num_altsetting
end type
type usb_config_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort wTotalLength
as ubyte bNumInterfaces
as ubyte bConfigurationValue
as ubyte iConfiguration
as ubyte bmAttributes
as ubyte MaxPower
as usb_interface ptr interface
as ubyte ptr extra /' Extra descriptors '/
as Long extralen
end type
type usb_device_descriptor
as ubyte bLength
as ubyte bDescriptorType
as ushort bcdUSB
as ubyte bDeviceClass
as ubyte bDeviceSubClass
as ubyte bDeviceProtocol
as ubyte bMaxPacketSize0
as ushort idVendor
as ushort idProduct
as ushort bcdDevice
as ubyte iManufacturer
as ubyte iProduct
as ubyte iSerialNumber
as ubyte bNumConfigurations
end type
type usb_ctrl_setup
as Long bRequestType
as Long bRequest
as Long wValue
as Long wIndex
as Long wLength
end type
type usb_bus_ as usb_bus
type usb_device
as usb_device ptr next, prev
as zstring * PATH_MAX + 1 filename
as usb_bus_ ptr bus
as usb_device_descriptor descriptor
as usb_config_descriptor ptr config
as any ptr dev /' Darwin support '/
as ubyte devnum
as ubyte num_children
as usb_device ptr ptr children
end type
type usb_bus
as usb_bus ptr next, prev
as zstring * PATH_MAX + 1 dirname
as usb_device ptr devices
as Ulong location
as usb_device ptr root_dev
end type
type usb_dev_handle as any
type usb_bus_ as usb_bus
/' Variables '/
extern usb_busses as usb_bus ptr
extern "C"
declare function usb_open (dev as usb_device ptr) as usb_dev_handle ptr
declare function usb_close (dev as usb_dev_handle ptr) as Long
declare function usb_control_msg (dev as usb_dev_handle ptr, requesttype as Long, request as Long, value as Long, index as Long, bytes as byte ptr, size as Long, timeout as Integer) as Long
declare function usb_set_configuration(dev as usb_dev_handle ptr, configuration as Long) as Long
declare function usb_claim_interface (dev as usb_dev_handle ptr, interface as long) as long
declare function usb_release_interface(dev as usb_dev_handle ptr, interface as Long) as Long
declare function usb_detach_kernel_driver_np(dev as usb_dev_handle ptr, interface as Long) as Long
declare sub usb_init()
declare function usb_find_busses() as Long
declare function usb_find_devices() as Long
declare function usb_device(dev as usb_dev_handle ptr) as usb_device ptr
declare function usb_get_busses() as usb_bus Ptr
end extern
#endif /' __USB_BI__ '/
Dim Shared as Long Found, RetBytes, Detach
Dim Shared as usb_device ptr aDev
Dim Shared as usb_bus ptr aBus
Dim Shared handlePtr As Any Ptr
Dim Shared usb_ctrl_setup As usb_ctrl_setup
Dim Shared Buffer As UByte Ptr
Code: Select all
#include once "libusb.bi"
Sub usbInitialize
''----Start by init, list busses & devices-------
''1605:0018 Change this to suit device you are looking for.
usb_init()
Print "Busses found =;";usb_find_busses() ''prints 3 for Nbr of busses found
Print "Devices found =;";usb_find_devices() ''print 9 for Nbr of devices found
''--------Then see if Vendor:Product exists----------
aBus = usb_get_busses() ''sets aBus as pointer to usb_get_busses
while (aBus) ''gets usb_get_busses Next
aDev = aBus->devices
while aDev
If Hex(aDev->descriptor.idVendor,4) = "1605" And Hex(aDev->descriptor.idProduct,4) = "0018" Then
Found = 1 ''stop looking we found it
Exit While ''exit loop
End If
aDev=aDev->next ''otherwise go for Next device
wend
If Found = 1 Then Exit While ''exit loop
aBus = aBus->next ''otherwise go for Next Bus
wend
''--------If Vendor:Product found then get handle and claim port----
If Found = 1 Then
Dim As usb_device Ptr AccessIO = aDev ''save the Ptr for device.
handlePtr = usb_open(AccessIO) ''use it to open, which returns a handle
Print "AccessIO Handle =;";handlePtr
Detach = usb_detach_kernel_driver_np(handlePtr, 0) ''This fails
Print "Detach success =;";Detach ''0 if success
Print "Claim Success =;";usb_claim_interface(handlePtr, 0) ''This succeeds
Endif
''--------Set Digital I/O bits using Control Transfer--
usb_ctrl_setup.bRequestType = &H80
usb_ctrl_setup.bRequest = &H00
usb_ctrl_setup.wValue = &H00
usb_ctrl_setup.wIndex = &H00
usb_ctrl_setup.wLength = 4
Buffer = Allocate(4)
Buffer[0] = &H99 ''O/P 0-7 output bits
Buffer[1] = 100 ''O/P 8-15
Buffer[2] = &H0 ''I/P 0-7 ignored when setting O/P's
Buffer[3] = &H0 ''I/P 8-15
RetBytes = usb_control_msg(HandlePtr, usb_ctrl_setup.bRequestType,usb_ctrl_setup.bRequest,usb_ctrl_setup.wValue,usb_ctrl_setup.wIndex, Buffer,usb_ctrl_setup.wLength,5000)
Print "RetBytes =;";RetBytes
Print "Values in Buffer=;";(Buffer[3]),(Buffer[2]),(Buffer[1]),(Buffer[0])
Deallocate Buffer
End Sub
Sub usbQuit
''--------Release/Close port and quit-------------------------
If handlePtr Then
Print "Release result =;";usb_release_interface(handlePtr, 0)
Print "usb_Close result=;";usb_close(HandlePtr)
Else
Print "Interface Not found"
Endif
End Sub
usbinitialize
usbQuit
End
Here you are:Dinosaur wrote:Wouldn't it be nice if some one has already done the full conversion of .h to .bi for libusb-1.0 :(
getting errors from that:Function libusb_get_iso_packet_buffer
Other than that it worked perfectly.error 41: Variable not declared, offset in 'offset += transfer->iso_packet_desc(i).length
Code: Select all
#include once "libusb-1.0.bi"
Found = libusb_init(0)
Print "libusb_Init =;";Found ''This print 0
Handleptr = libusb_open_device_with_vid_pid(0, &H1605, &H0018)
Print "Handle Ptr=;";handleptr ''This print the pointer (34551824)
If Handleptr > 0 Then
Detach = libusb_detach_kernel_driver(Handleptr, 0)
Print "Detached =;";Detach ''This print -5
Claim = libusb_claim_interface(Handleptr, 0)
Print "Claim =;";Claim ''This print 0
libusb_control_setup.bmRequestType = &B10000000
libusb_control_setup.bRequest = &H00
libusb_control_setup.wValue = &H00
libusb_control_setup.wIndex = &H00
libusb_control_setup.wLength = 4
Buffer = Allocate(4)
Buffer[0] = &H99 ''O/P 0-7 output bits
Buffer[1] = 100 ''O/P 8-15
Buffer[2] = &H0 ''I/P 0-7 ignored when setting O/P's
Buffer[3] = &H0
With libusb_control_setup
RetBytes = libusb_control_transfer(HandlePtr,.bmRequestType,.bRequest,.wValue,.wIndex,Buffer,.wLength,5000)
End With
Print "RetBytes =;";RetBytes ''This prints the value 2
Print "Values in Buffer=;";(Buffer[3]),(Buffer[2]),(Buffer[1]),(Buffer[0]) ''This prints 0,0,0,0
Deallocate Buffer
Endif
Libusb_exit(0)
End