Using NI-VISA to detect USB insertion/​removal

Is there a way to use NI-VISA to detect when a USB device has been inserted or removed?
I am currently using Windows API in my LabWindows application to capture the WM_DEVICECHANGE event.  When this event is called, I check to see if the USB devices are still connected to my PC  by using viFindRsrc function.  On Windows XP 32-bit, this approached worked successfully.  On my Windows 7 64-bit system this is no longer working.  After I remove the USB device, the viFindRsrc function is still indicating that the device is connected even though it isn't. 
Also, when a USB device is controlled by a NI-VISA driver, I cannot capture the Windows DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events.  I am able to see these events for other USB devices that are not controlled by a NI-VISA driver.
Solved!
Go to Solution.

I solved the issue.
The behavior of the NI-VISA driver requires that you register to receive Windows notifications. The other USB devices that weren't controlled by a NI-VISA driver didn't require me to register to receive the DBT_DEVICEARRIVAL and DBT_DEVICEREMOVECOMPLETE events.  I received them by default...
Here is the code to register USB events
Here is the code where I register the USB events:
DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
intptr_t postHandle = 0;
/* Windows HWND */
HWND hWnd = 0;
long long unsigned int hWndVal = 0;
/* Get HWND of LabWindows\CVI panel */
GetPanelAttribute(panelHandle,ATTR_SYSTEM_WINDOW_H​ANDLE,&hWndVal);
hWnd = (HWND)hWndVal;
* USB Raw Device
* Device Interface Class GUID = {a5dcbf10-6530-11d2-901f-00c04fb951ed}
GUID_CLASS_USB_DEVICE.Data1 = 0xA5DCBF10L;
GUID_CLASS_USB_DEVICE.Data2 = 0x6530;
GUID_CLASS_USB_DEVICE.Data3 = 0x11D2;
GUID_CLASS_USB_DEVICE.Data4[0] = 0x90;
GUID_CLASS_USB_DEVICE.Data4[1] = 0x1F;
GUID_CLASS_USB_DEVICE.Data4[2] = 0x00;
GUID_CLASS_USB_DEVICE.Data4[3] = 0xC0;
GUID_CLASS_USB_DEVICE.Data4[4] = 0x4F;
GUID_CLASS_USB_DEVICE.Data4[5] = 0xB9;
GUID_CLASS_USB_DEVICE.Data4[6] = 0x51;
GUID_CLASS_USB_DEVICE.Data4[7] = 0xED;
NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
NotificationFilter.dbcc_classguid = GUID_CLASS_USB_DEVICE;
* Installs a callback function for WM_DEVICECHANGE Windows message posted
* or sent to a LabWindows/CVI panel.
InstallWinMsgCallback (panelHandle, WM_DEVICECHANGE,
WindowsDeviceDetection, VAL_MODE_INTERCEPT, NULL, &postHandle);
* Register device notification for USB Raw Device interface class GUID
RegisterDeviceNotification(hWnd, &NotificationFilter,
DEVICE_NOTIFY_WINDOW_HANDLE);
Here is the code that responds:
static int CVICALLBACK WindowsDeviceDetection (int panelHandle, int message,
unsigned int* wParam, unsigned int* lParam, void* callbackData)
PDEV_BROADCAST_HDR lpdb = (PDEV_BROADCAST_HDR)lParam;
switch (message)
/* Received Windows WM_DEVICECHANGE message */
case WM_DEVICECHANGE:
switch (*wParam)
* Received Windows device-change event "DBT_DEVNODES_CHANGED".
* Device has been added or removed from the system.
case DBT_DEVNODES_CHANGED:
printf("[%s] DBT_DEVNODES_CHANGED\n",TimeStr());
break;
* Received Windows device-change event "DBT_DEVICEARRIVAL".
case DBT_DEVICEARRIVAL:
printf("[%s] DBT_DEVICEARRIVAL\n",TimeStr());
break;
* Received Windows device-change event "DBT_DEVICEREMOVECOMPLETE".
case DBT_DEVICEREMOVECOMPLETE:
printf("[%s] DBT_DEVICEREMOVECOMPLETE\n",TimeStr());
break;
default:
break;
return 0;

