Jump to content

Recommended Posts

Posted (edited)

Hi, I have been playing arround with libusb0-win32 and was/am attempting to make the starts of a udf library as I haven't found one and it would come in handy for my current project.

I am having trouble figuring out how I would convert this code:

http://libusb.sourceforge.net/doc/examples-code.html

more notably this section

struct usb_bus *bus; int c, i, a; /* ... */ for (bus = busses; bus; bus = bus->next) { struct usb_device *dev; for (dev = bus->devices; dev; dev = dev->next) {

to work with autoit.

At the moment I have this code:

libusb0.au3

#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.4.0 Author:    Craig Gilhooley Script Function:    libusb0 Functions. #ce ---------------------------------------------------------------------------- ; Script Start $libusb0 = DllOpen("libusb0.DLL") Func usb_init()    DllCall ($libusb0, "none", "usb_init") EndFunc Func usb_find_busses()   $retval = DllCall ($libusb0, "int", "usb_find_busses")  Return $retval EndFunc Func usb_find_devices()  $retval = DllCall ($libusb0, "int", "usb_find_devices")     Return $retval EndFunc Func usb_get_busses()    $retval = DllCall ($libusb0, "ptr", "usb_get_busses")   Return $retval EndFunc Func usb_open($devicePointer)    $retval = DllCall ($libusb0, "int", "usb_open", "ptr", $devicePointer)  Return $retval EndFunc Func usb_close($devicePointer)   $retval = DllCall ($libusb0, "int", "usb_close", "ptr", $devicePointer)     Return $retval EndFunc

libusb test.au3

#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.4.0 Author:    Craig Gilhooley Script Function:    libusb0 test. #ce ---------------------------------------------------------------------------- ; Script Start #include <Array.au3> #include "libusb0.au3" usb_init() usb_find_busses() usb_find_devices() $busses = usb_get_busses() $bus = DllStructCreate("ptr;ptr;char[512];ptr;ULONG;ptr;", $busses[0]) MsgBox(0, "Busses Pointer", $busses[0]) $next = DllStructGetPtr($bus, 1) MsgBox(0, "Next Pointer", $next) $previous = DllStructGetPtr($bus, 2) MsgBox(0, "Previous Pointer", $previous) $path = DllStructGetData($bus, 3) MsgBox(0, "Path", $path) $devices = DllStructGetPtr($bus, 4) MsgBox(0, "Devices Pointer", $devices) $location = DllStructGetData($bus, 5) MsgBox(0, "Location", $location) $root_dev = DllStructGetPtr($bus, 6) MsgBox(0, "Root Device Pointer", $root_dev) $dev = $devices MsgBox(0, "Device Pointer", $dev) $dev_handle = usb_open($dev) MsgBox(0, "Device Handle", $dev_handle) $closed = usb_close($dev) MsgBox(0, "Device Closed", $closed) ;_ArrayDisplay($busses)

As I am testing it but I cant seem to get the usb_open to work and I dont have a clue how to convert the code I showed at the top of the post.

I have found relevant documentation here:

http://libusb.sourceforge.net/doc/

And I got the information about the structure of the STRUCT's from libusb.h, I beleive that the more relevant ones are:

struct usb_device { struct usb_device *next, *prev; char filename[LIBUSB_PATH_MAX]; struct usb_bus *bus; struct usb_device_descriptor descriptor; struct usb_config_descriptor *config; void *dev;      /* Darwin support */ unsigned char devnum; unsigned char num_children; struct usb_device **children; }; struct usb_bus { struct usb_bus *next, *prev; char dirname[LIBUSB_PATH_MAX]; struct usb_device *devices; unsigned long location; struct usb_device *root_dev; };

Here is a link to the DLL:

http://sourceforge.net/projects/libusb-w...in32-device-bin-0.1.12.2.tar.gz/download

And a link to the src (libusb.h):

http://sourceforge.net/projects/libusb-w...ibusb-win32-src-0.1.12.2.tar.gz/download

Any help or information towards my goal is appreciated.

Thanks,

Craig.

Edited by FaT3oYCG

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

  • 1 month later...
Posted

Hi, sorry I didn't pick up on this earlier, I went away to try and fix it on my own and did not realise the readability issues and since got distracted.

I currently have the functions for initialising the lib and finding the busses and devices sorted (hopefully) they seem to function as described.

To put my original problem in a different way, there is a simple example provided for the lib in C which I was attempting to convert but hit a road block when it came to the for loop.

Here is the example in C:

http://libusb.sourceforge.net/doc/examples-code.html

Here are the relevant structs from the usb.h file:

struct usb_device {
 struct usb_device *next, *prev;

 char filename[LIBUSB_PATH_MAX];

 struct usb_bus *bus;

 struct usb_device_descriptor descriptor;
 struct usb_config_descriptor *config;

 void *dev;     /* Darwin support */

 unsigned char devnum;

 unsigned char num_children;
 struct usb_device **children;
};

struct usb_bus {
 struct usb_bus *next, *prev;

 char dirname[LIBUSB_PATH_MAX];

 struct usb_device *devices;
 unsigned long location;

