《毕业论文(设计)基于DLL 的虚拟仪器系统开发32248.doc》由会员分享,可在线阅读,更多相关《毕业论文(设计)基于DLL 的虚拟仪器系统开发32248.doc(7页珍藏版)》请在三一办公上搜索。
1、基于DLL的虚拟仪器系统开发 汤晓安 湖南长沙国防科技大学电子科学与工程学院405教研室摘 要本文在介绍最新技术虚拟仪器及其开发环境LabVIEW的特点的基础上,分析并实现了将LabVIEW与外部代码进行连接的高级技术之一动态链接库机制。实践表明,此机制高效、易行,是增强LabVIEW与其它Windows应用程序之间的数据共享能力的一条很好的途径。关键词虚拟仪器,LabVIEW,动态链接库,DLL1 引言美国国家仪器公司的创新产品基于G语言的开发环境LabVIEW的出现,使得“虚拟仪器”的思想为工业界所接受。所谓虚拟仪器,就是在通用计算机平台上,用户根据自己的需求定义和设计仪器的测试功能,其实
2、质是将传统仪器硬件和最新计算机软件技术充分结合起来,以实现并扩展传统仪器的功能。与传统仪器相比,虚拟仪器在智能化程度、处理能力、性能价格比、可操作性等方面均具有明显的技术优势。LabVIEW(Laboratory Virtual Instrument Engineering Workbench实验室虚拟仪器工程平台)是目前国际上首推应用最广的虚拟仪器开发环境之一,主要应用于仪器控制、数据采集、数据分析、数据显示等领域,并适用于Windows 3.1/ 95/98、 Windows NT、Macintosh、UNIX等多种不同的操作系统平台。与传统程序语言不同,LabVIEW采用强大的图形化语言
3、(G语言)编程,面向测试工程师而非专业程序员,编程非常方便,人机交互界面直观友好,具有强大的数据可视化分析和仪器控制能力等特点。使用LabVIEW开发环境,用户可以创建32位的编译程序,从而为常规的数据采集、测试、测量等任务提供了更快的运行速度。LabVIEW是真正的编译器,用户可以创建独立的可执行文件,能够脱离开发环境而单独运行。对于大多编程任务,LabVIEW通常能产生高效的代码。但LabVIEW亦存在不足,如,不适于或不擅长于完成大量数据处理的任务;不能进行系统调用实现底层操作(如,访问物理地址)等。在虚拟仪器系统开发中若遇到这类问题,就可利用LabVIEW所提供的与外部代码进行连接的机
4、制(如,动态链接库机制),将其自身无法或不易实现的任务通过能够或更适于完成此类任务的外部代码来实现。2 LabVIEW调用外部程序代码的途径之一 动态链接库机制2.1 动态链接库机制概述LabVIEW是一个功能强大的虚拟仪器开发环境,它完整地集成了与GPIB、VXI、RS-232、RS-485和内插式数据采集卡等硬件的通讯。LabVIEW还具有内置程序库,提供了大量的连接机制,通过DLLs、共享库、ActiveX等途径实现与外部程序代码或软件系统的连接。LabVIEW提供了4种调用外部程序代码的途径,其中动态链接库(Dynamic Link LibraryDLL)机制是从LabVIEW调用标准
5、共享库和用户自定义库函数的通用方法。具体实现时,是使用LabVIEW功能模板中“Advanced”子模板里的“调用库函数(Call Library Function)”结点。 “调用库函数结点”包括大量的数据类型和调用规范,使用它可调用大多数标准共享库和用户自定义库中的函数,包括:Windows 3.1/95/98/NT下的动态链接库(Dynamic Link Library)、Macintosh下的代码段(Code Fragment)、UNIX下的共享库函数(Shared Library Function)等。当用户需要调用的代码已经存在;或者用户比较熟悉Windows中动态链接库、Maci
6、ntosh中代码段、UNIX中共享库的创建过程时,“调用库函数结点”非常有用,此时使用它也最为合适恰当,因为库使用了对几个开发环境都适用的格式标准,故用户可以使用几乎任何开发环境去创建LabVIEW能够调用的库。2.2 动态链接库机制实现步骤设此处要实现:在Windows 98下,利用LabVIEW 5.1 (for Windows 95/98/NT)中的“动态链接库机制”调用一个DLL,此DLL返回机器的名称。1) 建立“调用库函数结点”新建LabVIEW程序“hostname.vi”,存至新建目录“d:temp”下,其前面板如下: 图1框图程序如下:图2其中,“Call Library F
7、unction”结点是通过选择功能模板中“Advanced”子模板里的 “Call Library Function”功能模块而产生的。此LabVIEW程序通过“调用库函数结点”调用一个DLL,此DLL将返回机器的名称,返回结果存至字符串指示量“Machine Name”中,而后将字符串常量“LabVIEW is running on ”与“Machine Name”相拼接,拼接之结果在字符串指示量“Message”中显示。2) 配置“调用库函数结点”双击框图程序窗口的“Call Library Function”结点,在弹出的对话框中对此“调用库函数结点”进行配置。其中:在“Library
8、Name or Path”一项中键入“d:temphostname.dll”(即,指明此结点所链接的DLL文件名,它由C源代码“hostname.c”编译而来);在“Function Name”一项中键入“MachineName”(即,指明与此结点相链接的DLL文件中的函数的名称);参数“return type”的类型选择“Void”;所增加的另一个参数“arg1”的类型选择“String”、字符串格式选择“String Handle”;3)编辑C源文件编辑C源文件“hostname.c”(存至目录“d:temp”下),其内容如下:/* include extcode.h which cont
9、ains the prototypes for the LabVIEW functions */#include #include #include BOOL WINAPI DllMain (HANDLE hDLL, DWORD dwReason, LPVOID lpReserved) return TRUE;/* This functions gets the computer name and returns it to LabVIEW */_declspec (dllexport) void MachineName(void *LVHandle) char computerNameMAX
10、_COMPUTERNAME_LENGTH+1;int compNameLength = MAX_COMPUTERNAME_LENGTH+1;/* Get computer name */GetComputerName(computerName, &compNameLength);/* Size LabVIEW handle to the correct size */DSSetHandleSize(LVHandle, compNameLength + 5);/* Copy the string size to the LabVIEW handle */*(int32 *)LVHandle =
11、compNameLength ;/* Copy the string to the LabVIEW handle */sprintf(*(char *)LVHandle)+4,%s,computerName);此程序首先了调用Windows的API函数“GetComputerName”获取机器名;然后调用LabVIEW的函数“DSSetHandleSize”来设置LabVIEW句柄之大小;最后将机器名长度(32位整型)、机器名(字符串型)依次写入句柄中。4) 编译C源代码将C源代码“d:temp hostname.c”编译成一个DLL文件“d:temphostname.dll”。可使用VC+
12、6.0 (for Windows 95/98/2000/NT),完成此编译工作。5)运行VI运行LabVIEW程序“hostname.vi”,结果如下: 图33. 结束语本文着重阐述并实现了将LabVIEW与外部代码进行连接的高级技术之一动态链接库机制,并给出了应用实例。由于在LabVIEW中引入了C语言的强大功能,从而提高了LabVIEW的整体性能。本方法已在LabVIEW 5.1 for Windows 95/98/NT及Visual C+ 6.0 for Windows 95/98/2000/NT 环境下实现。实践证明,此方法高效、易行,是增强LabVIEW与其它Windows应用程序之
13、间的数据共享能力的一条很好的途径。参考文献1. LabVIEW User Manual,National Instruments Corporation,19982G Programming Reference Manual,National Instruments Corporation,19983LabVIEW Advanced Course Manual,National Instruments Corporation,1997Development of DLL-Based Virtual Instrument SystemTang Xiao AnCollege of Electron
14、ic Science And Engineering, National Univ. of Defence Technology , Chang Sha, Hunan, 410073AbstractThis paper introduces virtual instrument and its development environmentLabVIEW,discusses and realizes the advanced technologyDynamic Link Library(DLL) ,which is one of the general methods for calling
15、external code from LabVIEW 。It has been proved that this method is efficient,practicable,and it is a good way improving the LabVIEWs capacity sharing data with other applications in Windows。Key wordsvirtual instrument,LabVIEW,Dynamic Link Library(DLL)邮编: 410073电话 0731-4576434(O)Email: xatangEditors
16、note: Judson Jones is a meteorologist, journalist and photographer. He has freelanced with CNN for four years, covering severe weather from tornadoes to typhoons. Follow him on Twitter: jnjonesjr 待添加的隐藏文字内容3(CNN) - I will always wonder what it was like to huddle around a shortwave radio and through
17、the crackling static from space hear the faint beeps of the worlds first satellite - Sputnik. I also missed watching Neil Armstrong step foot on the moon and the first space shuttle take off for the stars. Those events were way before my time.As a kid, I was fascinated with what goes on in the sky,
18、and when NASA pulled the plug on the shuttle program I was heartbroken. Yet the privatized space race has renewed my childhood dreams to reach for the stars.As a meteorologist, Ive still seen many important weather and space events, but right now, if you were sitting next to me, youd hear my foot ta
19、pping rapidly under my desk. Im anxious for the next one: a space capsule hanging from a crane in the New Mexico desert.Its like the set for a George Lucas movie floating to the edge of space.You and I will have the chance to watch a man take a leap into an unimaginable free fall from the edge of sp
20、ace - live.The (lack of) air up there Watch man jump from 96,000 feet Tuesday, I sat at work glued to the live stream of the Red Bull Stratos Mission. I watched the balloons positioned at different altitudes in the sky to test the winds, knowing that if they would just line up in a vertical straight
21、 line we would be go for launch.I feel this mission was created for me because I am also a journalist and a photographer, but above all I live for taking a leap of faith - the feeling of pushing the envelope into uncharted territory.The guy who is going to do this, Felix Baumgartner, must have that
22、same feeling, at a level I will never reach. However, it did not stop me from feeling his pain when a gust of swirling wind kicked up and twisted the partially filled balloon that would take him to the upper end of our atmosphere. As soon as the 40-acre balloon, with skin no thicker than a dry clean
23、ing bag, scraped the ground I knew it was over.How claustrophobia almost grounded supersonic skydiverWith each twist, you could see the wrinkles of disappointment on the face of the current record holder and capcom (capsule communications), Col. Joe Kittinger. He hung his head low in mission control
24、 as he told Baumgartner the disappointing news: Mission aborted.The supersonic descent could happen as early as Sunday.The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited c
25、loud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airl
26、iners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause), he can expect a lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet (22.7 miles/36.53 kilometers). Here, Fearless Felix will unclip. He will roll ba
27、ck the door.Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like divin
28、g into the deep end of a pool. It will be like he is diving into the shallow end.Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the mor
29、e dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main c
30、hute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartn
31、er still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).It might not be the moon, but Kittinger free fell from 102,800 feet in 1960 - at the dawn of an infamous space race that captured the hearts of many. Baumgartner will attempt to break that record, a feat that boggles the mind. This is one of those monumental moments I will always remember, because there is no way Id miss this.