Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

What's the easiest way to control instruments out of Visual C++?

I have Measurement Studio 6.0 and I'm anxious to know the easiest way to control my instruments from within C++. I know that VISA is an option and that IVI drivers play a part. I know that CW tools can be imported as well but that seems to have a lot of overhead. All my boards are NI PXI boards and they show up under MAX 2.1 just fine. If I use a CW tool like CWAO and try and configure the instrument I get the following:
-------------------------------------------------------
Error in:
"Configuring Channels"

NI-DAQ DLL could not be called due to an inerface error.
-------------------------------------------------------

I hear rumors about instrument driver classes available in MS 6.0. I can't
find them. I would love to just have an object of my PXI-6704 card and just make calls to it's functions like in CVI. Am I out of luck here? Any guidance is appreciated.

Thanks for all your help so far,

Grant
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 1 of 15
(5,286 Views)
Grant,

Your PXI card should be programmed through the NI-DAQ driver that came with it, not through VISA and definitely not with IVI. So the way you were programming it (with the CWAO control) seems correct since the CWAO control generates waveforms on one or more analog output channels on a data acquisition device and it communicates with NI-DAQ. You can also program your PXI card by calling the NI-DAQ driver directly through the C API that comes with this driver.
I'm not sure why you are getting the error you mentioned. It seems like the NI-DAQ DLL cannot be loaded. National Instruments has a knowledgebase on a similar error and it includes a patch to fix it.
I would recommend you run the patch on your system. It will install NI-PAL 1.5 (you probably
have NI-PAL 1.4.x) and then try again.

I am attaching this patch for you to try. Please let me know if this works for you.

Azucena Perez
Product Support Engineer
National Instruments
Message 2 of 15
(5,286 Views)
The patch fixed it Azucena. Thanks. Now I just have to start trying functions and seeing what they do. I tried the "CString = instrument.GetDeviceName();" function and it worked great.

I get nervous when I can't do the basic things. I just want to put 5V on a channel and control some digital ports. Do I really need to use .Configure() and .Start()? Can I just output a number/voltage and let my channel settings on the property sheet do the rest? I'd appreciate a tip as to which functions I should focus on to just do some basic things. Thanks again.

Grant
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 4 of 15
(5,286 Views)
Grant,
I'm glad to hear that fixed it. If you want to output just one voltage value on one of your channels, you are better off using the CWAOPoint control. The CWAO control is used for waveform generation.
If you use the CWAOPoint control, then it's really easy to send 5V to a channel. Once you configure the device and channel settings on the property sheet, all you need to write is
CWAOPoint.SingleWrite(5.0) //outputs 5V on configured channel.

Just make sure you call CWAOPoint.Reset() before finishing your app in order to leave your device in a known state.

Now, if you want to control digital ports, you need to use the CWDIO control. This control performs single-point updates or reads on the digital lines of a data acquisition device. Yo
u can use the CWDIO control to control the state of a physical device (such as a valve, relay, or LED) or read the current state of a similar device (such as a switch or light gate). You also can use the CWDIO control to generate slow pulses to activate other parts of your system.
So sending a value of 0 to one of the configured dig ports could be as simple as: DIO.SingleWrite(0)

Hope this helps,

Azucena Perez
National Instruments
0 Kudos
Message 5 of 15
(5,286 Views)
Thanks for your help Azucena. I tried the CWAOPoint.SingleWrite(5.0) command and I was told that SingleWrite doesn't take one parameter.

I tried:
COleVariant vOptional((long)DISP_E_PARAMNOTFOUND,
VT_ERROR);
CCWAOPoint.SingleWrite(5.0,vOptional);

and got
can't convert paramter 1 to const struct tagVARIANT &. I feel like I'm out of my league here. I can't seem to get the basics.

Grant
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 6 of 15
(5,286 Views)
You aren't out of your league, it's just some starting pains in programming an ActiveX control. The SingleWrite function is prototyped as:

CCWAOPoint::SingleWrite(VARIANT value, VARIANT Scaled);

The reason you are getting an error is that the 5.0 is not a variant, it's a double value. Pass it as CNiVariant(5.0) and it will work.

