Jump to content

LibUSB0 usb device


Recommended Posts

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") ;Exit the program by ESC key
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

;**************************************************LIBUSB0 functions*********************************************
 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()
DllCall ($libusb0, "none","usb_device")
 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> 
#include <file.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <Process.au3>


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

Global $bus
Global $c
global $i
Global $a
;*******************find busses*********************************************
$usb_bus = DllStructCreate("ptr;ptr;char[512];ptr;ulong;ptr", $busses[0])
;$usb_bus = DllStructCreate("ptr;ptr;char[512];ptr;ulong;ptr", $bus[0])
MsgBox(0, "ugb", DllStructGetData($usb_bus, 3))
MsgBox(0, "ugb", DllStructGetData($usb_bus, 1))
MsgBox(0, "ugb", DllStructGetData($usb_bus, 2))





    


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


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


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

$next = DllStructGetPtr($usb_get_busses, 1) 
ConsoleWrite("Pointer:"& $next &@CRLF)


$previous = DllStructGetPtr($usb_get_busses, 2)  ;pointer on the bus
ConsoleWrite("Previous Pointer : "& $previous&@CRLF) 
$path = DllStructGetData($usb_get_busses, 3)     ;path of the bus
ConsoleWrite("Path:  "& $path&@CRLF) 
$devices = DllStructGetPtr($usb_get_busses, 4) 
ConsoleWrite( "NextPointer : "& $devices&@CRLF)  ;next ponter
$location = DllStructGetData($usb_get_busses, 5) 
ConsoleWrite( "Location:  "& $location &@CRLF) 
$root_dev = DllStructGetPtr($usb_get_busses, 6) 
ConsoleWrite("Root Device Pointer:  "& $root_dev& @CRLF& @CRLF) ;"Root Device Pointer:



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

$usb_find_devices = DllStructCreate("Int",$find[0])
$devi = DllStructGetPtr($usb_find_devices,1) 




If($devi=0x00000001) then ;test if a device was detected
ConsoleWrite("A device is connected:  "& $devi & @CRLF)


;*********************************verify by windows configuration*******************************
send("{LWIN}")
send("{RIGHT}")
send("{UP}")
send("{UP}")
send("{UP}")
send("{ENTER}")
sleep(3000)
send("{DOWN}")
send("{DOWN}")
send("{DOWN}")
send("{DOWN}")
send("{ENTER}")
sleep(2000)

$var = ControlGetText("Propriétés de : M221 Controller","M221 Controller","[CLASS:Edit; INSTANCE:1]") ;search word : M221 controller
ConsoleWrite("Text found: " & $var & @CRLF)
 if $var="M221 Controller:" Then  ;if the word M221 was found
     ConsoleWrite("verify : OK M221 controller detect "& @CRLF)
 EndIf
 
;***
$control = ControlGetHandle("Propriétés de : M221 Controller","M221 Controller","[CLASS:Edit; INSTANCE:1]") ;retrieve handle window
ConsoleWrite("Control handle found: " & $control & @CRLF& @CRLF)


send("{ENTER}") ;close window M221
WinKill("Périphériques et imprimantes","") ;close window
;***********************************************************************************************

$iPID=376
$ff=_ProcessGetName ( $iPID )
ConsoleWrite("PID found: "& $ff & @CRLF)


Else
ConsoleWrite("Not device...  "& @CRLF) ;display if no device was detected

EndIf


$a = usb_device()
ConsoleWrite("usb device: " & $a & @CRLF) ;usb device retrieve by usb_device function
$us=usb_open($a) ;open te device by  usb_device
ConsoleWrite("usb open:" & $us & @CRLF)        





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




DllClose("libusb0.DLL")
Link to comment
Share on other sites

Prob not what you want to hear, but you should be able to collect that information using WMI.

Here's a link to a vbscript that should do it. It doesn't look too hard to convert to AutoIt.

Edited by spudw2k
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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