NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing a string from TestStand into CVI dll

I'm having a problem to use the control \n (new line) in a string written in TS. When I get it (TS_PropertyGetValString) and display it in CVI it uses the \n as text and not as a new line control.

Any idea?
Thanks
Rafi
0 Kudos
Message 1 of 7
(4,047 Views)
Hi

I didn't have time to check this yet but, just as quick idea: if you have a string like "myString\n" in TestStand, it sounds like the string is actually something like this "myString\\n".

As you may know, to show the character "\" as text in C, the string must be "\\". So, may guess is, that TestStand automatically understands, that you want to include the text "\n" in your string and not a newline.

One option would be to go through the string (acquired with TS_PropertyGetValString) in CVI and to replace all "\\n" with "\n".

Hope this helps?

Best regards,
Aleksi Sandqvist
0 Kudos
Message 2 of 7
(4,047 Views)
It reacts the same whether it is /n or //n. In both cases I see it as text. I reformated the result (sprintf(buf,"%s", var) and still the same. I look at the string with the debugger and it looks normal. "any text /n more text". When I print it with MessagePopup, the whole text appear. If I write the same text into the MessagePopUp, it will make a new line where the /n is. So, the coclusion is that TS is doing something to the text.

How do I make it perform like normal text?

Thanks
Rafi
0 Kudos
Message 3 of 7
(4,047 Views)
Rafi2003,

When you pass the argument to a C function as one of the C string types, I
think TestStand massages the buffer and replaces \n text with actual newline
characters before handing it off to the DLL function.

However, when you get the string directly from TestStand using the TestStand
API, TestStand simply returns the raw text.

I don't know of a way to have TestStand do the additional translation for
you (there may be a way, I just don't know of it).

The most straightforward solution I think is to write a routine in CVI to
traverse the string and replace the substring "\n" with ASCII 13 and call
this function for each string you expect to contain empbedded newline chars.
An example function, which performs inplace replacement is presented
below:

void ReplaceEmbeddedNewline(char *pszTarget)
{
int i;

i = FindPattern (pszTarget, 0, -1, "\\n", 0, 0);
while (i>0)
{
pszTarget[i] = '\n';
while (pszTarget[i])
{
i++;
pszTarget[i] = pszTarget[i+1];
}
i = FindPattern (pszTarget, 0, -1, "\\n", 0, 0);
}
}

Good luck,

---
Bob
0 Kudos
Message 4 of 7
(4,047 Views)
Rafi -
TestStand only translates the two characters "\n" to a new line when evaluating expressions, but only if you specify the characters "\n" within a literal string in an expression.

So if you specify the following text:
"This is my first line\n second line"

or the following text:
"This is my first line" + "\n" + second line"

for an expression of a parameter to a function in a DLL or for one of the text to display the Message Popup step, the two characters are translated to a newline character before giving over the result.

If you enter two text characters into a string variable, Locals.MyString, TestStand treats this just as text. If you want to enter a new line into a string variable, just use the Ctrl-Enter key
stroke to continue text on the second line.

Scott Richardson
Scott Richardson
https://testeract.com
0 Kudos
Message 5 of 7
(4,046 Views)
Thank you Scott,

It works perfectly, Thank you!

I'm still dismayed by the fact that the string received from TS looks exactly like a string written inside CVI (line1 \n line2), yet, the string from CVI will split the line where the string from TS will not.

RAfi
0 Kudos
Message 6 of 7
(4,046 Views)
Thanks Bob,

Actually, the solution was very simple (too simple). See next response...

Your solution will probably work too although not needed here. I'll save it for future use.

Thanks
Rafi
0 Kudos
Message 7 of 7
(4,046 Views)