Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

CWAIPoint SingleRead()

"Sorry that I can't figure this out. How do I just sample a voltage off of channel 0? I have only one string set up in the AIPoint control and have called it 0. I thought that might select channel 0. Anyway, what's wrong with this code?

double voltage;


m_analogInput.SingleRead(CNiVariant(Voltage), CNiVariant(1));


It doesn't seem to work but maybe I don't have my channel string configured correctly from the dialog.


Grant"
Grant M. Johnson
Project Engineer
LECO Corporation
0 Kudos
Message 1 of 3
(3,199 Views)
Grant,

Try the following instead:

CNiVariant voltage;
m_analogInput.SingleRead(voltage, CNiVariant(1));


You can use the CNiVariant voltage almost anywhere you can use the double voltage. If you run across a place where the compiler doesn't accept using voltage, use (double) voltage instead.

When you call CNiVariant(voltage), you are actually creating a CNiVariant and initializing it to the same value that voltage has. This variant is what is getting changed by the SingleRead call, but it is discarded, with your new value, immediately after the SingleRead call returns.

Tony
Software Engineer
Measurement Studio
Message 2 of 3
(3,199 Views)
The code seems alright. Make sure that the correct device is chosen on the property pages in CWAIPoint. Also, if it is a very small voltage, check to make sure that the range is appropriate. Setting the channel string to "0" will sample from channel 0. Also make sure your external wires are hooked up to the right channel (check the documentation for the device for the pinout). If you have MAX(Measurement & Automation Explorer) make sure you can verify a single from there, that will rule out hardware configurations.
Joji
Message 3 of 3
(3,199 Views)