Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Using the traditional NIDAQ driver in .NET w DAQPad 6508

Can anyone give me some quick advice for using the DAQPad 6508 as DIO in VB.NET? Pretty simple what I am trying to do.... am I declaring the object wrong and using the interface incorrectly? Any help appreciated! Both these simple bits of code cause a "Catastrophic Failure" when it tries to assign or use a port. Smiley Sad
 

Sub IO(ByVal Port As Integer, ByRef Data As Integer, ByVal IO As String)

Dim DIO As New CWDAQControlsLib.CWDIO()

If 0 = StrComp(IO, "I", CompareMethod.Text) Then
'Read port input
DIO.Ports.Item(Port).SingleRead(Data)
ElseIf 0 = StrComp(IO, "O", CompareMethod.Text) Then
'Write to port
DIO.Ports.Item(Port).SingleWrite(Data)
End If

End Sub

Sub PORTCFG(ByVal Port As Integer, ByVal IO As String)

Dim DIO As New CWDAQControlsLib.CWDIO()

If 0 = StrComp(IO, "I", CompareMethod.Text) Then
' assign the port to input
DIO.Ports.Item(Port).Assignment = CWDAQControlsLib.CWDIOAssignments.cwdioInput
ElseIf 0 = StrComp(IO, "O", CompareMethod.Text) Then
' assign the port to putput
DIO.Ports.Item(Port).Assignment = CWDAQControlsLib.CWDIOAssignments.cwdioOutput
End If

End Sub

0 Kudos
Message 1 of 6
(4,460 Views)

Some more details..... Error is as follows :

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in mscorlib.dll
Additional information: Catastrophic failure

I also downloaded a C# .NET DIO example from the support site and tried to run it and I get the same error!!!!

http://zone.ni.com/devzone/conceptd.nsf/webmain/9298A74802718F6386256C8B006244E4

http://sine.ni.com/apps/we/niepd_web_display.display_epd4?p_guid=B45EACE3DEFF56A4E034080020E74861&p_...

0 Kudos
Message 2 of 6
(4,439 Views)
Some more info : It seems the entire control is totally hosed .....
Look at the screen shot (attached) it shows that even the Device properties cannot be read from the ActiveX control.....
 
Any ideas? The DAQPad shows up and works fine in Measurement Explorer.
 
 
0 Kudos
Message 3 of 6
(4,435 Views)

It can be difficult to use Traditional NI-DAQ with Visual Basic .NET. NI-DAQ was not designed to work natively in VB .NET but you can use ActiveX control by using Runtime Callable Wrappers. See this KB for more information.

 

It may be easier to use Visual C++, you can run the examples in the NI-DAQ directory:

C:\Program Files\National Instruments\NI-DAQ\Examples\VisualC, follow the instructions in this KB to add the necessary library files. If this does not work, could you post what version of the NI-DAQ driver you are using as well?

Thanks,

Micaela N
National Instruments
0 Kudos
Message 4 of 6
(4,418 Views)
Hi Micaela
 
Thanks for the reply... In one of my posts on the thread I mentioned I tried the C# .NET code example right off the NI website and get the same error.
 
I am open to trying other things to get it to work but unfortunately I cannot switch to C++ this late in the game and get anywhere....
 
I have to get this NIDAQ working in VB.NET if at all possible. Also I am using Visual Studio .NET 2002
 
Traditional NIDAQ Version is 6.9.2 as seen in Measurement Explorer
 
 
0 Kudos
Message 5 of 6
(4,416 Views)
Just thought I should post an update in the interest of adding a usefull chunk of information to the forum..... Thanks to both Jason N. and Micaela N. from NI for their support. Turns out when I went to use the DAQPad I already had Labview 6.1 Development suite installed on my PC. The traditional NIDAQ driver was 6.9.2 as mentioned. I plugged it in and it was instantly recognized so I thought "OK everything should be good to go". I could configure it from the test panel in Measurement Explorer also just fine
 
The C# example would not work however.
 
Turns out after installing the software from the NIDAQ CD that came with the DAQPad this updated the traditional NIDAQ to version 7.3
 
The C# example then worked fine!
 
So then to make the DAQ work in Visual Basic you have to host the ActiveX control somehow. Using a RCW as mentioned...... However if you do not access the ActiveX properties page for the object and select the device you are using from the drop down list of avaliable interfaces..... you still will not be able to make it work! Details on what happens :
 
When you attemp to use the DAQ it will allow you to read the device name fine but properties such as "Number Of Ports" or "Number Of Pins" always read back as "0" so when you go to read or write to the device and identify a port with an integer value it gives you an error "Invalid Index" because it thinks it has no ports for you to control.
 
So since I had to access the ActiveX properties which I am sure can be done by other means but what seemed easiest is to just do it from a form. However I had no intention of using a form anywhere for doing DAQ I/O operations.
 
So I simply created a blank form to host the object exclusively and dropped the CWDIO ActiveX control into the form. The form allows me to host the ActiveX object and open its properties to select the DAQPAD-6508 so it will work properly.
 
In code I never show the form however. I simply created a new module that has my I/O and Port Config code standalone by itself. The form is called "DAQHOSTFORM" and a variable is created as a new instance of the class in my Module's public declaration space. (See attached)
 
I then can access the ActiveX control through that variable for my various IO needs. And it works!!!!!!!!!! Finally!
0 Kudos
Message 6 of 6
(4,406 Views)