{"id":19128,"date":"2017-02-13T10:00:02","date_gmt":"2017-02-13T18:00:02","guid":{"rendered":"https:\/\/blog.digilentinc.com\/?p=19128"},"modified":"2021-06-11T10:43:50","modified_gmt":"2021-06-11T17:43:50","slug":"creating-a-subvi-in-labview","status":"publish","type":"post","link":"https:\/\/digilent.com\/blog\/creating-a-subvi-in-labview\/","title":{"rendered":"Creating a SubVI in LabVIEW"},"content":{"rendered":"<p>So let&#8217;s say you have been working on a complex <a href=\"https:\/\/digilent.com\/shop\/labview-home-bundle\/\">LabVIEW <\/a>VI, you finally finish, and you go to test it, but it doesn&#8217;t work. You go back to try and correct the problem but are overwhelmed by the mess of wires and blocks. So many while loops and case structures, that it&#8217;s actually bigger than your screen size, so you have to use the scrollbars to navigate the program. This is the perfect situation to start creating SubVI&#8217;s!<\/p>\n<p>SubVIs are the same as VIs, they contain front panels and block diagrams, but you call them from within a VI. A SubVI is similar to a subroutine in text-based programming languages.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19130 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.17.51-AM-e1486989007855.png\" alt=\"\" width=\"256\" height=\"109\" \/><\/p>\n<p><strong>So, what exactly is a SubVI?<\/strong> It is a VI that is placed on the block diagram of a\u00a0higher-level\u00a0VI. It allows you to write modules of code that you can wire into your diagrams later. The icon is what the SubVI will look like on another VI&#8217;s block diagram. The connector pane allows you to assign terminals on the icon to front panel controls and indicators for the purpose of wiring values into and out of a SubVI.<\/p>\n<p><strong>Creating a SubVI from an Existing VI:<\/strong><\/p>\n<p>You can simplify the block diagram of a VI by converting sections of the block diagram into SubVIs. Create a new VI and construct the following block diagram.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" wp-image-19129 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-3.52.58-AM-590x600.png\" alt=\"\" width=\"389\" height=\"396\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-3.52.58-AM-590x600.png 590w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-3.52.58-AM.png 647w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><\/p>\n<p>Next, Select the section of the block\u00a0diagram you want to convert and then select\u00a0Edit\u00bbCreate SubVI from the Tools menu.\u00a0The selected section of the block diagram is replaced with an icon for the SubVI. LabVIEW creates controls and indicators for the new SubVI, automatically configures the connector pane based on the number of control and indicator terminals you selected, and wires the SubVI to the existing wires. The SubVI interface (icon and connector pane) is not as immediately obvious as the front panel and block diagram when a VI is opened. It is accessible from the upper\u00a0right-hand\u00a0corner of the front panel window.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19130 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.17.51-AM.png\" alt=\"\" width=\"352\" height=\"168\" \/><\/p>\n<p>Now that the connector pane is wired for this VI, it is a usable SubVI. However, to make it easily identifiable in the block diagrams of VIs that call it, you should give it a custom icon. This is not necessary, but a brief summary of the steps to do so are detailed below:<\/p>\n<p>First, use the right click menu on the Icon or Connector Pane to select &#8220;Edit Icon.&#8221; The following utility appears:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-19132 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.06.54-AM-600x287.png\" alt=\"\" width=\"600\" height=\"287\" \/><\/p>\n<p>This program operates more or less like a\u00a0rudimentary paint program. I made the following simple icon for this example (the heart took way longer than I thought it would, I must really like math&#8230;.).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-19131 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.13.12-AM-600x287.png\" alt=\"\" width=\"600\" height=\"287\" srcset=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.13.12-AM-600x287.png 600w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.13.12-AM-768x367.png 768w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.13.12-AM-702x336.png 702w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.13.12-AM-800x383.png 800w, https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.13.12-AM.png 962w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>But what if you want to reuse this SubVI in another VI? First, save the SubVI. Then open the other VI, right click the block diagram, and click &#8220;Select a VI&#8230;&#8221;. This then brings up a file browser, then browse to the SubVI you saved and double click it. This drops the SubVI in the block diagram with it focused on your mouse so you can drag it around the new VI, then click to drop it. You now have your SubVI on your Front Panel!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-19133 aligncenter\" src=\"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.24.26-AM.png\" alt=\"\" width=\"504\" height=\"221\" \/><\/p>\n<p>Thank you for reading my blog post, and for more information about creating SubVI&#8217;s in LabVIEW check out\u00a0this <a href=\"http:\/\/www.ni.com\/white-paper\/7593\/en\/\">link<\/a>. If you are interested in trying out LabVIEW for yourself, you can purchase a copy of <a href=\"https:\/\/digilent.com\/shop\/labview-home-bundle\/\">LabVIEW 2014 Home Edition<\/a>\u00a0which includes everything you will need to run\u00a0<a href=\"https:\/\/www.labviewmakerhub.com\/doku.php?id=learn:tutorials:libraries:linx:3-0:beaglebone-black-setup\">LINX 3.0<\/a>.\u00a0Please comment below with any questions or comments you may have.<\/p>\n<div class='watch-action'><div class='watch-position align-left'><div class='action-like'><a class='lbg-style6 like-19128 jlk' data-task='like' data-post_id='19128' data-nonce='b777872406' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Like' \/><span class='lc-19128 lc'>+5<\/span><\/a><\/div><div class='action-unlike'><a class='unlbg-style6 unlike-19128 jlk' data-task='unlike' data-post_id='19128' data-nonce='b777872406' rel='nofollow'><img src='https:\/\/digilent.com\/blog\/wp-content\/plugins\/wti-like-post-pro\/images\/pixel.gif' title='Unlike' \/><span class='unlc-19128 unlc'>0<\/span><\/a><\/div><\/div> <div class='status-19128 status align-left'><\/div><\/div><div class='wti-clear'><\/div>","protected":false},"excerpt":{"rendered":"<p>Feeling overwhelmed by your messy LabVIEW Front Panel? Check out how to create a LabVIEW SubVI!<\/p>\n","protected":false},"author":42,"featured_media":19130,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4323,1563],"tags":[],"ppma_author":[4493],"class_list":["post-19128","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","category-guide"],"jetpack_featured_media_url":"https:\/\/digilent.com\/blog\/wp-content\/uploads\/2017\/02\/Screen-Shot-2017-02-13-at-4.17.51-AM-e1486989007855.png","authors":[{"term_id":4493,"user_id":42,"is_guest":0,"slug":"astanton","display_name":"Austin Stanton","avatar_url":"https:\/\/secure.gravatar.com\/avatar\/0cc9db2caf6344c8f78ea46c21570f33a954c45596addf479125043e52431de0?s=96&d=mm&r=g","1":"","2":"","3":"","4":"","5":"","6":"","7":"","8":"","9":"","10":""}],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/19128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/users\/42"}],"replies":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/comments?post=19128"}],"version-history":[{"count":0,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/posts\/19128\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media\/19130"}],"wp:attachment":[{"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/media?parent=19128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/categories?post=19128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/tags?post=19128"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/digilent.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=19128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}