LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

USB Event

Hello Everybody,

I am attempting to set up events for a change in the USB state. The event fires, but there is no change in the parameters. lParam and wParam are always the same value regardless of an insertion or removal of a usb device. Any suggestions?

 

Here is the Windows API: 

https://msdn.microsoft.com/en-us/library/windows/desktop/aa363480(v=vs.85).aspx

 

#include "windows.h"
#include "Dbt.h"
#include "toolbox.h"
#include <cvirte.h> /* Initialize CVI libraries */
#include <userint.h>
#include <libsupp.h>

int main (int argc, char *argv[]) { if (InitCVIRTE (0, argv, 0) == 0) { return -1; } if ((panelHandle = LoadPanel (0, "PANEL.uir", PANEL)) <= 0) { return -1; } InstallWinMsgCallback (panelHandle, WM_DEVICECHANGE , UsbCallback, VAL_MODE_INTERCEPT, NULL, &postingHandle); RegisterWinMsgCallback(UsbCallback, 0, NULL, 0, &id, 1); /* display the panel and run the UI */ DisplayPanel (panelHandle); RunUserInterface (); RemoveWinMsgCallback(panelHandle, WM_DEVICECHANGE); /* free resources and return */ DiscardPanel (panelHandle); CloseCVIRTE (); return 0; } int CVICALLBACK UsbCallback (int panelHandle, int message, unsigned int* wParam, unsigned int* lParam, void* callbackData) { struct _DEV_BROADCAST_HEADER *DeviceHeader = (struct _DEV_BROADCAST_HEADER *)lParam; unsigned int DeviceType = DeviceHeader->dbcd_devicetype; switch (*wParam) { case DBT_DEVICEARRIVAL:
break; } /* switch */ return 0; } /* UsbCallback */
Message 1 of 3
(3,504 Views)

How are you checking the parameter? I tried setting a breakpoint just inside of the callback and always saw wParam = 0x0007, but setting a breakpoint in the DBT_DEVICEARRIVAL case worked as expected:

Capture.PNG

Maybe you're missing the message you're looking for because CVI is at a breakpoint and isn't processing them. Take that as a guess at an explanation... i'm no expert on windows messages.

 

It may be easier to see what's going on with print statements instead of breakpoints:

 switch (*wParam)
 {
  case DBT_DEVICEARRIVAL:
	  DebugPrintf("Device added\n");
	  break;
   
  case DBT_DEVICEREMOVECOMPLETE:
	  DebugPrintf("Device removed\n");
	  break;
	  
 } /* switch */

Hope this helps!

Trent

 

https://www.linkedin.com/in/trentweaver
0 Kudos
Message 2 of 3
(3,469 Views)

Hi Trent

 

Thanks for the suggestion, I will try that out when I can. I am looking at the parameters via watch expression and breakpoints.

0 Kudos
Message 3 of 3
(3,440 Views)