现在的位置: 首页 > 综合 > 正文

labview编程技巧—-labview与INI文件

2013年12月13日 ⁄ 综合 ⁄ 共 5915字 ⁄ 字号 评论关闭

在WIN95以前,WINDOWS还没有引入注册表的概念,WINDOWS是利用INI文件来存储计算机相关配置的,在API里,WINDOWS提供了丰富的API函数来操作INI文件,LV里也专门有个子类别封装了这些API函数,使用非常方便。

LV使用INI文件来存储配置,应用非常广泛,生成执行文档后也自动生成一个INI文件。

LV主要在下列情况下使用INI文件:

存储前面板或者前面板特定控件的默认值和当前值

存储本次应用的运行结果供下一次启动是调用

存储硬件配置文件

存储硬件配置是非常重要的,比如一般的板卡都有16个数字输出,外部接继电器来控制外部设备,继电器是比较容易损坏的,而通常16个继电器中是有备用的,如何在不改变软件和硬件的情况下把输出更改到另外的继电器上,这样,只需要简单地改动一下外部接线就可以了那,使用配置文件可以轻松实现。

INI文件结构很简单,装了多操作系统的人都知道,WINDOWS本身有个BOOT.INI

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)/WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)/WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

我们看一下LV软件本身也利用了INI文件来保存配置。

[LabVIEW]
server.tcp.port=3363
server.tcp.enabled=TRUE
server.tcp.access="+127.0.0.1"
IsFirstLaunch=False
PaletteHidddenControlCategories_LocalHost="Modern;System;Classic;Control Design & Simulation;.NET & ActiveX;Addons;"
PaletteHidddenFunctionlCategories_LocalHost="Programming;Measurement I/O;Instrument I/O;Vision and Motion;Mathematics;Signal Processing;Data Communication;Connectivity;Control Design & Simulation;SignalExpress;Addons;"
menuSetup="default"
saveFloaterLocations=True
find.viListFlags=4
LastErrorListSize=0,0,379,486
paletteStyle="NamedIcons"
NoAdvice070=",CleanUpWire,FlatSequence"
SaveChanges_ApplyToAll=True
PropPageBounds="398;181;884;636"
RecentFiles.pathList="C:/Program Files/National Instruments/LabVIEW 8.5/examples/DAQmx/Analog In/Measure Voltage.llb/Acq&Graph Voltage-Int Clk.vi;C:/Program Files/National Instruments/LabVIEW 8.5/examples/DAQmx/Analog In/Measure Voltage.llb/Acq&Graph Voltage-Ext Clk-Analog Ref.vi;C:/Documents and Settings/Administrator/Local Settings/Temporary Internet Files/Content.IE5/7M9NS8HF/chart%20right%20to%20left[1].vi;C:/Documents and Settings/Administrator/My Documents/windows_environment_variable_reader_writer/Windows Environment Variable Reader Writer.vi;C:/Documents and Settings/Administrator/My Documents/MDI.llb/Simple MDI Demo.vi;D:/Control 1.ctl;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/tree/Tree Sorter.llb/Join.vi;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/notifier.llb/Create Notifier.vi;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/notifier.llb/Wait On Notification.vi;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/inputDevices.llb/Acquire Input Data.vi"
ShowBufferAllocationsArrays=True
ShowBufferAllocationsClusters=True
ShowBufferAllocationsStrings=False
ShowBufferAllocationsPaths=False
ShowBufferAllocationsScalars=False
ShowBufferAllocationsVariants=False
ShowBufferAllocationsOther=False
NewDlgRecentMainTemplates.pathList="C:/Program Files/National Instruments/LabVIEW 8.5/templates/Frameworks/DesignPatterns/ProducerConsumerEvents.vit"
NewDlgBounds="700;480"
NewDlgRecentTemplates.pathList=""
NewDlgLastSelected="8E4D36AD-F776-4C48-97C6-C1D85EFE889F"
NewDlgSmall=False
NewDlgCollapsed="77E350A8-F9AA-43FF-85E2-454279EBB9A7/Frameworks 3F7CF7A8-5E4D-4EDC-AA25-FA4A326988EF 8E4D36AD-F776-4C48-97C6-C1D85EFE889F"
SuperSecretPrivateSpecialStuff=True
colorHistoryItemA=00000BFF
RecentFiles.projectPathList="C:/Documents and Settings/Administrator/My Documents/xcontrol events/xcontrol events/XControl Events Project.lvproj;C:/Program Files/National Instruments/LabVIEW 8.5/examples/general/xcontrols/Dual Mode Thermometer/Simple Dual Mode Thermometer XControl.lvproj;C:/Program Files/National Instruments/LabVIEW 8.5/examples/lvdsc/XControls/Spinner/Spinner.lvproj;C:/Documents and Settings/Administrator/My Documents/Linked_List_Project/Linked List/Linked_List_Project.lvproj;D:/TEST/Untitled Project 1.lvproj;C:/Documents and Settings/Administrator/My Documents/Scripting_Tools_0.16.02/Scripting Tools/Scripting Tools.lvproj;C:/Documents and Settings/Administrator/My Documents/IconEditor_85_V2.2/IconEditor.lvproj;C:/Documents and Settings/Administrator/My Documents/第一名_何凌_公司问题/第一名 何凌 公司问题/Src/VI company.lvproj"
ProjectExplorer.ClassicPosition=143,53,543,415
colorHistoryItemB=009A8574
editRecentPaths="C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/sysinfo.llb;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/semaphor.llb;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/miscctls.llb;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/GetType.llb;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/inputDevices.llb;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/Utility/notifier.llb;C:/Program Files/National Instruments/LabVIEW 8.5/vi.lib/tree/Tree Sorter.llb"
LLBMgr_ActivePlugins=""
LLBMgr_RecentPath="C:/Documents and Settings/Administrator/My Documents/MDI.llb"
colorHistoryItemC=00FF8242
autoerr=2
colorHistoryItemD=00000FDC
colorHistoryItemE=003100DC
colorHistoryItemF=00FFFFFF
colorHistoryItemG=00FF3D00
colorHistoryItemH=000F00DC
colorHistoryItemI=004AFF42
colorHistoryItemJ=00C88E00
colorHistoryItemK=000025FF
exoticControls=TRUE
NoAdvice080=",ClassBrowser"
SuperPrivateScriptingFeatureVisible=True
SuperSecretPrivateSpecialStuff=True
superPrivateScriptingFeatureSichtbar=True

