LabWindows CVI教程
LabWindowsCVI库函数的使用
LabWindowsCVI库函数的使用LabWindows/CVI库函数的使用一、实验目的1、进一步熟悉CVI的集成开发环境2、进一步学习仪器面板中控键的使用3、学习CVI库函数使用方法4、学习用CVI库函数进行频谱分析的步骤二、实验内容1、编写一个波形显示程序,要求根据输入的幅值和周期数显示正弦波;根据输入的幅值和占空比显示方波。
2、制作一个简单仪器面板:要求有两个图形控件,用来显示图形;四个数字控件,分别用来输入正弦波幅值、周期以及方波的幅值、占空比;五个命令控件,分别用来启动程序产生正弦波、产生方波,清楚屏幕上显示的图像和退出程序。
3、利用CVI的代码生成工具生成你制作的一起面板的程序框架。
4、在用户程序中添加相应程序,运行后观察程序执行的结果。
三、程序源代码#include#include#include#include "guweiming.h"static int panelHandle;double a,b,c,d;int main (int argc, char *argv[]){if (InitCVIRTE (0, argv, 0) == 0)return -1; /* out of memory */if ((panelHandle = LoadPanel (0, "guweiming", PANEL)) < 0) return -1;DisplayPanel (panelHandle);RunUserInterface ();DiscardPanel (panelHandle);return 0;}int CVICALLBACKQINGPINGCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:DeleteGraphPlot (panelHandle, PANEL_GRAPH_2, -1, V AL_IMMEDIATE_DRAW);break;}return 0;}int CVICALLBACK FANGBOCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){ double wave[512] ;double phase=120,*p;p=&phaseswitch (event){case EVENT_COMMIT:SquareWave (512, c, 7.8125e-3, p, 50.0, wave);PlotWaveform (panelHandle, PANEL_GRAPH, wave, 512,V AL_DOUBLE, 1.0, 0.0, 0.0, d, V AL_THIN_LINE, VAL_EMPTY_SQUARE, V AL_SOLID, 1, V AL_RED);break;}return 0;}int CVICALLBACK QINGPING2Callback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, V AL_IMMEDIATE_DRAW);break;}return 0;}int CVICALLBACK TUICHUCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:QuitUserInterface (0);break;}return 0;}int CVICALLBACK FTCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_FT, &a);break;return 0;}int CVICALLBACK ZQCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_ZQ, &b);break;}return 0;}int CVICALLBACK FZCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event)case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_FZ, &c);break;}return 0;}int CVICALLBACK ZKBCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2) {switch (event){case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_ZKB, &d);break;}return 0;}int CVICALLBACK ZHENGXIANBOCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){ double Waves[512] ;switch (event){case EVENT_COMMIT:SinePattern (512, a, 0.0, b, Waves);PlotWaveform (panelHandle, PANEL_GRAPH_2, Waves, 512, V AL_DOUBLE, 1.0, 0.0, 0.0, 1.0, V AL_THIN_LINE, V AL_EMPTY_SQUARE, V AL_SOLID, 1, V AL_RED);break;}return 0;}四、思考题1.简述Panel Handle 和Control ID 参数的作用;答:Panel Handle 这一参数由LoadPanel 库函数设置,存入的是已存储的面板文件这一对象。
[labwindows cvi教程]LabWindows试用版入门指南
[labwindows cvi教程]LabWindows™/CVI™试用版入门指南最低系统要求想运行LabWindows/CVI,须具备以下配置:∙采用Pentium 1 GHz或更高性能微处理器的个人计算∙Microsoft操作系统:o Windows 7 (32位和64位)o Windows Vista (32位和64位)o Windows XP (32位)o Windows Server 2008 R2 (64位)o Windows Server 2003 R2 (32位)注:LabWindows/CVI仅支持Windows Server R2版本。
∙1024 × 768分辨率(或者更高) 视频适配器∙至少128 MB RAM, 推荐采用512 MB∙ 1.1 GB可用硬盘空间适合完整安装∙兼容Microsoft的鼠标安装指南完成下列步骤,从而安装LabWindows/CVI试用版软件包:1. 下载源自 的LabWindows/CVI试用版软件包并依照屏幕指南解压缩文件2. 解压缩文件后,安装自动开始,同时NI LabWindows/CVI窗口出现。
单击安装LabWindows/CVI 版本,其中的版本是您在试用的LabWindows/CVI版本3. 单击下一步4. 在用户信息面板上,选择安装NI LabWindows/CVI 版本试用版-不需要序列号5. 根据屏幕上的指示操作6. 安装LabWindows/CVI后,LabWindows/CVI安装程序提示您插入NI设备驱动盘。
评估LabWindows/CVI,无需通过安装设备驱动程序。
单击稍后安装(Later),完成LabWindows/CVI的安装。
LabWindows/CVI试用版在下载后,可安装LabWindows/CVI试用版软件包;该试用版软件包能在之后作为具有许可证的LabWindows/CVI版本被激活。
当您在试用期内启用LabWindows/CVI或是您购买合法许可证前,LabWindows/CVI会展现下图中出现的对话框。
LabWindowsCVI教程(1)PPT课件
LabWindows/CVI
19.08.2020
4/18
2. LabWindows/CVI的历史
19.08.2020
5/18
3. LabWindows/CVI的特点
(1)针对测试测量领域的ANSI C语言开发环境
C compiler for Virtual Instruments (CVI)
变量命名 程序的格式和注释 复杂的程序要事先规划设计
19.08.2020
7/18
4. 程序结构
测控软件一般包括:用户界面、程序控制、数 据采集和数据分析4部分
19.08.2020
8/18
5. 开发环境
(1)主要窗口
LabWindows/CVI开发环境的三个主要窗口是工程窗口 (.prj)、源代码窗口(.c)和用户界面编辑器窗口(.uir)。
19.08.2020
15/18
LabWindows/CVI的函数库
19.08.2020
16/18
(4)交互式代码生成 C文件中生成程序结构:Main, Switch, If, For Loop… … UIR文件中生成代码框架: Main Function, Callback Functions (panel, control, menu) 函数面板中函数的自动插入
20/18
C源代码文件
.uir 用户界面资源文件
.h
用户界面资源头文件
.lib 外部静态库模块文件
.obj 目标文件
.h
外部模块头文件
.dll 动态链接库文件
.lib 动态链接库导入库文件
.fp 函数库(函数数和函数面板)文件
19.08.2020
LabWindows CVI实时模块入门指南说明书
October 2008374686A-01Getting Started with theLabWindows /CVIReal-Time ModuleThis document provides an introduction to the LabWindows ™/CVI ™ Real-Time Module. Refer to this document for installation and configuration instructions and information about creating a real-time (RT) project.Installing the Real-Time Module Software on a Host ComputerYou must first install the Real-Time Module software on a host computer. Then you can configure and install software on the RT target.To install and use the Real-Time Module software, you must have the following:•Free Disk Space —In addition to the minimum system requirements for LabWindows/CVI, you must have at least 250 MB of free disk space for the Real-Time Module software. Refer to the LabWindows/CVI Release Notes for minimum system requirements.•RT Target —The LabWindows/CVI Real-Time Module supports NI RT Series PXI controllers and desktop PCs converted to RT targets. Refer to the Using Desktop PCs as RT Targets with the LabWindows/CVI Real-Time Module document for more information about converting a desktop computer to an RT target.Complete the following steps to install the LabWindows/CVI Real-Time Module on a host computer.1.Install LabWindows/CVI. Refer to the LabWindows/CVI Release Notes for information about installing LabWindows/CVI.Note Do not install the device driver software when you are prompted to do so during the LabWindows/CVI installation. Instead, install the device driver software when you are prompted during the LabWindows/CVI Real-Time Module installation.™™2.Insert the LabWindows/CVI Real-Time Module CD into the CD drive. Ifthe CD does not run automatically, open Windows Explorer, right-click the CD drive icon, and select AutoPlay.3.Select Install LabWindows/CVI Real-Time Module on the NationalInstruments LabWindows/CVI screen.4.Follow the instructions on the screen.5.During the installation, use the NI Device Drivers media to install thedevice drivers that you need.Configuring the RT TargetAfter you install LabWindows/CVI and the RT module, you must useNI Measurement & Automation Explorer (MAX) to configure the RT target and to install software and drivers on the RT target. MAX provides access to NI devices and systems and can communicate with networked RT targets, or remote systems, located on the same subnet as the computer running MAX. Complete the following steps to configure the RT target. The following sections describe these steps in more detail.1.Boot the RT target into LabVIEW RT.2.Configure network settings.3.Install software on the RT target.4.Configure system settings.5.Configure I/O.Refer to the Measurement & Automation Explorer Help for a complete tutorial about configuring the RT target. Select Help»MAX Help to access this help file, and then refer to the MAX Remote Systems Help section.LabVIEW Real-Time Module. However, you can apply the sameconcepts when you use the LabWindows/CVI Real-Time Module. Booting the RT Target into LabVIEW RTIf the RT target has only LabVIEW RT installed on its hard drive, the system is already set up to boot into LabVIEW RT, and you can continue to the Installing Software on the RT Target section of this document. If the RT target has LabVIEW RT and Windows installed on its hard drive, your system may have DIP switches or BIOS settings for booting into LabVIEW RT.If the RT target is a PXI system that does not have LabVIEW RT installedand has a floppy disk drive, you can create a boot disk to boot the system intoLabVIEW RT.Getting Started with LabWindows/CVI © National Instruments Corporation 3Getting Started with LabWindows/CVI Real-Time 1.Select Tools»RT Disk Utilities»Create PXI Boot Disk in MAX tocreate a boot disk from the host computer.2.Click Yes in the Measurement & Automation Explorer dialog box andfollow the instructions on the screen to create the boot disk.3.When you finish creating the boot disk, remove the floppy disk from thehost computer and insert it into the floppy drive of the PXI controller you are using as an RT target.4.Power on or reset the controller to boot it into LabVIEW RT.If you are converting a desktop computer to an RT target, refer to the Using Desktop PCs as RT Targets with the LabWindows/CVI Real-Time Module document for information about booting into LabVIEW RT.Configuring Network SettingsNoteTo perform the initial configuration, you must connectunconfigured RT targets to the same network subnet as the host computer from which you launch MAX. Unconfigured targets outside of the subnet do not appear under the Remote Systems item in the MAX configuration tree.1.Connect the RT target to the network and power on the target.unch MAX and expand the Remote Systems item in the MAXconfiguration tree.3.Select the RT target from the Remote Systems item and click theNetwork Settings tab. The RT target appears as 0.0.0.0 under the Remote Systems item.4.Assign an IP address in the Network Settings tab using one of thefollowing options:•Select the Edit the IP settings option and specify an IP address.You also can click Suggest Values to select an IP address suggested by MAX.•Select Obtain IP address from DHCP server to obtain an addressautomatically.5.Click Apply to commit the changes.6.Click Yes to reboot the RT target.If your previously configured RT target is on another subnet and does not appear under the Remote Systems item, you must add the target manually. Complete the following steps to add the RT target:1.Right-click the Remote Systems item and select Create New .2.Select the target type and click Next.Getting Started with LabWindows/CVI Real-Time 3.Enter the host name or IP address of the device. You can obtain the hostname or IP address of the RT target by running MAX from a computer on the same subnet as the target or by connecting a monitor to the target and viewing the information displayed when the target boots.4.Click Finish . MAX adds the device to the Remote Systems list.Installing Software on the RT TargetUse the LabVIEW Real-Time Software Wizard to install software on the RT target. With the LabVIEW Real-Time Software Wizard, you can view the software that is already installed on the target, view the software that is available to install on the target, and change the software that is installed on the target. Click Help in the wizard for more information about installing and uninstalling software on the RT target.1.Expand the RT target under the Remote Systems item in the MAXconfiguration tree, right-click Software , and select Add/Remove Software .2.Select the software you want to install on the RT target.Note If you have multiple software versions installed on the host computer, the most recent version is selected by default. You can choose to install another version.•Ethernet Drivers —MAX automatically selects the appropriate Ethernet driver(s) for the RT target when you install theLabWindows/CVI Run-Time Engine for RT component.•LabVIEW Real Time —MAX selects this item automatically when you install the LabWindows/CVI Run-Time Engine for RTcomponent.•NI RT Extensions for SMP (MultiCore Support)—Install this item to take advantage of parallel processing on a multiple-CPU system.Note Single-CPU systems perform best without the NI RTExtensions for SMP . Also, some applications, such as those that consist mainly of single-point I/O, can achieve lower latency on a multicore system by using a single CPU without the NI RTExtensions for SMP .•LabWindows/CVI Network Variable for RT —Install this item only if your application uses functions from the Network VariableLibrary.•LabWindows/CVI Run-Time Engine for RT—Install this item to add support for LabWindows/CVI RT applications on the RT target.This component is required for all LabWindows/CVI RTapplications.•Language Support for LabVIEW RT—Install this item if you are using strings in your RT application containing ASCII charactersabove 127 or multibyte characters. After installing this item on theRT target, you can configure the locale in MAX by selecting thetarget in the Remote Systems item in the MAX configuration tree,selecting the System Settings tab, and modifying the Locale option.•NI Hardware Drivers—Install the appropriate drivers for any other hardware libraries that you use in your application. For example,install the NI-DAQmx component if your application uses functionsfrom the NI-DAQmx Library.•Network Variable Engine—MAX automatically selects this item when you install the LabWindows/CVI Network Variable for RTcomponent.•USB Support—Install this item to enable support for accessing USB thumbdrives.•Variable Client Support for LabVIEW RT—MAX automatically selects this item when you install the LabWindows/CVI NetworkVariable for RT component.Configuring System Settings1.Select the System Settings tab to configure system-level settings for theRT target.e the Timezone option to configure time zone and daylight savingsettings for the RT target. You can use this setting with time and date functions to provide accurate time information, relative to the time zone setting.3.Configure the Locale option to match the language you use for strings inyour RT application. This option is available only when you install the Language Support for LabVIEW RT component on the RT target.This option determines the code page that LabWindows/CVI uses when processing strings containing ASCII characters above 127 or multibyte characters.Configuring I/OYou must configure any National Instruments I/O devices before you can target them from a LabWindows/CVI RT application. For information about how to correctly configure I/O devices, refer to the documentation for that hardware.© National Instruments Corporation5Getting Started with LabWindows/CVI Real-TimeConfiguring an RT ProjectAfter you configure the RT target, you can create an RT application on the host computer and then run the application on an RT target. The applications that you create with the LabWindows/CVI Real-Time Module are DLLs. Complete the following steps to create a DLL and specify an RT target directly from LabWindows/CVI.1.Create a project in LabWindows/CVI using RTmain instead of main asthe entry point function for the program. Select Edit»Insert Construct»RTmain to insert the RTmain code into the program source.2.Select Build»Configuration»Debug or Build»Configuration»Releaseto specify the active configuration for the project.3.Select Build»Target Type»Dynamic Link Library to configure theproject to generate a DLL.4.Select Build»Target Settings to open the Target Settings dialog box.Select Real-time only in the Run-time support option. If you specify this option, LabWindows/CVI does not link to the entire set ofLabWindows/CVI libraries but instead links to only those librariessupported on an RT system.5.Configure other options in the Target Settings dialog box and click OKto exit the dialog box.6.Select Build»Create Debuggable Dynamic Link Library or Build»Create Release Dynamic Link Library to create the DLL.You also can use a project template to create an RT DLL. The project template includes basic settings for RT projects described in the preceding section. To select a project template, select File»New»Project from Template. In the New Project from Template dialog box, select Real-Time Target Application.Specifying an RT TargetComplete the following steps to select the RT target on which to run your RT application.1.Select Run»Select Execution Target for Debugging to view a list ofpreviously configured RT targets. Select the RT target you want to use from the list, if it is available.2.To configure a new RT target, select Run»Select Execution Target forDebugging»New Execution Target.3.In the New Real-Time Execution Target dialog box, enter the computername or IP address of the RT target in the Hostname/IP Address option and click OK to exit the dialog box.Getting Started with LabWindows/CVI © National Instruments Corporation 7Getting Started with LabWindows/CVI Real-Time Running an RT ApplicationSelect Run»Debug Project to run your RT application.NoteIf you select Run»Configuration»Release ,LabWindows/CVI displays a warning message. Click Continue to download and run the release DLL on the RT target. LabWindows/CVI automatically builds the DLL and downloads the DLL and any DLLs that are statically linked to it onto the specified RT target. LabWindows/CVI places the files that it automatically downloads in the NI-RT\CVI\temp folder. LabWindows/CVI empties the folder when you reset the RT device.While you run your RT application, LabWindows/CVI displays a <<Running on target >> menu in the upper left corner of theLabWindows/CVI environment. The menu contains the following options, which you can use for debugging and for shutting down the RT application:•Toggle Breakpoint —Turn on or turn off a breakpoint on the selected line.•Break Execution —Suspend execution of the program.•Simulate RT Shutting Down —End program execution. This option causes the RTIsShuttingDown function to return 1, giving the RT application an opportunity to run any necessary cleanup code and exit. The RT target does not reboot.•Abort Execution and Reboot Target —End program execution and reboot the RT target. The application cleanup code is not guaranteed to finish running before the RT target reboots.•Disconnect from RT target —Disconnect LabWindows/CVI from the RT target while the RT application continues running on the target. Once you disconnect from the RT target, you cannot reconnect LabWindows/CVI to the RT application that is running.Debugging an RT ApplicationIf you select Build»Configuration»Debug , you can debug the DLL from the LabWindows/CVI environment as you would debug any other application. For example, you can set breakpoints and watch expressions, step through code, view and edit variable values, and so on. For more information about debugging in LabWindows/CVI, refer to the Using LabWindows/CVI»Debugging Tools section of the LabWindows/CVI Help.Using the Real-Time Execution Trace ToolkitThis version of the LabWindows/CVI Real-Time Module includes a 30-day full-featured evaluation of the Real-Time Execution Trace Toolkit.Use the Real-Time Execution Trace Toolkit to analyze the timing and execution of an RT application. Use the Execution Trace functions in the Real-Time Utility Library to capture the timing and execution data of functions and threads in applications running on an RT target. The Real-Time Execution Trace Tool displays the timing and event data, or trace session, on the host computer.In LabWindows/CVI, select Tools»Real-Time Execution Trace Tool to launch the Real-Time Execution Trace Tool. Refer to the LabWindows/CVI Help for more information about using the Real-Time Execution Trace Toolkit to analyze RT applications.Deploying an RT ApplicationWhen you finish developing your RT application, you can deploy it to an RT target. After you deploy the RT application, the RT application runs automatically every time the RT target reboots.Select Run»Install Program to Real-Time Execution Target to deploy your RT application. This option performs the following actions:•Checks that the release configuration of the DLL has been built; if not, LabWindows/CVI prompts you to build the DLL or cancel.•Deploys the release DLL and any statically linked DLLs to the NI-RT\CVI folder on the RT target.•Sets the release DLL as a startup DLL.•Displays a dialog box indicating that the DLL was copied and prompting you to reboot the RT target.If you have additional support files that you need to deploy, complete the following steps:1.Select Run»Manage Files on Real-Time Execution Target to launchthe LabWindows/CVI Real-Time File Copy Utility.2.Click Add Files and browse to any support files that your applicationrequires. The utility immediately copies the files to the NI-RT\CVIfolder on the RT target.3.Click Done when you finish adding support files.Getting Started with LabWindows/CVI Where to Go from HereRefer to the following resources for more information about the LabWindows/CVI Real-Time Module:•The LabWindows/CVI Real-Time Module Help section of the LabWindows/CVI Help includes conceptual information about real-time programming techniques, application architectures, and Real-TimeModule software features you can use to create real-time applications.Select Help»Contents in LabWindows/CVI to access theLabWindows/CVI Help.•Use the NI Example Finder, available by selecting Help»Find Examples in LabWindows/CVI, to browse or search for example programs. You also can access the example programs from the samples\CVIsamples\realtime directory.© National Instruments Corporation9Getting Started with LabWindows/CVI Real-TimeNational Instruments, NI, , and LabVIEW are trademarks of National Instruments Corporation. Refer to the Terms of Use section on /legal for more information about National Instruments trademarks. The mark LabWindows is used under a license from Microsoft Corporation. Windows is a registered trademark of Microsoft Corporation in the United States and other countries. Reliance™ is a trademark of Datalight, Inc. Copyright 1989-2008 Datalight, Inc., All Rights Reserved. Datalight® is a registered trademark of Datalight, Inc. Other product and company names mentioned herein are trademarks or trade names of their respective companies. For patents covering National Instruments products/technology, refer to the appropriate location: Help»Patents in your software, the patents.txt file on your media, or the National Instruments Patent Notice at /patents.© 2007–2008 National Instruments Corp. All rights reserved.374686B-01Oct08。
labwindows-CVI-教程
l a b w i n d o w s-C V I-教程本页仅作为文档封面,使用时可以删除This document is for reference only-rar21year.MarchLabWindows/CVI基础教程序言LabWindows/CVI是National Instruments公司推出的一套面向测控领域的软件开发平台。
它以ANSI C为核心,将功能强大,使用灵活的C语言平台与数据采集,分析和表达的测控专业工具有机地接和起来。
它的集成化开发平台,交互式编程方法,丰富的控件和库函数大大增强了C语言的功能,为熟悉C语言的开发人员建立检测系统,自动测量环境,数据采集系统,过程监控系统等提供了一个理想的软件开发环境。
本教程面向的是那些从未使用过LabWindows/CVI的读者,但是假设读者以有了C语言的基础并且熟悉Windows 2000/9x/NT操作系统。
在每一章节的学习中,作者都是通过一个具体的实例让读者迅速的掌握本章的知识点;而不是长篇大论,述及边枝细叶,反而使读者望而却步,只见树木,不见森林。
想信通过对本教程的学习,读者可迅速掌握LabWindows/CVI编程思想及步骤,为读者日后进一步学习打下基础。
本书约定:“File>>Page Setup>>Options”File 这一种黑色斜体字是指多级菜单名,按扭名,窗口名或者是关键性词汇。
“>>”是指打开一个多级菜单或对话框。
如:File>>Page Setup>>Options是指你首先打开File 菜单,然后选择Page Setup项,最后从弹出的对话框中选择Options 项。
“说明:通过这种方式你可以修改Panel顶端所显示的名字。
”该种字体所写的文字是值得读者注意并记忆的内容。
“该椭圆形框所框住的内容是读者需修改的地方。
第一部分 CVI快速入门本部分通过编制一个简单的LabWindows/CVI程序,使读者对CVI编程环境,思想及步骤有一初步的认识。
Labwindows CVI2013安装教程
Labwindows/CVI 2013详细安装图文教程1.下载安装包,如下图共3个文件。
2.安装软件,按以下步骤进行。
注:如果提示需要.net framework 4.0按提示下载安装即可,如果你的电脑有安装有就不会出现这个提示。
大部分软件的安装路径都不支持中文路径,请尽量避免软件安装在中文路径下。
耐心等待,根据个人电脑配置不同需要的时间也不同,我的要半小时。
3.下面进入最重要的一步,就是软件激活了!
找到NI License Activator v1.1.exe激活工具打开并按下面的步骤进行激活。
在需要激活的版本和模块上依次点鼠标右键,出现Activate再点鼠标左键确认,直到出现绿色图标,表示已经激活。
请选择自已需要的版本进行激活,我只是举例说明激活步骤一般Base Package和Full Development System(Debug only)版本不需要激活,
这两个版本功能要弱一些,Full Development Systems要激活。
在开始---程序处点击NI License Manager,确认激活情况
到此激活完成,慢慢享用吧!
注:模块的安装激活在此不再讲述,因为模块很多,每个人需求的也不同。
安装激活方法同上(先安装后用激活工具激活)。
NI-LabwindowsCVI串口编程-RS232--教程
4.4.1 RS-232C 接口介绍在介绍具体的RS-232 函数库之前,本节先简要介绍RS-232C 接口。
美国电子工业协会(EIA)公布的RS-232C 是用的最多的一种串行通信标准,它是从CCITT 远程通信标准中导出的,用于数据终端设备(DTE)和数据通信设备(DEC)之间的接口。
该标准包括按位串行传输的电气和机械方面的规定。
一、接口信号RS-232C 的机械指标规定:RS-232C 接口通向外部的连接器(插针插座)是一种“D”型25 针插头。
由于25 芯中有许多是不常用的,IBM-PC 对其进行了简化,取了其中的常用的9 芯,构成了9 芯RS-232C 串行接口,使其成为一种事实上的串行接口标准配置。
RS-232C 的“D”型9 针插头引脚定义如图4-13 所示。
RS-232C 标准接口中的主要信号是“发送数据”和“接收数据”,它们用来在两个系统或设备之间传送串行信息。
对于异步通信,传输的串行位数据信息的单位是字符。
二、数据传送格式和电气特性图4-14 示出了RS-232C 以位串行方式传输数据的格式,这是微机系统中最通用的格式。
7 位ASCII 码数据的连续传送由最低有效数字位开始,而以奇偶校验位结束。
应当指出,RS-232C 标准接口并不限于ASCII 数据,事实上还可有5 到8 个数据位,后加一奇偶校验位,并有1 或2 位停止位。
在电性能方面,这一标准使用负逻辑。
逻辑1 电平是在-15V 到-5V 范围内,逻辑0电平则在+5V 到+15V 范围内。
它要求RS-232C 接收器必须能识别低至+3V 的信号作为逻辑0,而识别高至-3V 的信号作为逻辑1,这意味着有2V 的噪声容限。
RS-232C 进行数据传输的最高速率为20KB/S,通信距离最长为15m。
4.4.2 RS-232 函数库概述LabWindows/CVI 6.0 提供的RS-232 函数库主要包括以下几类函数:串行口打开/关闭(Open/Close)函数,串行口输入/输出(Input/Output)函数,串行口控制(Control)函数,串行口状态查询(Status)函数,串行口事件处理(Callbacks)函数。
LabwindowsCVI8.5安装步骤详解
Labwindows/CVI8.5 安装详解
1、双击安装文件中setup.exe文件,填写基本信息。
图1 填写基本信息
安装过程中需填写一个序列号,此时运行ViewFile文件夹下的keygen文件,点击Generate产生一个序列号,同时需点击Create license file创建一个license 文件(注意该lic文件必须保存在英文路径下,如保存在C:\\1.lic),如图2、图3。
图2 产生一个序列号图3 产生一个lic文件
2、将图2产生的序列号copy到图1 seiral Number处,点击下一步。
图4 修改安装路径,也可不修改,默认安装C盘
继续点下一步,选择接受条款,即可安装
图5 接受,一直点下一步
图6 安装进行中,等待下一步提示3、安装过程中,有以下提示,选择Later
图7
图8 将Activate 前面的勾去掉,稍后用lic激活
4、接下来重启计算机,运行license manager-即NI许可证管理器(位置在:开始->程序->national instruments->NI license manager)。
按提示使用由图3生成的.lic 文件即可。
图9
进入管理界面,选项-安装许可证文件,选择刚刚生成的1.lic文件,即可。
图10
5、安装完毕,打开NI CVI软件,如下:
图11
至此,若不提示剩余试用天数,表示Labwindows/CVI8.5 已成功安装至计算机,接下来请尽情享受该款强大软件带给你的开发快感吧。
LabWindowsCVI库函数的使用
LabWindows/CVI库函数的使用一、实验目的1、进一步熟悉CVI的集成开发环境2、进一步学习仪器面板中控键的使用3、学习CVI库函数使用方法4、学习用CVI库函数进行频谱分析的步骤二、实验内容1、编写一个波形显示程序,要求根据输入的幅值和周期数显示正弦波;根据输入的幅值和占空比显示方波。
2、制作一个简单仪器面板:要求有两个图形控件,用来显示图形;四个数字控件,分别用来输入正弦波幅值、周期以及方波的幅值、占空比;五个命令控件,分别用来启动程序产生正弦波、产生方波,清楚屏幕上显示的图像和退出程序。
3、利用CVI的代码生成工具生成你制作的一起面板的程序框架。
4、在用户程序中添加相应程序,运行后观察程序执行的结果。
三、程序源代码#include <analysis.h>#include <cvirte.h>#include <userint.h>#include "guweiming.h"static int panelHandle;double a,b,c,d;int main (int argc, char *argv[]){if (InitCVIRTE (0, argv, 0) == 0)return -1; /* out of memory */if ((panelHandle = LoadPanel (0, "guweiming", PANEL)) < 0) return -1;DisplayPanel (panelHandle);RunUserInterface ();DiscardPanel (panelHandle);return 0;}int CVICALLBACKQINGPINGCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:DeleteGraphPlot (panelHandle, PANEL_GRAPH_2, -1, V AL_IMMEDIATE_DRAW);break;}return 0;}int CVICALLBACK FANGBOCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){ double wave[512] ;double phase=120,*p;p=&phase;switch (event){case EVENT_COMMIT:SquareWave (512, c, 7.8125e-3, p, 50.0, wave);PlotWaveform (panelHandle, PANEL_GRAPH, wave, 512,V AL_DOUBLE, 1.0, 0.0, 0.0, d, V AL_THIN_LINE, V AL_EMPTY_SQUARE, V AL_SOLID, 1, V AL_RED);break;}return 0;}int CVICALLBACK QINGPING2Callback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:DeleteGraphPlot (panelHandle, PANEL_GRAPH, -1, V AL_IMMEDIATE_DRAW);break;}return 0;}int CVICALLBACK TUICHUCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:QuitUserInterface (0);break;}return 0;}int CVICALLBACK FTCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_FT, &a);break;return 0;}int CVICALLBACK ZQCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_ZQ, &b);break;}return 0;}int CVICALLBACK FZCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event)case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_FZ, &c);break;}return 0;}int CVICALLBACK ZKBCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_ZKB, &d);break;}return 0;}int CVICALLBACK ZHENGXIANBOCallback (int panel, int control, int event,void *callbackData, int eventData1, int eventData2){ double Waves[512] ;switch (event){case EVENT_COMMIT:SinePattern (512, a, 0.0, b, Waves);PlotWaveform (panelHandle, PANEL_GRAPH_2, Waves, 512, V AL_DOUBLE, 1.0, 0.0, 0.0, 1.0, V AL_THIN_LINE, V AL_EMPTY_SQUARE, V AL_SOLID, 1, V AL_RED);break;}return 0;}四、思考题1.简述Panel Handle 和Control ID 参数的作用;答:Panel Handle 这一参数由LoadPanel 库函数设置,存入的是已存储的面板文件这一对象。
LabWindowsCVI基础指导教程
LabWindows/CVI基础指导教程1. 简介LabWindows/CVI是一种基于C语言的集成开发环境(IDE),广泛应用于数据采集、实验控制和测试自动化等领域。
本教程旨在为初学者提供关于LabWindows/CVI的基础指导,包括环境安装、项目创建、界面设计和编程等方面的内容。
2. 环境安装在开始使用LabWindows/CVI之前,我们首先需要安装LabWindows/CVI的运行环境。
按照以下步骤进行安装:1.下载LabWindows/CVI安装程序,并运行安装程序。
2.在安装程序中选择安装路径,并点击“下一步”进行安装。
3.根据提示完成安装过程。
安装完成后,我们就可以开始创建LabWindows/CVI项目了。
3. 项目创建LabWindows/CVI使用项目(Project)的方式来组织和管理代码。
下面是创建新项目的步骤:1.打开LabWindows/CVI IDE。
2.点击“文件”菜单,并选择“新建项目”。
3.在弹出的对话框中选择项目类型和保存路径,然后点击“确定”。
4.在新建项目的基础上,可以添加文件、配置编译选项等。
4. 界面设计LabWindows/CVI提供了UI工具箱,可以通过拖拽控件来设计界面。
下面是界面设计的基本步骤:1.打开项目。
2.点击“窗体”菜单,并选择“添加窗体”。
3.在窗体设计器中,可以拖拽控件到窗体中,并调整位置和大小。
4.可以通过属性编辑器来设置控件的属性和事件。
界面设计完成后,我们可以进行程序的编程。
5. 编程LabWindows/CVI使用C语言进行编程。
下面是编程的基本步骤:1.打开窗体设计器,选择需要编写代码的控件。
2.双击控件,进入控件的事件处理函数。
3.在事件处理函数中编写代码,实现相应的功能。
4.可以使用LabWindows/CVI提供的函数库来完成各种操作,如数据采集、图形绘制等。
除了事件处理函数,我们还可以创建其他类型的函数来实现更复杂的功能。
Labwindows CVI2013安装教程
Labwindows/CVI 2013详细安装图文教程1.下载安装包,如下图共3个文件。
2.安装软件,按以下步骤进行。
注:如果提示需要.net framework 4.0按提示下载安装即可,如果你的电脑有安装有就不会出现这个提示。
大部分软件的安装路径都不支持中文路径,请尽量避免软件安装在中文路径下。
耐心等待,根据个人电脑配置不同需要的时间也不同,我的要半小时。
3.下面进入最重要的一步,就是软件激活了!
找到NI License Activator v1.1.exe激活工具打开并按下面的步骤进行激活。
在需要激活的版本和模块上依次点鼠标右键,出现Activate再点鼠标左键确认,直到出现绿色图标,表示已经激活。
请选择自已需要的版本进行激活,我只是举例说明激活步骤一般Base Package和Full Development System(Debug only)版本不需要激活,
这两个版本功能要弱一些,Full Development Systems要激活。
在开始---程序处点击NI License Manager,确认激活情况
到此激活完成,慢慢享用吧!
注:模块的安装激活在此不再讲述,因为模块很多,每个人需求的也不同。
安装激活方法同上(先安装后用激活工具激活)。
LabWindowCVI安装方法
LabWindows/CVI 2009你下载完成后,你看到的下载文件,如下图所示!需要解压缩这个文件,在该文件上点击右键,选择加“压缩到NILWCVI2009SP1”,这样你在你的电脑上多了一个叫“NILWCVI2009SP1”的文件夹!如下图所示打开“NILWCVI2009SP1”文件夹,选择文件夹下的setup.exe,双击打开该文件,这个时候会出现LabWindows的安装界面!如下图所示点击next按钮,进行下一步安装!这是会出现让你输入软件的序列号,这个没有怎么获取呢?如下图所示关于序列号的获取方法可以参看我的另外一篇经验文章!里面有详细的描述,这里就不在赘述了!文章链接为:/article/597035521808e98fc0074031.html根据上一步的操作获取到序列号之后,将序列号粘贴到对应的框中,点击next按钮,会出现亲切的选择安装路径的界面了!注意:这时候不要关闭序列号生成器,因为后边的激活操作还需要它生成Lic文件!一直点击next按钮,直到出现下图所示的界面,这个时候注意:你需要取消掉这个勾,取消更新检测!因为更新检测的时间挺长的,没有必要检测!!然后点击next按钮执行安装下一步,这个时候就可以真正的进行安装了,这时你会看到如下图的安装进度条,看到这个,说明你的软件正在安装过程中了,这个时候你可以去喝口茶,等安装完之后,只差最后的一步就可以完美激活你的软件了!O(∩_∩)O哈哈~END注意事项序列号生成之后,这时不要关闭序列号生成器,因为后边的激活操作还需要它生成Lic文件!如果你已经关闭了序列号生成器,那也不要紧,这时候你执行激活的时候,就要非常认真的看我写的经验了哦!要不接下来的激活会很费劲!LabWindows/CVI2009 激活1浏览:3842|3更新:2013-04-12 15:291),安装CVI_FDS_2009 ,到需要注册号时暂停。
2),运行注册机,选择“Full Development System”,点击“生成”得到系列号。
LabWindowsCVI教程数据库应用程序的设计主讲乔立岩精品文档17页
16.03.2020
1/15
第十讲 数据库应用程序设计
一条记录(行)
一个字段(列)
• •
16.03.2020
表里的数据本身并无顺序。在用SELECT语句从表 中回收数据时,发生排序、分组和其它数据操作。
表中每列都有一个数据类型。相对于不同的数据库 管理系统(DBMS),可用的数据类型定义也是存
在差异的。
11/15
第十讲 数据库应用程序设计
• 步骤4. 断开SQL连接
▪ SQL操作结束后,应断开SQL连接来释放系统资源。 这个步骤在任何方向上取值时都是特别重要的,它可 保证工具包适当地关闭并删除临时登记文件。
• 步骤5. 断开数据库
▪ 全部数据库操作结束时,应断开通过SQL建立的数据 库连接,以适时地释放系统资源。
• 可获取SELECT语句返回的字段名和数据类型。
• 不用SQL语句即可创建表并选择、插入、更新 和删除记录。
16.03.2020
9/15
第十讲 数据库应用程序设计
8. SQL Toolkit数据库操作基本步骤
• 步骤1. 连接数据库
执行SQL语句前,必须建立数据库连接。LabWindows/CVI SQL工具包支持单个数据库或多个数据库的多个同步连接。
▪ 使用SELECT语句必须将选择的字段绑定到程序中的 变量上。接着用取值函数获取所选记录。每次调用取 值函数,工具包将列变量拷贝到在程序中绑定的变量。 更新行或创建行时还可用绑定的变量,即更新行或创 建行时将新值拷贝到绑定的变量并随后调用适当的函 数,将程序中的数据添加到数据库对应的字段。
16.03.2020
第十讲 数据库应用程序设计
1. 数据库的基础知识
LabWindows CVI Easy tab control使用教程
LabWindows/CVI中EasyTab Control的使用教程2016年12月4日,星期日狄阁老最近在使用国产板卡过程中发现,很多板卡的测试软件都用到了类似于tab的控件,但是子界面很多,又要团队完成的,如果还使用Tab控件就非常麻烦。
在CVI使用中,发现CANVAS 控件和easy tab.fp可以完成Tab控件的任务,下面开始介绍如何使用Easytab control先新建一个工程,再新建一个主界面和三个子界面,在主界面上添加一个CANVAS控件,再右下角load instruments,找到CVI安装目录下的Toolslib\custctrl下的easytab.fp,再在工程下添加这个fp。
首先介绍一下easytab.fp双击这个fp.可以看到这个fp内的函数,最重要的两个函数:1)EasyTab_ConvertFromCanvas (界面句柄, CANVAS的ID);2)EasyTab_LoadPanels (参数,参数,…..);EasyTab_ConvertFromCanvas函数简单,重点来说EasyTab_LoadPanels参数1:Panel 来自下面这行代码if ((panelHandle = LoadPanel (0, "EasyTabControlTest.uir", PANEL)) < 0) return -1;参数2:Tab Control 来自这行代码tabCtrl = EasyTab_ConvertFromCanvas (panelHandle, PANEL_CANVAS);参数3:Row该参数设置为1参数4:File Name指工程的.uir参数5:Calling Module Handle一般设置为常量:__CVIUserHInst参数6:Panel IDs and Handle Pointers该参数在要设置子界面的ID和句柄例如:三个界面EasyTab_LoadPanels (panelHandle, tabCtrl, 1, "EasyTabControlTest.uir", __CVIUserHInst,PANEL1, &panel1, PANEL2, &panel2, PANEL3, &panel3, 0);运行后的界面:代码如下:#include <formatio.h>#include "easytab.h"#include <cvirte.h>#include <userint.h>#include "EasyTabControlTest.h"static int panelHandle,tabCtrl,ActPan;int panel1,panel2,panel3,panel4;int main (int argc, char *argv[]){if (InitCVIRTE (0, argv, 0) == 0)return -1; /* out of memory */if ((panelHandle = LoadPanel (0, "EasyTabControlTest.uir", PANEL)) < 0)return -1;tabCtrl = EasyTab_ConvertFromCanvas (panelHandle, PANEL_CANVAS);EasyTab_LoadPanels (panelHandle, tabCtrl,1, "EasyTabControlTest.uir",__CVIUserHInst, PANEL1, &panel1, PANEL2, &panel2, PANEL3, &panel3, 0);EasyTab_SetAttribute (panelHandle, tabCtrl,ATTR_EASY_TAB_STRETCH_TO_FIT, 0);//InstallPopup(panelHandle);DisplayPanel (panelHandle);RunUserInterface ();DiscardPanel (panelHandle);return 0;}//退出事件int CVICALLBACK QuitCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT:QuitUserInterface (0);break;}return 0;}//切换TAB的事件int CVICALLBACK TabCtrlCallBack (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){char ActPanOut[100];switch (event){case EVENT_TAB_CHANGED:EasyTab_GetAttribute (panelHandle, tabCtrl ,ATTR_EASY_TAB_ACTIVE_PANEL, &ActPan);//EasyTab_GetAttribute (panelHandle, tabCtrl,ATTR_EASY_TAB_META_FONT, mm);Fmt (ActPanOut, "激活了第%d子界面", ActPan-1);SetCtrlVal (panelHandle, PANEL_STRING, ActPanOut);break;}return 0;}int CVICALLBACK AutosizeCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){int status;switch (event){case EVENT_COMMIT:status=EasyTab_AutoSize (panelHandle, tabCtrl);break;}return 0;}int CVICALLBACK AddPanelCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){switch (event){case EVENT_COMMIT://&panel4 = NewPanel (panelHandle, "xx", 0, 0, 350, 500);EasyTab_AddPanels (panelHandle, tabCtrl, 1,PANEL4,0,0);break;}return 0;}//移除tabint CVICALLBACK deltetCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)int panelRemove;switch (event){case EVENT_COMMIT:GetCtrlVal (panelHandle, PANEL_RING,&panelRemove ) ;switch (panelRemove){case 0:EasyTab_RemovePanel (panelHandle, tabCtrl, panel1);break;case 1:EasyTab_RemovePanel (panelHandle, tabCtrl, panel2);break;case 2:EasyTab_RemovePanel (panelHandle, tabCtrl, panel3);break;default:break;}break;}return 0;}int CVICALLBACK SetFontCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){char *new="";switch (event){case EVENT_COMMIT:CreateMetaFont (new, VAL_DIALOG_META_FONT, 16, 1, 0, 0, 0); EasyTab_SetAttribute(panelHandle, tabCtrl,ATTR_EASY_TAB_META_FONT, new);break;}return 0;}。
LabWindowsCVI教程
LabWindowsCVI教程第⼀章 : LabWindows/CVI1.1 LabWindows/CVI1.1.1 LabWindows/CVI概述LabWindows/CVI是美国NI(National Instruments)公司开发的⾯向计算机测控领域的虚拟仪器软件开发平台,可以在多种操作系统(WindowsXP/Vista/7、Mac OS和Unix)下运⾏。
LabWindows/CVI 是为C 语⾔程序员提供的集成开发环境(IDE),在此开发环境中可以利⽤C语⾔及其提供的库函数来实现程序的设计、编辑、编译、链接、调试。
使⽤LabWindows/CVI 可以完成以下但不限于以下⼯作:·交互式的程序开发;·具有功能强⼤的函数库,⽤来创建数据采集和仪器控制的应⽤程序;·充分利⽤完备的软件⼯具进⾏数据采集、分析和显⽰;·利⽤向导开发IVI 仪器驱动程序和创建ActiveX 服务器;·为其它程序开发C ⽬标模块、动态连接库(DLL)、C 语⾔库。
图 1‐1 LabWindows/CVI界⾯LabWindows/CVI 的功能强⼤在于它提供了丰富的函数库。
利⽤这些库函数除可实现常规的程序设计外,还可实现更加复杂的数据采集和仪器控制系统的开发。
数据采集。
IVI库、GPIB/GPIB 488.2库、NI-DAQmx库、传统的NI-DAQ库、RS-232库、VISA库、VXI库以及NI-CAN库。
数据分析。
格式化IO库、分析库以及可选的⾼级分析库。
GUI库。
使⽤LabWindows/CVI 的⽤户界⾯编辑器可以创建并编辑图形⽤户界⾯(GUI),⽽使⽤LabWindows/CVI 的⽤户界⾯库函数可以在程序中创建并控制GUI。
此外,LabWindows/CVI为GUI ⾯板的设计,准备了许多专业控件,如:曲线图控件、带状图控件、表头、旋钮和指⽰灯等,以适应测控系统软件开发的需求,利⽤这些控件可以设计出专业的测控程序界⾯。
LabWindows-CVI安装教程
1.启动setup.exe.
2.打开LabWindows-CVI 9-0 Evaluation\Crack下keygen.exe。
点击Generate,随后copy生成
的serial number到上图对应的位置。
最后点击Create license file,将生成的文件保存到你知道的位置。
(此处默认文件名为1.lic,后续有用)
3.接下来选择文件的安装位置。
(安装路径上不要有中文),点击Next。
4.再次选择安装路径。
点Next。
5.之后会出现软件安装接受协议。
一直点击Next即可。
(因为我电脑里面已经安装,不会
出现后续的画面,所以没有图片展示)最终安装开始。
6.安装完成后,点击Finish,出现安装完成的祝贺信息。
7.点击Next,在出现的方面中选择重新启动Restart。
完成安装过程。
8.重启电脑后,选择National Instruments下的NI License Manager。
9.在选项中点击安装许可证文件。
然后找到1.lic文件。
软件激活完成。
LabWindowsCVI教程用户图形界面设计
带状图控件( )
数字图控件( )
图片控件()
树形控件()
定时器控件() 画布控件()
表格控件()
分隔控件()
分页控件()
定制控件( )
通用控件操作函数:
( , , *); (, , );
( , , ...); (, , 5.0);
பைடு நூலகம்
控件
技术简介 技术是指宽松定义的、基于组件对象模型()的
技术集合。它是基于已经存在的(对象链接与 嵌入)技术,通过把桌面系统“对象共享”的 范围扩展到整个,以使得构造这类新应用程序 成为可能。 定义了创建、配置和使用应用程序的规则。它 是一个二进制标准,包含了一系列规则,目的 是构建与语言无关的,面向对象的应用程序。
文档——在容器中(如的面板)查看文档。例如,可以把 一个 文档或电子表格放在的面板中显示。
控件
控件是的外部组件,可以象的内部控件一样使 用。
设计带有控件的程序
选择控件 :在窗口选择>> ,选择 选项,在控 件列表中选择需要的控件,单击按钮。
设置控件属性:双击控件,也可以点击编辑控 件对话框中的“ ”按钮,编辑控件特性页。
( ); ();
( ); = ();
( , [], ); = (, "文件", -1);
(, ,
[], , , , *);
= (, , "打开...", -1, 0, , 0);
( , ); = (, );
……
4. 控件设计 5. 控件种类: 6. 数值型():数值控件,颜色选择控件,数值滑动条
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第一章 : LabWindows/CVI1.1 LabWindows/CVI1.1.1 LabWindows/CVI概述LabWindows/CVI是美国NI(National Instruments)公司开发的面向计算机测控领域的虚拟仪器软件开发平台,可以在多种操作系统(WindowsXP/Vista/7、Mac OS和Unix)下运行。
LabWindows/CVI 是为C 语言程序员提供的集成开发环境(IDE),在此开发环境中可以利用C语言及其提供的库函数来实现程序的设计、编辑、编译、链接、调试。
使用LabWindows/CVI 可以完成以下但不限于以下工作:·交互式的程序开发;·具有功能强大的函数库,用来创建数据采集和仪器控制的应用程序;·充分利用完备的软件工具进行数据采集、分析和显示;·利用向导开发IVI 仪器驱动程序和创建ActiveX 服务器;·为其它程序开发C 目标模块、动态连接库(DLL)、C 语言库。
图 1‐1 LabWindows/CVI界面LabWindows/CVI 的功能强大在于它提供了丰富的函数库。
利用这些库函数除可实现常规的程序设计外,还可实现更加复杂的数据采集和仪器控制系统的开发。
数据采集。
IVI库、GPIB/GPIB 488.2库、NI-DAQmx库、传统的NI-DAQ库、RS-232库、VISA库、VXI库以及NI-CAN库。
数据分析。
格式化IO库、分析库以及可选的高级分析库。
GUI库。
使用LabWindows/CVI 的用户界面编辑器可以创建并编辑图形用户界面(GUI),而使用LabWindows/CVI 的用户界面库函数可以在程序中创建并控制GUI。
此外,LabWindows/CVI为GUI 面板的设计,准备了许多专业控件,如:曲线图控件、带状图控件、表头、旋钮和指示灯等,以适应测控系统软件开发的需求,利用这些控件可以设计出专业的测控程序界面。
网络和进程间通信库。
动态数据交换(DDE)库、TCP库、ActiveX库、Internet 库、DIAdem连接库、DataSocket库等。
除此之外,用户可以在CVI中使用ANSI C库中的全部标准函数。
正式因为有了强大的库支持,所以在CVI中,完成绘制图 1‐2所示正弦函数波形的功能,只需要在main()函数中写三行代码:图 1‐2 CVI程序运行结果一旦提及NI公司,大家可能最先联想到的是NI公司推出的LabVIEW软件。
LabWindows/CVI与LabVIEW相比,主要应用在各种测试、控制、故障分析及信息处理软件的开发中,其更适合中、大型复杂测试软件的开发,是工程技术人员开发建立监测系统、自动测量环境、数据采集系统、过程监测系统的首选工具。
1.1.2 LabWindows/CVI安装要安装CVI,只需要根据CVI安装包里的“Release Notes.pdf”和“说明.txt”一步步完成安装即可。
安装完CVI后,我们有必要看一下,安装程序在我们计算机的磁盘中丢下了哪些东西。
表 1‐1 LabWindows/CVI主要目录及其内容目录名说明\bin LabWindows/CVI的库文件\extlib外部编译器使用的CVI库文件(只在Windows95/NT中使用)\fonts字体文件\include头文件\instr仪器模块\samples CVI开发例程\sdk SDK库文件(只在Windows95/NT中使用)\toolslib开发工具包和库文件\tutorial使用手册\vxd VXD实例开发模板\wizard CVI开发环境中的向导程序其中,samples文件夹中的例程可以使初学者迅速掌握CVI编程开发基本步骤。
bin 文件夹下的cvi.chm(也可以通过CVI开发环境中按F1打开)是学习CVI之路必不可少的参考文档。
1.2 寻根问底:开发环境对于一门学问的初学者来说,最希望搞懂的就是学的东西的本质是什么。
在前一小节中我们提到了,LabWindows/CVI是NI推出的一个基于C语言的集成开发环境(IDE,Integrated Development Environment)。
那么什么是开发环境呢,开发环境是怎么工作的呢?集成开发环境(IDE,Integrated Development Environment )是用于提供程序开发环境的应用程序,一般包括代码编辑器、编译器、调试器和图形用户界面工具。
集成了代码编写功能、分析功能、编译功能、调试功能等一体化的开发软件服务套。
所有具备这一特性的软件或者软件套(组)都可以叫集成开发环境。
如微软的Visual Studio系列,Borland 的C++ Builder系列等。
但我们自从学习C语言开始就与集成开发环境建立了不解之缘。
似乎在我们心中,C 语言就是VC/VS、VC/VS就是C语言、VC/VS就是编译器、编译器就是VC/VS。
虽然不可否认的是,IDE的出现大大的降低了软件开发的门槛,曾经帮助我们快速入门,但IDE过于友好的界面让人无需思考程序编译、运行的原理即可开始写自己的第一个HelloWorld程序。
所以,我们有必要了解IDE的工作模式,有必要了解IDE是怎么通过命令行去工作的。
命令行,看似简陋,却能让人专心于自己的事物,并搞清楚一个程序的来龙去脉。
Keil下的命令行工作方式已经在创新中心的《SST单片机实践教程》的“汇编语言工具链”一节中有了详细的介绍,下面通过一个实例介绍最常用的VC6.0的命令行工作方式。
在此之前,我们假设你至少已经用VC写过C语言,编译过工程,并对Windows下的命令行至少略知一二。
当然,如果你现在还不懂,赶紧利用Google等一切现代化的工具解除自己的疑惑。
例1 使用命令行完成用VC对下面简单的C语言程序的编译。
实验步骤(1) 将这段代码保存为.c文件(此处保存为main.c),并讲这段代码放在VC安装路径下的“VC98\Bin\”文件夹下。
启动命令行窗口,并将地址修改为当前地址(2) 敲入cl.exe main.c命令执行编译。
此时可能会弹出窗口,提示缺少文件“mspdb60.dll”,编译失败。
毕竟当前的命令行窗口没有标准VC的环境变量,所以编译程序cl.exe无法从当前的环境变量中找到mspdb60.dll。
(3) 在VC安装路径的“Common\MSDev98\Bin”目录中找到此DLL并复制到“VC98\Bin”文件夹下之后,按键盘方向键↑重新运行cl.exe main.c。
此时会提示找不到stdio.h文件。
在VC安装路径的“VC98\Include”目录中找到stdio.h之后,复制到“VC98\Bin”文件夹下。
图 1‐3 命令行编译main.c-提示找不到stdio.h(4) 同理,程序会依次提示找不到文件LIBC.lib、OLDNAMES.lib、kernel32.lib。
这些库文件都可以在VC安装目录下的“VC98\Lib”路径中找到。
(5) 再次运行,命令行提示编译成功。
图 1‐4 命令行编译main.c-编译成功(6) 在命令行中敲入main.exe。
“Hello,world!”是否显示出来了呢?图 1‐5 运行main.exe至此,聪明的你应该已经知道VC的IDE是如何依赖于安装包内的编译器CL.exe程序实现编译的功能了吧。
本小节旨在通过对大家熟悉的VC的IDE改用命令行进行编译的方式引导大家接触一个新的事物首先应该搞清楚其本质的思想,养成搞学问时喜欢刨根问底的好习惯。
除了编译器的功能外,集成开发环境IDE应该还带有调试器的功能。
限于篇幅,此处不再多过多探索,大家可以自行研究。
若对IDE感兴趣,大家还可以调用现有的编译器程序、调试器程序编写自己的IDE!1.3 C语言的魅力是不是在大家的印象里,C语言只能做那种char后面跟几个*,故意把人绕晕之后运行的时候还会弹出一个黑乎乎的窗口的程序?是不是在大家的印象里,C语言不能访问网络、不能播放声音、不能显示图片、不能跟硬件设备打交道、不能做GUI,即便做出来GUI也丑的很或者慢的很,更不能搞多线程之类的高端一点的玩意儿?是不是在大家的印象里,为了使用一个串口库,我们就必须丢掉C语言然后让C++甚至MFC闪亮登场?是不是在大家的印象里,C语言能做的事情,C++、Java、C#或者Python等等编程语言通通都能做到?而这些编程语言能做到的事情C语言就很难做到?如果一定要这么认为,那就大错特错了。
即便在编程语言更新换代如此之快的今天,我们也很难找出一个智能设备或者商业软件在开发的过程中未曾使用C语言过。
借助CVI以及CVI自带的丰富的函数库,C语言不仅能够做C++、C#、Java等可以做的事,有时还可以做的更快更好,甚至还可以做这些编程语言所不能做的事。
我们学校(华中科技大学)的论坛“白云黄鹤”的服务器端程序就是采用C语言开发的,没有使用现成的Web服务程序或者数据库管理程序(当时没什么IIS也没MySQL可以用),因此数据库通过不断对文件进行fread或者fwrite实现的。
第一次听说C语言还可以用来开发服务器程序,大家肯定不敢相信。
不过下面我们将以一个简单的实例来向大家证明,C语言真的可以写服务器端的程序,而且简单的超乎想象。
例2 使用C语言完成简单的Web服务器的功能。
实验步骤(1) 若您的计算机尚未安装Apache,请先安装Apache服务器。
若已安装Apache,请确保Apache程序处于运行状态。
(2) 在VC6.0中新建C语言工程,输入以下代码。
(3) 编译,并将编译后生成的可执行文件main.exe复制到Apache程序的cgi-bin 目录下。
(4) 在浏览器地址栏中输入http://localhost/cgi-bin/main.exe?HelloWorld图 1‐6 在浏览器中访问编译的程序并传入HelloWorld参数是不是见识到了C语言在网络开发中“初见端倪”的一面?上述例子其实是CGI(Common Gateway Interface,通用网关接口)的一个最简单的例子。
稍微详细一些的例子将会在第6 章“综合实例:远程环境参数检测系统”中见到。
如果你对C语言在开发CGI 程序感兴趣,也可以自行查找资料,编写一个更具实际价值的网络应用程序。
1.4 CVI开发环境初接触1.4.1 三步创建自己的Hello,world不管是学习一门新的语言,还是学习一个新的开发工具,大家的第一个程序都是Hello world。
所以,下面我们一步一步来,实现我们的Hello,world!1. 建立/保存工程运行LabWindows/CVI,初始状态的CVI会自动为我们建好一个新的工作空间Untitled.cws以及新的工程Untitled。