LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Host-RT Target communication lost

I am using the sample under "National Instruments\CVI2015\samples\realtime\ThreadPriorityRT" to control and communicate with the real time target (PXIe 8820, Pharlaps).

 

So the TCP server is on the host, and the RT target runs a client program.

How exactly I can modify the code so that when the host program is somehow shutdown by user, it can restart the host program and continue the communication with the RT target. What I found is, even I write a thread on the RT program that periodically checks the status of connection and once host program is back running, it uses "ConnectToTCPServer" (and successfully connected, judging by the returned status). However, the host program is not able to communicate with the client progrma using the ServerTCPWrite() function. The returned status shows a weird 160.

 

if host program starts first, rt program later (it is running a startup dll, so the rt target is restarted), it does not have any problem. I am trying to do the reverse.

 

any idea?

 

Thanks

 

0 Kudos
Message 1 of 7
(3,672 Views)

Hi LY12345,

 

I have a few questions:

1. What timeout durations are you using?

2. Could you describe how you detect and deal with the lost connection on the host side in more detail?

3. Is there a code associated with the error you're seeing? Could you post the text of the error or the error code?

 

I was able to find this forum post that deals with a similar issue, with some sample code. They tend to use the TCP_DISCONNECT event to detect a lost connection. Let me know what you think:

 

How do I check that the TCP server, the client is connecting to has gone down?

http://forums.ni.com/t5/LabWindows-CVI/How-do-I-check-that-the-TCP-server-the-client-is-connecting-t...

Austin
Staff Software Engineer
NI
0 Kudos
Message 2 of 7
(3,645 Views)

So usually I give a time out of 5s, but would like a shorter one, like 0.5s. 

sorry I can't post the code here, but I can describe it.

 

my code is quite like the link you sent (at the bottom, the last reply). 

 

for your 2nd question, there is some misunderstanding here. My problem is, when the host program is closed (as well as the TCP server), even when the program is back and TCP server is correctly registered, it can't send a command to the real time target computer's TCP client program using the ServerWrite function.  Interestingly, I have the similar code (to the link you provided) on the RT target to periodically check if the status of the host program (TCP server registration) and use the ConnectToTCPServer function and actually there is no error code from the function return. 

 

The only scenario it works, is to leave the host program running and restart the RT target, and when the RT target is running the same ConnectToTCPServer function, the ServerWrite function on the host program can run. 

 

Please let me know what you have in mind.

 

Thanks 

 

0 Kudos
Message 3 of 7
(3,637 Views)

Hi LY12345,

 

By my understanding, the connection is not properly established until the RT target restarts. Is there anything that happens differently when the RT target restarts as opposed to when it's trying to reconnect? Or is the connection apparently establishing but is just unable to send a command after the devices are connected? Could you tell me more about how you are trying to reconnect with the RT target? I'm wondering how are you detecting the connection is broken and how you are trying to reestablish.

 

My main thought whether there is something different about how you are reconnecting and how you are connecting the first time.

Austin
Staff Software Engineer
NI
0 Kudos
Message 4 of 7
(3,621 Views)

So, at start-up of the RT target, the RT program shall run the ConnectToTCPServer() function to establish as an client (This is when the host program's TCP server is properly registered and waiting for the RT program to run this initialization).  Once the host program quits (The TCP server is unregistered), the TCP callback function generates a "DISCONNECT", and the original sample uses a separate integer flag to reflect this as "INVALID TCP CONNECTION". So in the RT target program, I have an asyncrnoized Timer loop running every few seconds to check if the disconnection is posted or not. Once it detects, it shall re-run ConnectToTCPServer(). (Something here I am not quite sure is, the specified TCP callback function is the same. I just worry the function is not discarded properly, and I tried to use DisconnectFromTCPServer() function before I run the ConnectToTCPServer(), but still not working.)  Anyway, from the status return value of the ConnectToTCPServer() I got, it shows connected correctly. 

 

From the TCPIP point of view, I don't see any difference when the RT restart to initialize the TCP IP client program, and the my reconnecting subroutine.  If there is any difference, it should be either the real-time run-time engine, or other system threads initialization, which are not related to the TCP/IP. 

 

I hope this makes the problem clearer to you. 

 

Thanks very much

0 Kudos
Message 5 of 7
(3,617 Views)

Actually I just attached the sample file that NI provided, where I started modifying it. 

 

The question right now is simpler, how can I still keep this sample function well without restarting the RT target, if the host program is closed and opened again. 

 

Thanks

0 Kudos
Message 6 of 7
(3,613 Views)

Hi LY12345,

 

Thanks for the code, it did indeed clarify your questions. The things I would check:

1. Make sure to delete or properly deal with all instances of TCP_INVALID_CONNECTION. In particular, make sure losing the TCP connection doesn't stop the main loop.

2. Try closing the TCP connection before reopening it. You may have to have a short wait before reconnecting to ensure cleanup completes.

 

Could you please post your modified RT code as well? It sounds like you're doing things correctly.

Austin
Staff Software Engineer
NI
0 Kudos
Message 7 of 7
(3,587 Views)