element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
NI LabVIEW Community
  • Products
  • Dev Tools
  • NI LabVIEW Community
  • More
  • Cancel
NI LabVIEW Community
Labview Blogs LabVIEW: use an Event channel to send button clicks to a Subflow
  • Blog
  • LabVIEW Challenge Blogs
  • Forum
  • Documents
  • Quiz
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join NI LabVIEW Community to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 2 Apr 2023 11:32 AM Date Created
  • Views 2307 views
  • Likes 6 likes
  • Comments 1 comment
  • message
  • channel
  • labview
  • subvi
Related
Recommended

LabVIEW: use an Event channel to send button clicks to a Subflow

Jan Cumps
Jan Cumps
2 Apr 2023
LabVIEW: use an Event channel to send button clicks to a Subflow

In LabVIEW, you often use while loops with a stop button. The process will keep running and looping until you press the button. It then triggers the exit condition and the loop stops.
Here is an example from my Digilent DAQ driver:

image

The button is inside the loop. Its state gets evaluated at each run. When you click, the process will end as expected.

Problem statement: SubVI with loop will not react on button clicks on the Front Panel

If you want to wrap this whole flow in a SubVI, you'll see that the functionality changes. To get the button on the main form, you have to create a way to connect that button to the loop's stop condition. If you create the SubVI connector (it's called a terminal) inside the loop, it will not check the button status, but keeps using the status that the button had when the SubVI was invoked. The logic within the SubVI will only see any status once, at the time that the parent flow passed the data to the SubVI. Any subsequent clicks are not passed on, so if you click the stop button, the flkow will not stop.

Solution: Use a Channel

LabVIEW has several messaging systems, from very simple to flexible / complex. I'm going for the simplest possible solution: a Channel with Tags. The button will be placed in a loop on the main flow, and send its state into the channel. The SubVI receives the messages (button state) and can react on it

Receive the Button Click

This is the loop, with the button replaced by a channel:

image

It's not that complex. The channel will take the message, and the channel endpoint converts it to the original type - a boolean. When something (see next section: the stop button does that) shoots a true in the channel, the loop will stop.

Send the Button Click

This is little flow that wraps the button inside a loop, so that it's constantly checked - even when flow is active inside the SubVI:

image

As long as the button isn't clicked, this little loop keeps running. When the user clicks the stop button, two things happen. The true value is pushed in the channel, and the loop stops.
That last action is a design decision specific to my flow. When I click the stop button, I want that the SubVI is notified, but I also want to end my program. If I would not exit the button loop, the program would keep running until terminated.

Combined Flow:

This is a snippet from a real flow. You 'll regognise the stop button, the Channel and the SubVI that will now receive click events.

image

side note: You'll see in this example that the button loop is wrapped inside a case condition. That's specific for my application: I only want to have a stop option if the SubVI is set to continuous loop mode. If it is set to single scan, there's no need to interrupt it. And the process would stay active in single scan mode until the user clicks the stop button. Not good. Here's what happens with the button if continuous mode is false: nothing Slight smile. The loop isn't started

image

  • Sign in to reply
  • Jan Cumps
    Jan Cumps over 2 years ago

    A little optimisation:

    image

    The original flow pushes the state into the flow every time. The revised one only sends true.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube