LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Send an initialization packet (header) once then body continuously using TCP

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

0 Kudos
Message 1 of 18
(3,067 Views)

I don't see any loop for the part that you want to send continuously.

0 Kudos
Message 2 of 18
(3,060 Views)

There is an external while loop, no?

 

0 Kudos
Message 3 of 18
(3,056 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 18
(3,047 Views)

@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.

0 Kudos
Message 5 of 18
(3,029 Views)

Thank you all.

Could you help me more? How can I send data ( continously ) since the event structure pauses?

Regards,

0 Kudos
Message 6 of 18
(2,986 Views)

@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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 7 of 18
(2,982 Views)

Hi, 

How could I connect the tcp block to keep the same connection id and error using case structures of the sate machine?

Regards,

0 Kudos
Message 8 of 18
(2,972 Views)

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.

0 Kudos
Message 9 of 18
(2,963 Views)

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.

0 Kudos
Message 10 of 18
(2,958 Views)