FPFont="0" 18
BDFont="0" 18
toolPaletteLoc=494,22,645,100
LVLibraryThemeColor=006699FF

ini文件非常简单,是文本文件,可以用WINDOWS记事本直接打开,组成结构是一个简单的树型结构,说明如下:

[section1]

key1_section1=VALUE
key2_section2=VALUE
key3_section3=VALUE

[section2]
key1_section2=value
key2_section2=value
key3_section2=value

可以看出结构非常简单,每个INI文件又一个或者多个SECTION组成,每个SECTION又一系列键和键值组成,值的类型可以是BOOLEAN ,DOUBLE,I32,U32,STIRNG,PATH等等

LV专门提供了一组节点来处理INI文件:

上排的是操作INI的节点,下排的是读取INI本身信息的节点

操作INI节点包括:打开,读键值,写键值,删除键值,删除分类(SECTION),关闭。
信息节点包括:    取得所有分类中的键名称,取得所有分类名称,判断文件是否是配置文件。

具体操作和其他文件操作类似,打开(注意路径问题)---》读或者写-----》关闭

LV提供的INI节点非常基本,数据类型也是基本的数据类型,我们实际工作更常用的是数组和簇类型,OPENG为我们作好了这些,并且是开放原代码,看看它提供的节点:

这里的OPEN和CLOSE就是LV本身提供的节点,其它的分别介绍一下:

Read INI Cluster: 读取簇的配置
Write INI Cluster: 写簇的配置

这两个VI读写INI时,SETION部分就是簇的名称

Read Section Cluster:读取指定SECTION下的簇配置
Write Setion Cluster:写入指定SECTION的簇配置
这两个VI同上面的类似,但是可以指定SETION名称,这样可以在同一SECTION下,写入或者读取多个CLUSTER配置。

Read Panel: 读取指定的控件面板(恢复上次值)
Write Panel:写入指定的VI的控制面板当前值到配置文件(供下次调用)
这两个VI的输入是VI参考,既可以写入或者读本身,又可以在一个VI中来操作另一个VI

READ KEY:可以读取特定SECTION下特定CLUSTER中的元素的键值
WRITE KEY:写入特定SECTION下特定CLUSTER中的元素的键值

抱歉!评论已关闭.