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.

Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

Building resource name?

Solved!
Go to solution

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 

 

 

0 Kudos
Message 1 of 4
(5,518 Views)

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));

 

National Instruments
0 Kudos
Message 2 of 4
(5,511 Views)

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

 

0 Kudos
Message 3 of 4
(5,505 Views)
Solution
Accepted by topic author RogerMont

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

0 Kudos
Message 4 of 4
(5,503 Views)