LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Boolean Event And Modbus

This VI is meant to write to a register of a wireless module using Modbus protocol.  It also reads the register values, but this is only there as a quick method of testing.  The goal is for the boolean switch to control both the LED and change the value of the register from 0 to 16256.

 

As it is now, when the program runs, the button will control the LED and the register values only once.  I have ensured that the mechanical action of the button is as a switch, and not a latch.  I've included the VI.  The module it is communicating with should be irrelevant, as the Write and Read Modbus functions work fine, but it is a Control By Web X600-M.

0 Kudos
Message 1 of 7
(2,202 Views)

It's not clear from your description what the current problem is.

 

Are you getting an error message?

 

That Modbus Close belongs outside the loop like I told you in the other thread.

Why is there a while loop inside that event case?  It is stuck running forever with the same values until somehow you get an error on the modbus line to cause the loop to stop.  Then the modbus close will kill the reference on the wire to never be reopened again.

 

Please take some tutorials to learn more about LabVIEW and understand the concepts of Data Flow.

0 Kudos
Message 2 of 7
(2,192 Views)

The problem is that the boolean switch will trigger the event once, but not again.  This program, once finished, will run continuously for months at a time, and will need to continuously keep track of whether or not the switch is on.  For this, there is no error message, only the fact that it isn't continuously running.  My understanding of the process is this:

The while loop will continue until the Stop button is pressed.  Because of this, the event structure should always be alerted if the switch is activated.  I have tried having the switch both inside and outside of the Event Structure with no difference.

 

As for the Close Modbus VI, if I take it out of the while loop and run, it will boot me from LabVIEW.  No error message, just a crash.  The Modbus portion works as is.

0 Kudos
Message 3 of 7
(2,186 Views)

I suggest you turn on Highlight Execution to see how the dataflow works, because your understanding is mistaken.

 

The boolean switch can't trigger another event because it is still stuck in the first case it runs because your innermost while loop will only stop when you have an error on the Modbus Read.

 

See the attached VI to see how this should be programmed.

0 Kudos
Message 4 of 7
(2,170 Views)

So by adding a timeout parameter to the Event Structure, it ends each event after one second meaning that it can run again after?

0 Kudos
Message 5 of 7
(2,165 Views)

If no events happen within the timeout period, the event structure will execute the timeout case.  In this VI, nothing happens in there, but it allows the loop to iterate again and run the Modbus Read that is at the beginning of the while loop.

 

I could have just as easily put the Read after the event structure.

 

If you happen to mash away on the change button faster than once per second, then the timeout case never runs, but because the event structure finishes, the loop will iterate and do the Read.  It will just cause the Read to happen faster.

0 Kudos
Message 6 of 7
(2,161 Views)

No, that is not how the event structure works. The event structure is used to catch events, whether those are user defined or UI evens. The timeout event case means that it will trigger after the timeout if no other event has occurred. As your code is written you never exit the event case since your while loop will only exit on a Modbus error. The timeout will not stop the processing within another event case.



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 7 of 7
(2,156 Views)