From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

tcp state machine trigger

Hello, I am working on some statemachine architecture, I was wondering what the best method of sending states between vis could be. Essentially I would like to send states to be read over TCP as triggers for the various parts of the statemachine in another VI. Basically it would be like the following:

VI1: Statemachine1: Idle->State A->Send Trigger (Trigger1)->Wait for trigger (Trigger2)-> State A or ->End

VI2: Statemachine2: Idle-> State B-> Wait for trigger (Trigger1) -> Send Trigger (Trigger2) -> State B or ->End

 

State A and State B are arbitrary, Trigger1 and Trigger2 I am hoping to be merely state cases sent via TCP. 

0 Kudos
Message 1 of 15
(3,883 Views)

Are your VIs in the same application? If so you can use notifiers or queues. They will require less effort on your part than using TCP. They are also event driven.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 2 of 15
(3,861 Views)

No they are not in the same application, I would have used them if this was the case. 

0 Kudos
Message 3 of 15
(3,856 Views)

my suggestion would be in each application have a tcp loop and a Queued message handler loop. State machine 1 goes to state A, puts a 'send trigger1' message in a queue to its tcp loop. The TCP loop reads this from teh queue then sends this message to application 2, which reads it, stick the message in a queue to the state machine 2 loop to process.

 

By doing this you decouple your tcp logic from your state machine logic. From my experience, it is never good to mix network communication logic in the same loop as your data processing. TCP does some weird things if you aren't getting back to the "TCP Read" function on one end as quick as you are writing on the other end. I tried this once a couple years ago in order to simplify my architecture on a relatively simple and quick program, but it actually ended up taking more time troubleshooting the TCP IP. Now I always keep them separate.

Message 4 of 15
(3,852 Views)

Interesting, I will give it a try. So to handle it, a simple producer/consumer type structure for the queue/TCP? 

0 Kudos
Message 5 of 15
(3,849 Views)

I would agree than that you should have a separate task hanlding you TCP connection. This task would then use a queue/notifier/event to pass the command to the processing code or state machine.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 6 of 15
(3,838 Views)

yup, just arbitrarily pick which will be the server and which the client. If you are using RT, I always put the server on the RT platform, because you can wire a timeout of -1 to the listener and it can always be listening. You are able to do this since the program doesn't shut down, so you never have to service an exit command and stop the tcp loop; the user just powers the system on or off.

Message 7 of 15
(3,827 Views)

I will try. I am a little confused as to how to send the state to the queue itself before it gets sent to TCP. Since the statemachine is in its own loop, and the queue is in its own loop, how do I send the state from one to the other? 

 

Right now I have :

Loop1: Statemachine

Loop2: TCP

Loop3: Queue handler

 

For the obtain queue function I have the enum constant ring set for two states (triggerout and triggerin). My question is how do I send the state I want to the enqueue element block from a seperate loop?

0 Kudos
Message 8 of 15
(3,819 Views)

Your state machine should also be the queue handler. This is what some would call a queue driven state machine.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 9 of 15
(3,805 Views)

So this is not done yet, but am I on the right track? Any suggestions?

0 Kudos
Message 10 of 15
(3,785 Views)