LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

TCP wait on response

I have an instrument on a remote PC. I have TCP server running on that PC. The server can control the instrument and that works. I used NI CVI to create the TCP server and the instrument control interface. The TCP client is on a separate controller PC. The TCP client is a DLL that an application uses to communicate with the remote instrument PC. I used NI CVI for the DLL also. I can get TCP messages to control the instrument. However, I see no way to wait for a response in the client. The client would need to be multithreaded.

 

I would like a function in the DLL to send an operation via ClientTCPWrite to the server. The server would control the instrument and respond via a message back to the client. This would be mostly for error and status. I want the function in the client to return a response to the calling application. The TCP interface uses callbacks, so I am waiting for the server to send a response and initiate a callback in the client. The function would need to wait for a callback (likely on a different thread) and a semiphore or something would inidicate a response from the server. This would finish execution of the client function called by the application. The application would block waiting for the return.

 

I have looked at the NI CVI docemntation. However, I do not understand how to get the TCP callbacks on to a separate thread. Can someone point me to documentation to do this? Just calling a response function in the application has the same issue. I would need to poll for the response and wait (pause) to allow callback processing. There must be a way to used a multithreaded model. Thanks.

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

Hello;

 

There is an example that might help you. You can find it in the LabWindows CVI Example Finder by browsing to Networking>>TCP & UDP>>MultiThreading.cws

0 Kudos
Message 2 of 4
(5,200 Views)

What is Example Finder? I don't have that in my start menu. The NI website example finder does not find the example mentioned when I use the keywords given. Searches on the NI website do not find the example mentioned either. I do not have LabView. I only have CVI. I don't need a UI. The goal is automation.

 

The problem remains that I cannot wait in one thread for a TCP callback from the server in another. I have tried many variation of using  PostDeferredCallToThreadAndWait. The application hangs on it. I have used a new thread pool. I have use a default thread pool. I have used CmtWaitForThreadPoolFunctionCompletion. I have tried adding process system events in a while loop using a safe variable as a semaphore. that hangs. There is no sleep. There is no semaphores.

 

The issue is  that I am not waiting for a function to complete. I am waiting for a message (callback) from the server in the client. Tha process (thread) must be running to get the callback event. My normal understanding of threads is not helping me. I simply want to wait for a response from the server while blocking on a call into my DLL (that is the client). It is a round trip I want. The call into the DLL on one PC will calls into a instrument  on another. I need to get the error or status of the operatation while blocking the originating DLL call. In between is TCP communication.

 

If my answer is in a example I can't find it and the normal help examples assumes I am waiting for a function (like draw or read file) to complete. I tried a functionspinning (while loop) waiting on a safe variable. This hangs the thread. I have deadlock. I can't seemed to get two threads working.

 

The event for the callback is is not similar to function completetion it seems. I am sure this sound simple to you. However, I am new to CVI.

0 Kudos
Message 3 of 4
(5,179 Views)

I found the example finder thanks.

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