NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

return string from DLL to test stand

Hai,
I want to return some info in the form of a string buffer from DLL. But I am not sure, how to implment it from test stand.
I am giving the code I have from CVI. I created a DLL and loading the function from test stand. But it only have nummeric/boolean fileds as return values. Is there any way I can do this with std. steps types.
 
------------------------------------------------------------------------------------
char* _stdcall _export Read_SerialPort(int COM_Port)
{
 char data[1000]="Hello";
 char *p;    //pointer to to return information
 p=data;
 
 /* Commented code */

 return p;
 }
-----------------------------------------------------------------------------------
This code works when executed with in CVI, with out any problem.
Any help....
Thanks in advance
0 Kudos
Message 1 of 13
(8,893 Views)

1). Select the "LabWindows/CVI" adaptor from the adaptor drop-down and insert an action step

2). Right-Click on the action step and select "Specify Module..."

3). Under "Module Pathname" select your dll.

4). Under Function Name select your function, ie Read_SerialPort

5). It should pop-up with This function has parameter information. Would you like to use it?". Click YES.

6). It may pop-up with a message stating there is not enough information to determine if the function returns an array or a single item.  Select Pointer to single item and click ok.

7). Fill in the value expressions for port and return string.  Click Ok.

Hope this helps.

Charlie Rodway | Principal Software Engineer | Certified TestStand Architect (CTA)

Computer Controlled Solutions Ltd | NI Silver Alliance Partner | GDevCon#1 Sponsor

0 Kudos
Message 2 of 13
(8,886 Views)

Hai,

Thanks for the reply.

The trouble is I do not have any parameter information in DLL.When I select/load the function from DLL, it pop appears "This function doesn't have parameter information in the DLL. Do you wan to use the code template to specify the function prototype".

Any clues....

 

0 Kudos
Message 3 of 13
(8,884 Views)
I tried to look for any options that can send the parameter information to DLL in CVI. But I couldn't.
I also triedto I create a custom step type that allow me to return string pointer to test stand by editing the default action test step. But I can't see how to add a parameter catagory for a custom test type.
Can any one help me....
Thanks
0 Kudos
Message 4 of 13
(8,881 Views)

You cannot return a string as the return value of a function to TestStand, but you can return a string as a char buffer parameter.

Declare your function as follows. In C, you cannot assign a string to an array, you must use a function like strcpy() to copy the string:

void __declspec(dllexport) Read_SerialPort(char data[])
{
    strcpy(data, "Hello");
}

If you are using CVI 7.1 or greater and TestStand 3.1 or greater, TestStand will get the type information directly from the DLL. Otherwise, you can either create a type library using CVI (see http://digital.ni.com/public.nsf/websearch/BCB57B5F7E0D292486256BFA005DAD92?OpenDocument), or you can just define the parameter types manually in TestStand. For this function, you would declare a String parameter with a type of C String Buffer. Set the buffer size to the largest size string you will return.

Message 5 of 13
(8,871 Views)

Hai,

I did created the function panel with function prototype and created the DLL. But When I loaded the DLL into TestStand I get am message that  "The parameter information for this function could not be read. Return value is of an unsupported type"

Attached is the code I used in CVI....

 
Download All
0 Kudos
Message 6 of 13
(8,848 Views)
The problem is the return value.  TestStand does not support arrays as return values.

Looking at your test code, you will run into more problems.  The value you are returning will go out of scope when the function returns.  CVI will reclaim this memory and assign it to a different function.  What you will see is the string returned by the function will have funny characters in it.  It's better for you to create a buffer and pass it in as a parameter.
----
I am the founder of CnCSoftwareSolutions. When not cleaning up baby drool, I write about test data or work on Vision, a tool for understanding your test data. Visit me at www.cncsoftwaresolutions.com
0 Kudos
Message 7 of 13
(8,827 Views)
Hello, Erik

It works!  I have an other doubt.  Is there any problem with the string definition and its size?  In test stand there is nothing about this, so I suppose that TS strings are as strings in C++ and they are more than just char arrays.  Is there any limitation in the amount of characters that I can copy in the TS string from C (CVI)?

Thanks
Carlos Arcediano del Amo
0 Kudos
Message 8 of 13
(8,665 Views)
I think Test Stand only allows C srting buffers of size upto 1024 characters !!!!
0 Kudos
Message 9 of 13
(8,657 Views)
1024 is just the default. I don't think there is a hard coded limit.
0 Kudos
Message 10 of 13
(8,650 Views)