LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Automating Button Clicks

Hello all,

 

I have been working with an Omega platinum temperature controller.  Most of the VI was provided by omega, and I added in a second reading.  Their example VI utilizes an event structure, but I need to read the temperature about 1 time per second.

 

I've tried (unsuccessfully) to divide the time by a numeric constant and output true if there is no remainder and false if otherwise.  I have tried using a while loop but this also did not work. 

 

Is there a way to have LabVIEW click this button for me once per second? I have attached the VI below.

 

Thank you,

Jackson

0 Kudos
Message 1 of 35
(3,831 Views)

If you mean the Read button, then yes.

Inside the Event Structure that handles the button press, all it's doing is sending a User Event.

Create a timeout case in the same Event Structure, then send the same user event. Set the timeout to 1000ms and you're done 🙂

 

Edit: in fact, just go to the Read case, then right click on the border and choose "Edit Events handled by this case" then on the left, click "Add Event". Select "Application" from the middle column then Timeout from the right column. Complete by wiring a 1000 to the hourglass at the top-left of the event structure.

Adding a timeout caseAdding a timeout case


GCentral
Message 2 of 35
(3,816 Views)

cbutcher,

 

I tried to follow that same method but I recieved the error code:

 

VISA Write in MB Serial Transmit.vi:630007->MB Serial Master Query.vi:1850006->MB Serial Master Query Read Holding Registers (poly).vi->Platinum_MB_SerRead.vi->Platinum_MB_Example Serial Master.vi

 

Does the timeout set for the read button also impact the write button?


Thank you,

Jackson 

0 Kudos
Message 3 of 35
(3,805 Views)

Hi,


@jackson040 wrote:

VISA Write in MB Serial Transmit.vi:630007->MB Serial Master Query.vi:1850006->MB Serial Master Query Read Holding Registers (poly).vi->Platinum_MB_SerRead.vi->Platinum_MB_Example Serial Master.vi


So that's not really an error code, it's the call chain for the error - i.e. it tells you where the error occurred. If you go through those VIs (from right to left, starting at your main VI then working into the subVI in the bottom loop's Read case and then into their subVIs) you could see where the error originates.

 

What was the error code? (i.e. not just the top bit of the message, but the number and perhaps the explanation text?)

 


@jackson040 wrote:

Does the timeout set for the read button also impact the write button?


No. The write button is separate. Do you need both to happen once per second?


GCentral
0 Kudos
Message 4 of 35
(3,779 Views)

@cbutcher wrote:

If you mean the Read button, then yes.

Inside the Event Structure that handles the button press, all it's doing is sending a User Event.

Create a timeout case in the same Event Structure, then send the same user event. Set the timeout to 1000ms and you're done 🙂

 

Edit: in fact, just go to the Read case, then right click on the border and choose "Edit Events handled by this case" then on the left, click "Add Event". Select "Application" from the middle column then Timeout from the right column. Complete by wiring a 1000 to the hourglass at the top-left of the event structure.

Adding a timeout caseAdding a timeout case


This approach assumes that no other events occur during the 1 second. I think that in this case it will generally work - but if, for instance, the user were pressing Clear Error once every second then the timeout will never occur. For this reason I don't like using the timeout for timing. I would just send the Read command every 1 second in its own loop - it's just sent via a queue.

0 Kudos
Message 5 of 35
(3,703 Views)

@johntrich1971 wrote:

This approach assumes that no other events occur during the 1 second. I think that in this case it will generally work - but if, for instance, the user were pressing Clear Error once every second then the timeout will never occur. For this reason I don't like using the timeout for timing. I would just send the Read command every 1 second in its own loop - it's just sent via a queue.


OP mentioned 'about once a sec', so it might be enough. I'd probably use the timeout, but set it to 100 and use Elapsed time instead. 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 6 of 35
(3,696 Views)

@johntrich1971 wrote:
 I would just send the Read command every 1 second in its own loop - it's just sent via a queue.

Whilst it's true that this is a better approach from the point of view of ensuring a read, I figured an extra loop would perhaps overcomplicate the situation.

 

OP, if you anticipate pressing lots of other buttons frequently, but don't want to press the read button, you will need to use the idea suggested by johntrich, and add a 3rd loop with timing that enqueues the Read command. 

 

I also wasn't a huge fan of the code duplication inherent in adding either another case or another loop...


GCentral
0 Kudos
Message 7 of 35
(3,691 Views)

@cbutcher wrote:

@johntrich1971 wrote:
 I would just send the Read command every 1 second in its own loop - it's just sent via a queue.

Whilst it's true that this is a better approach from the point of view of ensuring a read, I figured an extra loop would perhaps overcomplicate the situation.

 

OP, if you anticipate pressing lots of other buttons frequently, but don't want to press the read button, you will need to use the idea suggested by johntrich, and add a 3rd loop with timing that enqueues the Read command. 

 

I also wasn't a huge fan of the code duplication inherent in adding either another case or another loop...


As I stated, it will probably work in this case although @Yameada's idea to use a shorter timeout with an elapsed time improves upon it (if the timeout is 1 sec then a button press just before the 1 sec is up will cause that iteration to be nearly 2 sec). I was just pointing out the pitfall with this approach that could cause trouble down the road (plus could cost points on the CLD-R exam https://forums.ni.com/t5/Certification/CLD-R-Question-6-paper-1/m-p/2590721) when more complex programs require more precise timing. I generally just use the timeout case for indicator updates or other things for which precise timing is not a requirement.

Message 8 of 35
(3,684 Views)

First time I've seen a question for CLD-R, so that's interesting to know the sort of level/topic.

 

That aside, I guess it's dependent on the situation. Of course you're clearly right that timeout doesn't guarantee timing (or even occurrence, in principle), and Yamaeda gives a nice alternative to reduce the impact of other events whilst also avoiding too much added complexity (although probably that solution requires two separate cases rather than one case with two conditions).

 

I felt this was more or less for "indicator updates" but I may well have been wrong. Hopefully the OP can give some clarity 🙂 


GCentral
Message 9 of 35
(3,672 Views)

The goal is to update the indicators without me physically clicking the "read" button. 

 

I've attempted to  implement a third event structure inside another while loop, but the program won't return a reading from the device.  I believe this has to do with how I added the new loop because I am not completely sure how to add this to the queue.  I tried to wire the conditional terminal of the new while loop to the conditional terminal of the other while loop, but I do not think this was the correct method. I've attached my VI below if you would please take a look.


Thank you for all your help!

0 Kudos
Message 10 of 35
(3,645 Views)