Similar Messages

  • Communicating USB using Labview VISA

    I have a USB RAW device that I am trying to communicate with using labview VISA. I have had success with setting up the driver and I am able to get information from the device such as serial number, etc. When I try to use the VISA read and write commands, I have no success getting the information I want. The commands are simple: R SP<CR><LF> is a read set point command. The only thing I do get back for every command I try, is a 2 byte message "01 60"hex.
    If you have any suggestions, I would appreciate it, thanks!
    [email protected]

    Hello Chris, I do not receive any errors and yes, I am including the termination characters in the string.
    Here is what I get when I use a USB port monitor when I send out this string.
    Thanks!!
    [94] URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER (SUCCESS/0x00000000) 20101119150318.131 (+0)
    Pipe handle: 0x87696D6C
    Transfer flags: 0x00000002 (USBD_SHORT_TRANSFER_OUT, USBD_SHORT_TRANSFER_OK)
    Transfer buffer MDL: 0x88C47208
    Transfer buffer length: 6
    Bytes transferred
    0x0000: 52 20 53 50 0D 0A (R SP.. )
    [94] URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER (SUCCESS/0x00000000) 20101119150318.147 (+16)
    IRP status: 0x00000000 (STATUS_SUCCESS)
    Pipe handle: 0x87696D6C
    Transfer flags: 0x00000002 (USBD_SHORT_TRANSFER_OUT, USBD_SHORT_TRANSFER_OK)
    Transfer buffer MDL: 0x88C47208

  • HT4623 The SIM card inserted in this iPhone does not appear to be supported. Only compatible SIM cards from a supported Carrier may be used to activate iPhone. Please insert the SIM card that came with your iPhone or visit a supported Carrier's store to r

    The SIM card inserted in this iPhone does not appear to be supported.
    Only compatible SIM cards from a supported Carrier may be used to activate iPhone. Please insert the SIM card that came with your iPhone or visit a supported Carrier's store to receive a replacement SIM card.

    I got the same message.
    I bought an iPhone 5 at full retail price from an AT&T store. I requested the phone to be unlocked through their unlock portal. The AT&T unlock system asked for the IMEI number, a copy of my receipt showing that I bougth the phone at "No Commitment" price. A few hours later I received a message from AT&T stating that the unlock request was approved. I then followed the instructions to back up the phone and restore it through Itunes. The phone activates normally with the AT&T SIM card. But when I insert my VODAFONE SIM I get the massage "THE SIM CARD... etc.
    I tried again to back up & restore the phone 3 or 4 times, no success. I have also allowed 24 hours for the unlock process to complete. Still no luck.
    I have checked again on the AT&T Unlock Status portal and it shows "Unlock approved".
    Where is the issue here? Do I have to call Apple or return the phone to AT&T and get the unlocked phone through the Apple Store?
    Thanks for any help on this.

  • TS4148 The SIM card inserted in this iPhone does not appear to be supported. Only compatible SIM cards from a supported Carrier may be used to activate iPhone. Please insert the SIM card that came with your iPhone or visit a supported Carrier's store to r

    The SIM card inserted in this iPhone does
    not appear to be supported.
    Only compatible SIM cards from a supported Carrier may be used
    to activate iPhone. Please insert the SIM card that came with your
    iPhone or visit a supported Carrier's store to receive a
    replacement SIM card.

    It appears that you have an iPhone that is locked to a carrier other than the one you were using. Now that you have tried to update the iOS, it has relocked. That is what happens if you are using a phone that has been hacked to unlock. You have also forfeited support from Apple and from this forum.

  • My mac book air has a virus which is creating a lot of issues...how do i get rid of it? is there a free software to detect it and remove it?

    my mac book air has a virus which is creating a lot of issues...how do i get rid of it? is there a free software to detect it and remove it?

    There is no need to download anything to solve this problem.
    You may have installed one or more of the common types of ad-injection malware. Follow the instructions on this Apple Support page to remove it. It's been reported that some variants of the "VSearch" malware block access to the page. If that happens, start in safe mode by holding down the shift key at the startup chime, then try again.
    Back up all data before making any changes.
    One of the steps in the article is to remove malicious Safari extensions. Do the equivalent in the Chrome and Firefox browsers, if you use either of those. If Safari crashes on launch, skip that step and come back to it after you've done everything else.
    If you don't find any of the files or extensions listed, or if removing them doesn't stop the ad injection, ask for further instructions.
    Make sure you don't repeat the mistake that led you to install the malware. It may have come from an Internet cesspit such as "Softonic" or "CNET Download." Never visit either of those sites again. You might also have downloaded it from an ad in a page on some other site. The ad would probably have included a large green button labeled "Download" or "Download Now" in white letters. The button is designed to confuse people who intend to download something else on the same page. If you ever download a file that isn't obviously what you expected, delete it immediately.
    Malware is also found on websites that traffic in pirated content such as video. If you, or anyone else who uses the computer, visit such sites and follow prompts to install software, you can expect more of the same, and worse, to follow. Never install any software that you downloaded from a bittorrent, or that was downloaded by someone else from an unknown source.
    In the Security & Privacy pane of System Preferences, select the General tab. The radio button marked Anywhere  should not be selected. If it is, click the lock icon to unlock the settings, then select one of the other buttons. After that, don't ignore a warning that you are about to run or install an application from an unknown developer.
    Still in System Preferences, open the App Store or Software Update pane and check the box marked
              Install system data files and security updates (OS X 10.10 or later)
    or
              Download updates automatically (OS X 10.9 or earlier)
    if it's not already checked.

  • I own a iPhone 2G Today  He underwent updated Software He gave me this message "The SIM card inserted in this iPhone does not appear to be supported. Only compatible SIM cards from a supported Carrier may be used to activate iPhone. Please insert the SIM

    I own a iPhone 2G Today
    He underwent updated Software
    He gave me this message
    "The SIM card inserted in this iPhone does not appear to be supported.
    Only compatible SIM cards from a supported Carrier may be used to activate iPhone. Please insert the SIM card that came with your iPhone or visit a supported Carrier's store to receive a replacement SIM card.
    I did not know what to do??

    Follow this article: iPhone: Troubleshooting No Service or No SIM
    Symptoms
    In certain situations, iPhone may present one of the following symptoms:
    "Invalid SIM" or "No SIM Card installed" alert appears intermittently.
    Status bar displays "No SIM" when a SIM card is installed.
    Resolution
    If you encounter any of the above symptoms on your iPhone, try these steps to attempt to resolve the issue:
    Update your iPhone to the latest version of iOS.
    Toggle Airplane mode On and Off.
    Try turning iPhone off and then on again.
    Check for a carrier settings update. Tap Settings > General > About. If an update is available, a prompt will appear.
    Remove the SIM Card and verify that it is a valid, carrier-manufactured SIM. Also verify that it is not damaged, worn, or modified. Then reinsert it.
    Restore the iPhone.
    If you still are unable to resolve this issue, contact Apple support for further assistance.

  • HP PAVILION G6-Not able to detect USB FLASH DEVICES.ERROR: NO DRIVERS DETECTED

    HI i have one year old HP pavilion g6 2005AX model with AMD processor.rEcently iam facing a issue with USB drivers.Any new flash drives which i havent used befre are not detectable by my system.It is throwing a error as no drivers detected.What should i do?Iam not able get the driver updates anywhere.

    Samvaram,
    Do a hard reset.
    Turn the computer off.
    Remove the power cable and the battery.
    Hold down the power button for 15 sec while booth power sources are removed.
    This should reset the hardware in the computer.
    As you turn it back on tap the F10 key. This will load BIOS setup utility.
    Press F9 to load defaults.
    Press F10 to save and exit.
    When the computer boots back up, check to see if everything is working.
    Open up command prompt and run the following command SFC /scannow.
    This will scan the system files and correct any errors that it can.
    Here is a link to command prompt.
    When you go to open command prompt, right click and run as administrator.
    What is the device that you are connecting?
    What version of windows are you using?
    Do you have any other devices connected when trying to connect the new device?
    Let me know how everything goes.

  • I bought an iTunes gift card, reedemed it, and when i try to buy a game it doesn't let me use my credits, but instead I have to buy it using my Visa card?

    I bought an iTunes gift card, reedemed it, and when i try to buy a game it doesn't let me use my credits, but instead I have to buy it using my Visa card?

    What exactly do you see when trying to buy a game, what messages do you get on-screen ?
    If it's an account that you've just created then unless the instructions on this page are followed when creating an account : Create an iTunes Store, App Store, or iBooks Store account without a credit card or other payment method
    then credit card details will need to be entered before the account can be used to download any item from the store. You should be able to remove the card after entering its details.
    If you are getting a prompt to review the account then you could see if this post by mountaingoatgirl lets you do so without needing to enter credit card details : https://discussions.apple.com/message/24303054#24303054

  • VISA Read over USB Problem: After a while the xBFFF0015 Timeout Error occurred

    Hi,
    I have trouble using labview with my non-NI USB device:
    The device is an analog input DAQ board. I was able to setup communication with the board using a VISA driver specifically created for this board and direct FW calls using the product's firmware specification provided by the manufacturer.
    This method has been working pretty good so far, but when I try to get large amount of data (64k samples @100ksps), the VISA Read returns the 'VISA: (Hex 0xBFFF0015) Timeout expired before operation completed.' error.
    Please see the attached screenshot of the block diagram for details.
    First, an 'analog input scan start' command is sent to the DAQ device, and then the vi tries to read all collected data from the device, once the right amount of data retrieved, or no more data is available the data collecting process (the while loop) ends and an 'analog input scan stop' command is sent to the DAQ device.
    The data collection starts with no problem, but after a while, in loop# 400, the VISA Read hangs and then returns the error mentioned above.
    I tried to increase the time out value, but it didn't help, the error occurred after the same number of loops, the VISA Read got hosed and the error occurred after the longer timeout expired.
    I also tried to add some delays in the loop, but it didn't help either.
    I am not sure what do I miss here and I would highly appreciate if anyone could give me some guidance how to solve this issue.
    Thanks,
    John
    Attachments:
    usb-read.png ‏18 KB

    I just wanted to specify that this is not an NI board avoiding to make people think this is a hardware issue. And I think that the rest of the code is irrelevant in this case.
    I believe that I don't use the VISA functions correctly. I assumed that someone who used these functions before would be able to point out the obvious steps missing in the data collecting process using the VISA functions.

  • Problems with asynchronous visa read with USB to serial port adapter

    I have an application that sends and recieves data from a power supply and on most computers (desktop PCs), the application runs fine. I found that on at least one computer, using a Keyspan Tripp Lite USB to RS232 adapter, in one out of 25 queries, I wasn't getting the whole reply back from the instrument. After some debugging I found out if I switch the VISA write and read calls from synchronous to asynchronous I don't see the error any more. Is there a way to disable asynchronous mode for that computer? I'd rather not have to find all the VISA write calls in my application and update each one just to support that computer.
    CLD (2014)

    Try playing with the Tx ACK Advance setting on that port first.  (From the Keystone config utility)  You might also look into the Rx FIFO buffer settings (16 is a short default buffer)
    There is no (Easy) way to universally disable Async .   VISA Async tranfers MAY complete synchronously anyhow (It throws a warning when that happens)  So if Keystone settings do not help you might want to swap out to a FTDI chip enabled USB - serial device.
    Jeff

  • Detecting slow inserts

    We have an application that does hundreds of inserts per second to a specific table.
    Naturally we are worried about performance there.
    Is there a way to detect when insert into the table takes over X seconds? Ideally the time this occured, the insert command and how long it took will be written to another table, so we can later analyze the results.
    Note that we don't want to do extra inserts just for testing how long they will take, we want to monitor the performance of the real application inserts.
    Is it possible at all? Does Oracle "know" how long the insert took?

    One simple approach is to monitor wait events on relevant segments - your table and its indexes. So using Statspack you can identify (in a 15 minute period, for example) whether there are any buffer busy waits, row lock waits etc, and if so, how long they took. If you have the level right (7, I think) you can also see the cumulative cost of specific SQL including inserts (counts, plus elapsed time and cpu if TIMED_STATISTICS are switched on).
    Statspack generally reports the top 5 or 10; you can easily modify that if you like, but if this insert isn't in the top 10, you're probably not interested in tuning it....
    HTH
    Regards Nigel

  • I need an economical product to insert/remove pages and convert PDF to PDF/A-1a

    I need an economical product (under $100) to insert/remove pages and convert PDF to PDF/A-1a (or, if it can create PDF/A-1a directly from my scanner, that's good too). There's something for $50 but it only supports PDF/A-1b. Any suggestions?

    As others point out, Acrobat is essential though a bit expensive. There are some very economical (i.e. free) tools that are extremely helpful in  properly tagging a PDF.
    - PDF Accessibility Checker (PAC) 1.3 from the Swiss Foundation Access for All validates the PDF for WCAG 2.0 compliance (to the extent that validation can be automated). It is far more thorough than the feeble accessibility checker that comes with Acrobat, http://www.access-for-all.ch/en/pdf-lab/pdf-accessibility-checker-pac/dl132.html.
    - PAC 1.3's successor, PAC 2.0 performs the same job for ISO 14289 compliance, http://www.access-for-all.ch/en/pdf-lab/pdf-accessibility-checker-pac/downloading-pac.html
    - PDFgoHTML from Callas Software provides a convenient screen-reader view of the document using an Acrobat plug-in, http://www.callassoftware.com/callas/doku.php/en:download. Both PACs also provide screen-reader views, but it is handy to have an Acrobat plug-in that provides the view in a couple of clicks.

  • To detect USB webcam

    Hi, I am trying to detect USB webcam using NI Vision Assistant but its not works ! I already installed requisite drivers for it though its not possible to acquire images using webcam.

    f your goal is to work with you ltener vision first note that the programs have a cost, in any case you can use them in mode of assessment and expire over a period of time. You can perform image acquisition only drivers from VAS , but for any treatment or handling or VDM VBAI you need , plus VAS . You can download the evaluation software from the following links :
    Módulo NI Vision Development https://lumen.ni.com/nicif/us/evalvisiondevmodule/content.xhtml
    NI Vision Builder para Inspección Automatizada (AI) https://lumen.ni.com/nicif/us/machinevisionbrochure/content.xhtml
    NI Vision Acquisition Software http://joule.ni.com/nidu/cds/view/p/id/3818/lang/en
    In this example, we will create a program in Labview to capture images from a USB camera to your application for further processing using the NI Vision module.
    https://decibel.ni.com/content/docs/DOC-30531
    Atom
    Certified LabVIEW Associate Developer

  • When you open iTunes this message appears. The sim card inserted in this iPhone does not Appear to be supported. Only compatible SIM cards from a supported Carrier may bre used to activate iPhone. Please insert the SIM card That cam with your iPhone or vi

    When you open iTunes this message appears. The sim card inserted in this iPhone does not Appear to be supported. Only compatible SIM cards from a supported Carrier may bre used to activate iPhone. Please insert the SIM card That came with your iPhone or visit a supported Carrier's store to receive a replacement sim card.

    dear sir.
    where i get this replacement sim card.i live in bangladesh.not have support carrier in my coutry..
    so how get..please help me..

  • TS3173 If I installed windows 7 without the USB drive inserted, do I have to start all over again or can I just restart the computer with the USB inserted?

    If I installed windows 7 without the USB drive inserted, do I have to start all over again or can I just restart the computer with the USB inserted?

    Following up:  tried multiple restarts but ended up needing to remove partition an reinstall windows 7. Now if I could only find that Mac disk to install boot camp.........

Maybe you are looking for

  • Removing corrupt environment without losing database data?

    OK, I'm using Berkeley DB 4.3.28, Java API with no transactions or concurrency. We have several environments with multiple databases under them. Occasionally the environment gets corrupted. The original coder didn't understand this had to be coded fo

  • How do i get a refund for black ops zombies on my ipa

    I bought black ops zombies on my ipad mini a while ago for 6.99. I was very excited for this app but when i opened the game everything was white. I would love for you to fix this but also give me a refund somehow through my apple account.

  • Adding a linked logo to Web Gallery?

    Is it possible to add that to the Web Gallery (it will return to the home page), along with the images in the thumbnails? I'm using CS1

  • Not suggesting words as you type?

    All of a sudden when I am texting on my phone it is not suggestiig the words as I type.... Like the suggestion option is off or something. HELP ... it is taking me FOREVER to send a 2 sentence text !!!!

  • Where is the Part Box located?

    I'm trying to print charts from Logic 8, but cannot find the elusive "part box" in order to type in chord symbols, etc. Where is that little bugger?