From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.
We appreciate your patience as we improve our online experience.
11-30-2011 05:56 PM
Hi Gang,
It's been a frustrating day.
I'm building an application driver for the PCI-6021 in native C++. I'm using the DAQmx driver inside of it. It appears that the driver needs C-type strings (array of type constant character) for the "counter" specification.
All works well when I create the below and pass that to the function:
char My Counter[10] = "Dev1/ctr0";
But, I need to build the character array by casting and inserting integer variables for the device and counter numbers.
I can build strings that have the right text in them, but I haven't figured out how to cast that into a variable that will work with the command.
I know this is more of a C/C++ question, but I'll really appreciate all help.
Thanks,
Roger
Solved! Go to Solution.
12-01-2011 01:48 PM
When the function help states that it requires a const char[], it is simply letting you know that it needs read-only acces. If you provide it with a char[], then it will make the conversion for you and work just fine. Below is some code I was able to run properly.
char chan[256]; strcpy(chan, "Dev1/ctr0"); chan[8] = '1'; ... DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,chan,"",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
12-01-2011 04:30 PM
Hi,
That doesn't help me.
I've also been able to build a string, inserting a char literal, using the "strcat()" function. The problem is that the device number gets passed in as an integer (this driver must be compatible with existing software). I can implicitly cast that by this code:
int MyIntArg = 1;
char MyChar = MyIntArg;
Then replace the character:
MyCounter = "Devx/ctr0" ;
MyCounter[3] = Mychar;
This compiles without error, but the counter doesn't run. It only runs when character literals are used. So far, I haven't figured out what the issue is. When the function doesn't run, it returns -200220, which seems to be a type exception error.
I appreciate all help.
Roger
12-01-2011 05:03 PM
Eureka!!
I found a workaround.
I create an array of character literals:
char Numbers[9] = {'1','2','3','4','5','6','7','8','9'};
int MyIntArg = 1;
Then replace the character:
MyCounter = "Devx/ctr0" ;
MyCounter[3] = Numbers[MyIntArg -1];
Whew! On to the next problem!
Roger