PALABIYIK Posted July 14, 2010 Report Share Posted July 14, 2010 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 Quote Link to comment
ned Posted July 14, 2010 Report Share Posted July 14, 2010 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. 1 Quote Link to comment
PALABIYIK Posted July 15, 2010 Author Report Share Posted July 15, 2010 Thank you for you response. You were right. After making the changes you suggested, I managed to get the code working! Cheers! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.