Seite 2 von 2

Re: libusb unter Windows mit PureBasic

Verfasst: 24.01.2013 15:17
von Alexsvc
Solution:

Code: Alles auswählen

EnableExplicit

IncludeFile "usbHeader.pb" ;константы и структуры необоходимые для libusb0.dll

; Прототипы функций
; ----------------------------------------------------------------------

; allready tested and works fine

PrototypeC.l prot_usb_get_version()
PrototypeC.l prot_usb_init()
PrototypeC.l prot_usb_find_busses()
PrototypeC.l prot_usb_find_devices()
PrototypeC.l prot_usb_get_busses()


; ----------------------------------------------------------------------

; Don't work for me, but don't know why :(

PrototypeC.l prot_usb_open(*dev.usb_device)      ;returns *usb_dev_handle
PrototypeC.l prot_usb_close(*dev.usb_dev_handle) ;returns 0 if success
PrototypeC.l prot_usb_set_configuration(*dev.usb_dev_handle, configuration.l) ;returns 0 If success
PrototypeC.l prot_usb_set_altinterface(*dev.usb_dev_handle, alternate.l)
PrototypeC.l prot_usb_resetep(*dev.usb_dev_handle, ep.l) ; usb_resetep is deprecated. Use usb_clear_halt
PrototypeC.l prot_usb_clear_halt(*dev.usb_dev_handle, ep.l)
PrototypeC.l prot_usb_reset(*dev.usb_dev_handle)
PrototypeC.l prot_usb_claim_interface(*dev.usb_dev_handle, hInterface.l)
PrototypeC.l prot_usb_release_interface(*dev.usb_dev_handle, hInterface.l)

PrototypeC.l prot_usb_control_msg(*dev.usb_dev_handle, requesttype.l, request.l, value.l, index.l, *bytes.c, size.l, timeout.l)
PrototypeC.l prot_usb_get_string(*dev.usb_dev_handle, index.l, langid.l, *buf.c, buflen.i)
PrototypeC.l prot_usb_get_string_simple(*dev.usb_dev_handle, index.l, *buf.c, buflen.i)
PrototypeC.l prot_usb_get_descriptor(*dev.usb_dev_handle, type.c, index.c, *buf.l, size.l)
PrototypeC.l prot_usb_get_descriptor_by_endpoint(*dev.usb_dev_handle, ep.l, type.c, index.c, *buf.l, size.l)

PrototypeC.l prot_usb_bulk_write(*dev.usb_dev_handle, ep.l, *bytes.c, size.l, timeout.l)
PrototypeC.l prot_usb_bulk_read(*dev.usb_dev_handle, ep.l, *bytes.c, size.l, timeout.l)

PrototypeC.l prot_usb_interrupt_write(*dev.usb_dev_handle, ep.l, *bytes.c, size.l, timeout.l)
PrototypeC.l prot_usb_interrupt_read(*dev.usb_dev_handle, ep.l, *bytes.c, size.l, timeout.l)

PrototypeC.l prot_usb_get_driver_np(*dev.usb_dev_handle, hInterface.l, *name.c, namelen.l)
PrototypeC.l prot_usb_detach_kernel_driver_np(*dev.usb_dev_handle, hInterface.l)



Global libUsbID = OpenLibrary(#PB_Any, "libusb0.dll")

;Define Function-Pointers for CallFunctionFast
If IsLibrary(libUsbID)
  

  Global usb_get_version.prot_usb_get_version             = GetFunction(libUsbID, "usb_get_version")

  ;-Функции ядра
  Global usb_init.prot_usb_init                           = GetFunction(libUsbID, "usb_init")
  Global usb_find_busses.prot_usb_find_busses             = GetFunction(libUsbID, "usb_find_busses")
  Global usb_find_devices.prot_usb_find_devices           = GetFunction(libUsbID, "usb_find_devices")
  Global usb_get_busses.prot_usb_get_busses               = GetFunction(libUsbID, "usb_get_busses")

  ;-Device operations
  Global usb_open.prot_usb_open                           = GetFunction(libUsbID, "usb_open")
  Global usb_close.prot_usb_close                         = GetFunction(libUsbID, "usb_close")
  Global usb_set_configuration.prot_usb_set_configuration = GetFunction(libUsbID, "usb_set_configuration")
  Global usb_set_altinterface.prot_usb_set_altinterface   = GetFunction(libUsbID, "usb_set_altinterface")
  Global usb_resetep.prot_usb_resetep                     = GetFunction(libUsbID, "usb_resetep")
  Global usb_clear_halt.prot_usb_clear_halt               = GetFunction(libUsbID, "usb_clear_halt")
  Global usb_reset.prot_usb_reset                         = GetFunction(libUsbID, "usb_reset")
  Global usb_claim_interface.prot_usb_claim_interface     = GetFunction(libUsbID, "usb_claim_interface")
  Global usb_release_interface.prot_usb_release_interface = GetFunction(libUsbID, "usb_release_interface")

  ;-Control Transfer
  Global usb_control_msg.prot_usb_control_msg             = GetFunction(libUsbID, "usb_control_msg")
  Global usb_get_string.prot_usb_get_string               = GetFunction(libUsbID, "usb_get_string")
  Global usb_get_string_simple.prot_usb_get_string_simple = GetFunction(libUsbID, "usb_get_string_simple")
  Global usb_get_descriptor.prot_usb_get_descriptor       = GetFunction(libUsbID, "usb_get_descriptor")
  Global usb_get_descriptor_by_endpoint.prot_usb_get_descriptor_by_endpoint = GetFunction(libUsbID, "usb_get_descriptor_by_endpoint")

  ;-Bulk Transfer
  Global usb_bulk_write.prot_usb_bulk_write               = GetFunction(libUsbID, "usb_bulk_write")
  Global usb_bulk_read.prot_usb_bulk_read                 = GetFunction(libUsbID, "usb_bulk_read")

  ;-Interrupt Transfer
  Global usb_interrupt_write.prot_usb_interrupt_write     = GetFunction(libUsbID, "usb_interrupt_write")
  Global usb_interrupt_read.prot_usb_interrupt_read       = GetFunction(libUsbID, "usb_interrupt_read")

  ;-Non Portable
  Global usb_get_driver_np.prot_usb_get_driver_np         = GetFunction(libUsbID, "usb_get_driver_np")
  Global usb_detach_kernel_driver_np.prot_usb_detach_kernel_driver_np = GetFunction(libUsbID, "usb_detach_kernel_driver_np")

EndIf



DisableExplicit

Re: libusb unter Windows mit PureBasic

Verfasst: 13.06.2013 03:02
von NicTheQuick
Ich hab eben übrigens den Header für libusb komplett übersetzt. Jetzt fehlt nichts mehr. Es fehlt eigentlich nur noch der eigentliche Wrapper, der die Funktionen auf die Library mappt. Ich nehme an das kann ich dann ganz gut mit 'Import' lösen.
Bei Gelingen gibt es einen neuen Eintrag bei 'Code, Tipps & Tricks' und einen Querverweis hier. Ich brauche das nämlich gerade für ein neues Mikrocontroller-Projekt mit Anbindung an Linux über USB und mit FullSpeed. :)

Re: libusb unter Windows mit PureBasic

Verfasst: 13.06.2013 10:22
von Rings
gibts evt. denn ein link mit etwas lauffähigem ?

Re: libusb unter Windows mit PureBasic

Verfasst: 13.06.2013 12:39
von NicTheQuick
Noch nicht. Werde heute oder morgen zunächst mal den eigentlich Wrapper programmieren und dann gibt es natürlich auch Beispiele. Bisher habe ich nur alle Structures, Enumerations und Konstanten korrigiert und die Kommentare aus dem originalen C-Header übernommen. Die Structures, die da oben stehen, sind fast alle falsch, weil dort 'unsigned char' als '.c' übersetzt wurde. Hier musste erst mal alles auf '.a' korrigiert werden und dann haben noch etliche Structures gefehlt. Wenn ich wieder zu Hause bin und nen zweiten Bildschirm neben mir stehen habe, dann werde ich mit dem Rest weiter machen und mich wieder melden.

Re: libusb unter Windows mit PureBasic

Verfasst: 13.06.2013 14:40
von dige
Klingt interessant .. ich "subscribe" mal hiermit vorsorglich das Thema ;-)

Re: libusb unter Windows mit PureBasic

Verfasst: 25.07.2013 22:42
von NicTheQuick
Hier mal ein neues Thema dazu.