 struct usb_device *root_dev;
};

Some functions I made for the libusb0.au3:

Func usb_init()
    DllCall($libusb0, "none", "usb_init")
EndFunc ;==>usb_init

Func usb_find_busses()
    $retval = DllCall($libusb0, "int", "usb_find_busses")
    Return $retval
EndFunc ;==>usb_find_busses

Func usb_find_devices()
    $retval = DllCall($libusb0, "int", "usb_find_devices")
    Return $retval
EndFunc ;==>usb_find_devices

My test:

$libusb0 = DllOpen("libusb0.DLL")

#include "libusb0.au3"

usb_init()
usb_find_busses()
usb_find_devices()

Which is all fine and dandy bit it doesn't do anything at the moment, looking at the documentation I am finding it hard to see how I would use the usb_get_busses() function as it seems to return a struct or the data is placed into one by reference somehow.

Again here is the documentation:

http://libusb.sourceforge.net/doc/functions.html

and the usb_get_busses() page:

http://libusb.sourceforge.net/doc/function.usbgetbusses.html

usb_get_busses

Name

usb_get_busses -- Return the list of USB busses found<a name="AEN139">

Description

struct usb_bus *usb_get_busses(void);

usb_get_busses simply returns the value of the global variable usb_busses. This was implemented for those languages that support C calling convention and can use shared libraries, but don't support C global variables (like Delphi).

Some help with this would be appreciated a lot.

Thanks,

Craig.

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Posted

Anyone got any ideas? I am actively working on this again.

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

Posted

Well determination and lots more research seem to have eventually prospered, I have found that I can use a pointer as the second argument to the DllStructCreate() function.

This gives me this at the moment:

#include <Array.au3>

$libusb0 = DllOpen("libusb0.DLL")

#include "libusb0.au3"

usb_init()
usb_find_busses()
usb_find_devices()

$busses = usb_get_busses()

$usb_bus = DllStructCreate("ptr;ptr;char[512];ptr;ulong;ptr", $busses[0])

MsgBox(0, "ugb", IsDllStruct($usb_bus))
MsgBox(0, "ugb", DllStructGetData($usb_bus, 3))

Which is working fine.

I hope to develop this into a UDF for use in more cases but I believe that I will be able to progress and provide some examples eventually.

Thanks,

Craig.

Interpreters have great power!Although they live in the shadow of compiled programming languages an interpreter can do anything that a compiled language can do, you just have to code it right.

  • 11 months later...
  • 2 months later...
Posted

Hi,

could you please provide the source of your usb_get_busses() function?

And maybe some info how you go on from here?

How to loop through usb DEVICES, OPEN devices, ...?

Thanks!

  • 1 year later...
  • Moderators
Posted

Selevo, we discourage necroing old posts, especially when the member has not been active in 2 years. AutoIt has grown and changed a lot in two years; what may have worked in 2010 may not work the same today. If you are attempting a specific project, by all means feel free to start a new topic and post your code; we'll do our best to help :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

  • 9 months later...
Posted

Hi,

I need help to make a script which recognize PID and VID device and connect this device.

i used libusb0 but i can't find the device connected and other informations.

 

This is my code :

 can you copy and paste it to understand my problem,?..

$libusb0 = DllOpen("libusb0.DLL") 


hotkeyset("{Esc}","Terminate")
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate


 Func usb_init()
 DllCall ($libusb0, "none", "usb_init") 
 EndFunc 
 
 Func usb_find_busses() 
 $retval = DllCall ($libusb0, "int", "usb_find_busses") 
 Return $retval 
 EndFunc 
 
  Func usb_device()
 $retval = DllCall ($libusb0, "Ptr", "usb_device") 
 Return $retval 
 EndFunc 
 
 Func usb_find_devices() 
 $retval = DllCall ($libusb0, "Ptr", "usb_find_devices") 
 Return $retval
 EndFunc 
 
 Func usb_get_busses() 
 $retval = DllCall ($libusb0, "ptr", "usb_get_busses")
 Return $retval 
 EndFunc 
 
 
 Func usb_open($devicePointer) 
 $retval = DllCall ($libusb0, "HWnd", "usb_open", "Ptr", $devicePointer) 
 Return $retval 
 EndFunc
  

