Jump to content

passing 1 d array from Labview dll to c++


Recommended Posts

I have a Labview server application where the data, 1d fixed sized array, is sent to a specific port in my machine through Labview TCP/IP blocks. Now I am trying to pass this 1d array into my c++ code. To this end, I created a client vi and then I converted it into three Labview dlls; initialize, read and close. "Init" initializes the port, "read" supposedly reads the port and write the content of the port to an array called Myarray, and finally "close" closes the connection. I am calling read.dll in a while loop in c++. The read dll is supposed to read the port and return the 1d array at the port. I attached the pictures of server vi, init.vi , read vi and close.vi. When converting read.vi into Labview dll, I defined the output function parameter to be an Array Data Pointer. Labview-created header file for the read vi is attached here.

In order to read the output of the read.dll file in c++, I am using the following code;

int main(int argc, char* argv[])

{

uInt32 a;

double MyArray[8]; //Initialization of array

a=Init(); //Calling the init.dll to initialize the port

int i=0;

while (i<100)

{

Read(a,MyArray,8); //Calling READ.DLL to read the 1d array at the port and write it to Myarray.

std::cout << "The result is" << MyArray[2] << '\n'; \\PRINTING ONE MEMBER ON THE SCREEN to see if I managed to read the 1d array.

i=i+1;

}

Close(a); // Calling close.dll to close the port

return(1);

}

However, I can't see anything on the screen. I did this successfully for a double number. In that application, my server sends a double number, and I read this number with Labview read.dll on the vc++ side just fine. Now, I am trying to do the same with an array with the methodology defined above. I am wondering if there is anyone out there who can help me out with the problem. Thank you so much!!

Kind Regards

post-17567-038010100 1279130001_thumb.jp

post-17567-039900200 1279130013_thumb.jp

post-17567-097090300 1279130026_thumb.jp

post-17567-069536400 1279130185_thumb.jp

Link to comment

You can put all three VIs into a single DLL and call them as different functions in that library.

Your problem is the length parameter in the TCP Read. You only read 64 bytes, which would be sufficient for one double-precision value, but is not enough for an array. You need to prepend either the length of the string, or the number of elements in the array, to the string before you send it. On the receiving end, read that length and use that to determine how many bytes of data you need to read.

Also, check the representation of your array constants; you do not need the conversion to DBL after the typecast.

  • Like 1
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.