Jump to content

Help with getting USB insert event


 Share

Go to solution Solved by Runner,

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
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

Link to comment
Share on other sites

  • Solution

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
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...