08-01-2017 09:42 AM
Hello,
I want to send a packet header only once then a body continously through tcp
I used an event structure with first call. But apparently, the tcp connection cuts since it was called only once.
Attached is the program, How do I do it?
Thanks
08-01-2017 09:54 AM
I don't see any loop for the part that you want to send continuously.
08-01-2017 10:00 AM
There is an external while loop, no?
08-01-2017 10:15 AM
1. You are closing the TCP connection every iteration of your loop that runs forever.
2. You have the Event Structure waiting for an event forever after the first iteration, which will block the rest of the code from running (the loop cannot iterate until everything in it has executed).
You might want to look into a State Machine. You can have a state for Initialize where the TCP connection is established, another for Send Header, another for Send Data, and finally one to Close Connection. If the initial connection fails, you can retry. When the connection succeeds, move to the Send Header. Then to the Send Data. You can repeat the Send Data state until the stop button is pressed (which you really need to add) or an error in the connection is detected. From there, go to the Close Connection. If an error was thrown, you can go back to the Initialize to try to reestablish the connection.
08-01-2017 10:44 AM
@idir93 wrote:
There is an external while loop, no?
You're right. There is. I did not see it because it blended in with the background of my browser.
But you are looping everything, including the closing of the port. When it runs again, your timeout value of -1 on the event structure means the code is going to pause forever waiting for a timeout that is set to infinity.
08-02-2017 02:57 AM
Thank you all.
Could you help me more? How can I send data ( continously ) since the event structure pauses?
Regards,
08-02-2017 04:33 AM
@idir93 wrote:
How can I send data ( continously ) since the event structure pauses?
You can't. You really need to rewrite your code. See my post above detailing a state machine that you should implement.
08-02-2017 08:32 AM
Hi,
How could I connect the tcp block to keep the same connection id and error using case structures of the sate machine?
Regards,
08-02-2017 08:55 AM
Connection ID belongs in a shift registers that is wired through all cases.
You only close the connection in the state that is intended to close it.
08-02-2017 09:22 AM
Thanks.
But I don't want to use any loop. I want this to become a VI where the user will use it inside his while loop.