Sign in to follow this  
Followers 0
Runner

Help with getting USB insert event

6 posts in this topic

The code below is C++ from msdn's Dev Center here

LRESULT CALLBACK WindowProc(
  HWND hwnd,       // handle to window
  UINT uMsg,       // WM_DEVICECHANGE
  WPARAM wParam,   // device-change event
  LPARAM lParam    // event-specific data
);

I am trying to find simple examples to understand what's going on with the wParam?

Is there any one that could put this in a minimum number of lines of code for AutoIt that can output to either MsgBox or ConsoleWrite values so that I can see what happens when different USB devices are inserted?

I'm trying to understand what the difference is between a USB drive and a USB to serial adaptor when it comes to the Windows Message code?

Thank you

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

If I'm not mistaken then I think that RegisterDeviceNotifications in my signature will help you.

I'm not sure if itworks correctly anymore or not.  I think it doesn't, but still it should help.

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

Jaber,

I had to make two changes:

see line 394  remove brackets around ($ret[0] = Null)    to   $ret[0] = Null

and line 404  changed Null to 'Null'

Does that make any sense to you? If others have run it before why was this not found before? I'm on a Win7 Pro 32-bit OS.

I'll have time later to play with it. By the way if this is what a simple example is then I'm in trouble :

I hoping that I will be able to pull out lines until I have something smaller. At this point I'm not worried about error checking and other stuff.

Thank you for your reply

Share this post


Link to post
Share on other sites

Jaber, many thanks. :thumbsup:

I finally got time to go through it. I just hope it's not a crime to butcher your work. I was able to whittle it down to just enough lines so that now when I plug a usb device in it runs the func "Find_Arduino". Which is exactly what I was trying to get. It even detects my usb-to-serial adapter.

Global $hWnd = GUICreate("")
Global Const $WM_DEVICECHANGE = 0x0219
GUIRegisterMsg($WM_DEVICECHANGE, "Find_Arduino")

While 1
    Sleep(100)
WEnd

Func Find_Arduino()
    ToolTip("Com3", 20, 20)
EndFunc ;==>MY_WM_DEVICECHANGE

The next step will be to get info from device manager>ports. Any ideas?

Cheers

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

lulz, you didn't need my code at all in that case.

Now that I think about it, I didn't read your post well enough to understand.  My apologies.

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Oh, yes I did.

It was a manageable size that I could go through and see results.

I find it difficult starting from scratch. It's easier to cut away lines of code until output doesn't work or I get errors.

Edit: Of course it look easy now that it works.

Edited by Runner

Share this post


Link to post
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
Sign in to follow this  
Followers 0