Qizhen's profileLabVIEWPhotosBlogListsMore Tools Help

Blog


    选择结构

        选择结构相当于文本语言中的条件语句。LabVIEW 8 中新增加的 Diagram Disable Structure,Conditional Disabled Structure 类似 C 语言中的条件宏定义语句。

    一. 程序框图禁用结构(Diagram Disable Structure)

        在调试程序时常常会用到程序框图禁用结构。程序框图禁用结构中只有 Enabled 的一页会在运行时执行,而 Disabled 页是被禁用、即不会执行的;并且在运行时,Disable 页面里的 SubVI 不会被调入内存。所以,被禁用的页面如果有语法错误也不会影响整个程序的运行。这是一般选择结构(Case Structure)无法做到的。



    图1、2:使用程序框图禁用结构

        例如图 1、2 中的示例,如果我们在运行程序的时候暂时不希望将 test 写入到文件里,但又觉得有可能以后会用到。此时,就可以使用程序框图禁用结构把不需要得程序禁用掉。需要注意的是程序框图禁用结构可以有多个被禁用的框架,但必须有且只能有一个被使用的框架。在被使用的框架中,一定要实现正确的逻辑,比如上图的例子中,在被使用的框架中一定要有连线把前后的文件句柄和错误处理联接好。

    二. 条件禁用结构(Conditional Disabled Structure)

        条件禁用结构则根据用户设定的符号(symbol)的值来决定执行哪一页面上的程序。其他方面与程序框图禁用结构相同。
    程序中所使用的符号,可以在项目或是运行目标机器(例如“My Computer”)的属性里设置。


    图3:条件禁用结构

        值得注意的是:程序框图禁用结构与条件禁用结构都是静态的,如果需要在运行时决定执行哪一部分的程序可以使用选择结构。

        程序框图禁用结构和条件禁用结构的一种实用案例可以参考:《其它常用调试工具和方法

    三. 选择结构(Case Structure)

        在一般情况下,选择结构类似于 C 语言的 switch 语句。当输入为 bool 数据类型或 error 数据类型时,选择结构类似于 C 语言中的 if 语句。


    图4:枚举类型的 Case Selector

        有输出时,则每一个框架中都必须连一个数据,当然也可以选择“Use Default If Unwired”。选择“Use Default If Unwired”会有一定的风险,因为你可能会忘记了连线,这时候 LabVIEW 并不会提醒你,程序就可能得到不可预料的结果。
        如图5所示,鼠标右击数据输出隧道,可以选择是否使用“Use Default If Unwired”


    图5:选择 Use Default If Unwired

    相关文章:
        我和 LabVIEW

    编辑

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    海波wrote:
    你好厉害哦。
    我是LABVIEW的新手,有什么问题一定要来请教你哦,我把他发在我的日志里,嘿嘿。
    Nov. 30

    Trackbacks

    The trackback URL for this entry is:
    http://ruanqizhen.spaces.live.com/blog/cns!5852D4F797C53FB6!1988.trak
    Weblogs that reference this entry
    • None