The reason this value is a variant in Visual C++ is that it could be an array, double, or int depending on how you use the function. Visual C++ will change the variants to basic C data types where it can, but it can't here so it leaves it as a variant. We give you the CNiVariant class to easily deal with variants in Visual C++. It has constructors for all the basic data types and you
can easily put our Vector and Matrix class in them as well. Just to clarify, here are your steps for creating a DAQ app with Visual C++.

1) Create the application and set it up with the MS AppWizard.

2) Add the DAQ controls you need (CWAI, CWAO, CWAOPoint, etc.)

3) Usually, you will add a DAQ control to your dialog resource. This allows you to use the property pages to setup the DAQ settings (real time saver).

4) Go to ClassWizard and declare a member variable for your DAQ control (i.e. m_AOPoint).

5) Program with the control. In your case,

COleVariant vOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

m_AOPoint.SingleWrite(CNiVariant(5.0), vOptional);


There is documentation on all of the functions and properties of the DAQ ActiveX controls in Visual C++ under Tools->Measurement Studio Reference. The documentation is for Visual Basic, but once you get used to variants, the VB help is usually enough.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 7 of 15
(5,286 Views)
You aren't out of your league, it's just some starting pains in programming an ActiveX control. The SingleWrite function is prototyped as:

CCWAOPoint::SingleWrite(VARIANT value, VARIANT Scaled);

The reason you are getting an error is that the 5.0 is not a variant, it's a double value. Pass it as CNiVariant(5.0) and it will work.

The reason this value is a variant in Visual C++ is that it could be an array, double, or int depending on how you use the function. Visual C++ will change the variants to basic C data types where it can, but it can't here so it leaves it as a variant. We give you the CNiVariant class to easily deal with variants in Visual C++. It has constructors for all the basic data types and you
can easily put our Vector and Matrix class in them as well. Just to clarify, here are your steps for creating a DAQ app with Visual C++.

1) Create the application and set it up with the MS AppWizard.

2) Add the DAQ controls you need (CWAI, CWAO, CWAOPoint, etc.)

3) Usually, you will add a DAQ control to your dialog resource. This allows you to use the property pages to setup the DAQ settings (real time saver).

4) Go to ClassWizard and declare a member variable for your DAQ control (i.e. m_AOPoint).

5) Program with the control. In your case,

COleVariant vOptional((long)DISP_E_PARAMNOTFOUND, VT_ERROR);

m_AOPoint.SingleWrite(CNiVariant(5.0), vOptional);


There is documentation on all of the functions and properties of the DAQ ActiveX controls in Visual C++ under Tools->Measurement Studio Reference. The documentation is for Visual Basic, but once you get used to variants, the VB help is usually enough.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 8 of 15
(5,286 Views)
Grant,
As far as I'm concerned (and from looking at the Measurement Studio Reference) SingleWrite takes only one parameter, but it has to be a Variant. I was looking at Visual Basic code when I wrote down the information I gave you.
I am attaching two VC++ examples that use the CWDIO control and perform a singleWrite on a port. Here is a snippet of code in VC++ to perform a single port write:

COleVariant Port; // we'll set it to point to Port 0
long WriteValue = 0;
.
// write the data to the selected port
m_CWDIO.GetPorts().Item(Port).SingleWrite(COleVariant(WriteValue));

Let me know if you have further questions.

Regards,
Azucena
0 Kudos
Message 9 of 15
(5,286 Views)
Grant,
As far as I'm concerned (and from looking at the Measurement Studio Reference) SingleWrite takes only one parameter, but it has to be a Variant. I was looking at Visual Basic code when I wrote down the information I gave you.
I am attaching two VC++ examples that use the CWDIO control and perform a singleWrite on a port. Here is a snippet of code in VC++ to perform a single port write:

COleVariant Port; // we'll set it to point to Port 0
long WriteValue = 0;
.
// write the data to the selected port
m_CWDIO.GetPorts().Item(Port).SingleWrite(COleVariant(WriteValue));

Let me know if you have further questions.

Regards,
Azucena
0 Kudos
Message 10 of 15
(5,286 Views)
Hey Azucena. The example works great. When I drop the code to read the digital port into my project however I get an "Invald Index" error from this line:

lValue = m_dio1.GetPorts().Item(vIndex).GetValue();

All I did was include the same header files that were in the DIO example and copy in the code from the CDIODlg::OnButtonRead function. Any ideas what could cause an "Invalid Index"?
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 12 of 15
(4,984 Views)