Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

Detect Device

I'm using VB6.0 and DaqMX calling the C api functions.

 

Is there a way to detect if the device usb cable is plugged into the computer or not ?  It does load/unload the driver nicely every time ?   

0 Kudos
Message 1 of 8
(8,953 Views)

Hi prginocx,

 

One way to accomplish this is to write a short routine with the DAQmxGetDevSerialNum function. All you have to do is specify the device name and it will try to get the serial number of the device. If it is plugged in, no error will be generated. However, if the device is unplugged, you can expect error -200220. When you plug the device back in, it should reassociate with the driver and change from a white icon (disconnected) in Measurement and Automation Explorer back to a green icon (connected). Hopefully this gives you some ideas.

 

Regards,

Kent

Applications Engineer

0 Kudos
Message 2 of 8
(8,939 Views)

I used this function, but when the power is OFF I get -200220 and when the board ( and my program ) is working, I get -200220 as the return value ?.  What gives ?

 

Private Sub Command2_Click()
Dim lngReturn As Long
Dim strdev As String
Dim lngdat As Long
' -200220 returned when unplugged.

lngReturn = DAQmxGetDevSerialNum(strdev, lngdat)

MsgBox " Device Name =   " & strdev & " Device No. =   " & lngdat & " func returned =   " & lngReturn
End Sub

0 Kudos
Message 3 of 8
(8,935 Views)
Hi prginocx,

I assume that you are defining strdev as your USB device's name. This function should return no errors when the device is populated in Measurement and Automation Explorer. Have you been able to get the serial number of the device using this function?

Regards,
Kent
Applications Engineer
0 Kudos
Message 4 of 8
(8,906 Views)

Nope, like I said, when I called this function it returned the same values, even when the device was working, and even when it was turned OFF.

 

The usb driver does load well and consistently when you power up the board which is nice.  I just want to be able to detect if the driver is present or not...

 

Or really detect the presence of the board any way at all....

0 Kudos
Message 5 of 8
(8,903 Views)

Hi prginocx,

 

What is your device's name? If the piece of code you posted is all you have, I would expect the function to not read the serial number since the device name is not being specified. The name of you device must be given in your strdev variable.

 

Regards,

Kent

Applications Engineer

0 Kudos
Message 6 of 8
(8,892 Views)

I didn't know I needed to give the name.   How do I find out the correct name string to pass in the function ?

 

In fact, how do I find documentation on how to use all these functions ?   What parameters to pass, what I can expect back, how to call, etc...

0 Kudos
Message 7 of 8
(8,887 Views)

Hi prginocx,

 

To get the device name, you can check Measurement and Automation Explorer (MAX) under Devices and Interfaces. The device name should be in parenthesis beside your USB device. I apologize for not referencing this earlier (I thought I put it in the first reply), the C function reference for NI-DAQmx is installed with the driver. If you are using Windows it can be found in the Start Menu under Programs » National Instruments » NI-DAQ.

 

Regards,

Kent

Applications Engineer

0 Kudos
Message 8 of 8
(8,884 Views)