 Func usb_close($devicePointer) 
 $retval = DllCall ($libusb0, "int", "usb_close", "ptr", $devicePointer)
 Return $retval
 EndFunc 


#include <Array.au3> 


usb_init() 
$findbus = usb_find_busses() 
$busses = usb_get_busses() 
$find = usb_find_devices() 



;*******************find busses*********************************************



$usb_find_busses = DllStructCreate("Int", $findbus[0]) 
$fbus= DllStructGetptr($usb_find_busses,1)
If($fbus=0x00000001) then
ConsoleWrite("Busses found  "& $fbus & @CRLF)
Else
ConsoleWrite("Busses Not found ...  "& $fbus & @CRLF)
EndIf


;*******************get busses*********************************************


$usb_get_busses = DllStructCreate("ptr;ptr;char[512];ptr;ULONG;ptr;", $busses[0]) 

$next = DllStructGetPtr($usb_get_busses, 1) 
MsgBox(0, "Next Pointer", $next)

$previous = DllStructGetPtr($usb_get_busses, 2) 
MsgBox(0, "Previous Pointer", $previous) 
$path = DllStructGetptr($usb_get_busses, 3) 
MsgBox(0, "Path", $path) 
$devices = DllStructGetPtr($usb_get_busses, 4) 
MsgBox(0, "Devices Pointer", $devices) 
$location = DllStructGetData($usb_get_busses, 5) 
MsgBox(0, "Location", $location) 
$root_dev = DllStructGetPtr($usb_get_busses, 6) 
MsgBox(0, "Root Device Pointer", $root_dev) 

;**********************data devices*********************************************

$usb_find_devices = DllStructCreate("Int",$find[0])
$devi = DllStructGetPtr($usb_find_devices) 
If($devi=0x00000001) then
ConsoleWrite("A device is connected  "& $devi & @CRLF)


; WORK ON IT :::
$id=0x00000001

$d = usb_open($id)
$usb = DllStructCreate("HWnd",$d[0])
$de = DllStructGetPtr($usb) 

ConsoleWrite("data" & $usb)
;*********************************


Else
ConsoleWrite("Not device...  "& @CRLF)
EndIf



;*******************************open / close*****************************************




DllClose("libusb0.DLL")
  • 11 years later...
Posted
On 5/13/2013 at 6:33 AM, jeffSCH said:

Hi,

I need help to make a script which recognize PID and VID device and connect this device.

i used libusb0 but i can't find the device connected and other informations.

 

This is my code :

 can you copy and paste it to understand my problem,?..

$libusb0 = DllOpen("libusb0.DLL") 


hotkeyset("{Esc}","Terminate")
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate


 Func usb_init()
 DllCall ($libusb0, "none", "usb_init") 
 EndFunc 
 
 Func usb_find_busses() 
 $retval = DllCall ($libusb0, "int", "usb_find_busses") 
 Return $retval 
 EndFunc 
 
  Func usb_device()
 $retval = DllCall ($libusb0, "Ptr", "usb_device") 
 Return $retval 
 EndFunc 
 
 Func usb_find_devices() 
 $retval = DllCall ($libusb0, "Ptr", "usb_find_devices") 
 Return $retval
 EndFunc 
 
 Func usb_get_busses() 
 $retval = DllCall ($libusb0, "ptr", "usb_get_busses")
 Return $retval 
 EndFunc 
 
 
 Func usb_open($devicePointer) 
 $retval = DllCall ($libusb0, "HWnd", "usb_open", "Ptr", $devicePointer) 
 Return $retval 
 EndFunc
  

 Func usb_close($devicePointer) 
 $retval = DllCall ($libusb0, "int", "usb_close", "ptr", $devicePointer)
 Return $retval
 EndFunc 


#include <Array.au3> 


usb_init() 
$findbus = usb_find_busses() 
$busses = usb_get_busses() 
$find = usb_find_devices() 



;*******************find busses*********************************************



$usb_find_busses = DllStructCreate("Int", $findbus[0]) 
$fbus= DllStructGetptr($usb_find_busses,1)
If($fbus=0x00000001) then
ConsoleWrite("Busses found  "& $fbus & @CRLF)
Else
ConsoleWrite("Busses Not found ...  "& $fbus & @CRLF)
EndIf


;*******************get busses*********************************************


$usb_get_busses = DllStructCreate("ptr;ptr;char[512];ptr;ULONG;ptr;", $busses[0]) 

$next = DllStructGetPtr($usb_get_busses, 1) 
MsgBox(0, "Next Pointer", $next)

$previous = DllStructGetPtr($usb_get_busses, 2) 
MsgBox(0, "Previous Pointer", $previous) 
$path = DllStructGetptr($usb_get_busses, 3) 
MsgBox(0, "Path", $path) 
$devices = DllStructGetPtr($usb_get_busses, 4) 
MsgBox(0, "Devices Pointer", $devices) 
$location = DllStructGetData($usb_get_busses, 5) 
MsgBox(0, "Location", $location) 
$root_dev = DllStructGetPtr($usb_get_busses, 6) 
MsgBox(0, "Root Device Pointer", $root_dev) 

;**********************data devices*********************************************

$usb_find_devices = DllStructCreate("Int",$find[0])
$devi = DllStructGetPtr($usb_find_devices) 
If($devi=0x00000001) then
ConsoleWrite("A device is connected  "& $devi & @CRLF)


; WORK ON IT :::
$id=0x00000001

$d = usb_open($id)
$usb = DllStructCreate("HWnd",$d[0])
$de = DllStructGetPtr($usb) 

ConsoleWrite("data" & $usb)
;*********************************


Else
ConsoleWrite("Not device...  "& @CRLF)
EndIf



;*******************************open / close*****************************************




DllClose("libusb0.DLL")

Hello, did you manage to resolve the communication? Could you help me?

  • Moderators
Posted

liro,

The person you are addressing has not been here for nearly 12 years. Start a new thread if you want any help please.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...