LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus TCP/IP: reset communication after error

hi, i'm using labview 2020 to encode my program and the problem is in the attached image. 

 

this part have to check errors in tcp/ip communication and reset it until it work again. so, when i get an error because the tcp master is turned off to test, the program reset without error even the tcp master stay off. 

 

i don't know what i could do to only stabilize the communication for user when theres is no error.

 

for show you how this part works, theres is a vi attached. you just must configure a tcp/ip master and force an error.

 

anyway, sorry for my junior english and hope you can help me.

 

0 Kudos
Message 1 of 7
(846 Views)

You forgot to attach your code to the message.

Yes, the Modbus Library from NI could be a little bit "tricky" when you need to "hold" your connection and reconnect when device is disconnected, and the connected back. Usually it solved with simple State Machine, after error you should close the connection, then try to reconnect periodically (once per second or so). In additional, there are some hard-coded timeouts, which will close connection on inactivity timeout. Which Modbus library exactly are you using and how, please show.

 

0 Kudos
Message 2 of 7
(832 Views)

oh, i'm sorry! i hope the files are attached now.

 

Download All
0 Kudos
Message 3 of 7
(826 Views)

In general nothing principal wrong with your VI. If you have the only troubles with Error's acknowledgement/Control graying out and don't like to reconnect until the error is not acknowledged by user, then simple state machine could help.

This is how it works (not sure if this is your expected behavior, but anyway):

modbus.gif

On the other hand I would like to recommend to check Modbus Master example, where you have queued state machine design pattern with Event Structure, which is slightly more elegant than provided.

Check VI in the attachment, may be will help you as an idea to get started.

 

0 Kudos
Message 4 of 7
(770 Views)

this looks so good, thank you! but i think that i made a mistake when expressing the idea, lol. i'm sorry. when there is a communication error, i have a listbox to show it for the user, like this:

 

- error alarm ("Communication error! Check the panel and connection! If communication has changed, wait a moment"):

patolino_0-1713198347273.png

- stabilized error alarm  ("Communication
reestablished!"):

patolino_1-1713198599647.png

 

the problem is even when my master is and stay off, that stabilized error alarm occurs, even if alarm hasn't been stabilized. i wanna stabilize the alarm at the correct time.

 

once again, sorry for the confusion.

 

0 Kudos
Message 5 of 7
(760 Views)

@patolino wrote:

this looks so good, thank you! but i think that i made a mistake when expressing the idea, lol. i'm sorry. when there is a communication error, i have a listbox to show it for the user, like this:

 

- error alarm ("Communication error! Check the panel and connection! If communication has changed, wait a moment")

 


Then I'm not fully understand your needs, because with state machine design pattern you can do almost anything - "hold" an error, wait for user interaction, and so on:

status_string.gif

Just draw on the piece of paper how your vi should proceed from one state to another and do it accordingly.

If you will get too many shift registers on the loop, then will be better to make a cluster to avoid too many wires.

Also instead of trivial "string-based" state machine you can use enum-based, or queued, or use any framework like JKI state machine toolkit (it depends from the overal complexity of your final solution).

 

Message 6 of 7
(741 Views)

@Andrey_Dmitriev  escreveu:

 

Then I'm not fully understand your needs, because with state machine design pattern you can do almost anything - "hold" an error, wait for user interaction, and so on:

 i need to be honest: i've never used state machine in labview, then i don't understand so well how it help me. but about my program's needs, the user can't do anything (in the program, as click a button) when a communication error occurs, because it must recover itself. so, when my master is off, the program just may shows the established alarm when the operator turn on the master panel.

0 Kudos
Message 7 of 7
(701 Views)