虚拟仪器平台LabVIEW下USB总线的应用开发
- 格式:pdf
- 大小:166.42 KB
- 文档页数:4
基于LabVIEW与USB的虚拟仪器接口设计
魏勇;孙士平
【期刊名称】《现代电子技术》
【年(卷),期】2009(32)8
【摘要】当前虚拟仪器得到了广泛的应用,而USB总线具有即插即用,接口简单、传送速率高等特点.基于LabVIEW与USB的虚拟仪器接口设计将两者优势结合起来,势必顺应未来测拉仪器的发展.在此介绍一种接口设计方案,它采用VC++编写DLL,通过LabVIEW调用DLL,实现与USB设备进行通信.经过测试,该系统稳定可靠.基于LabVIEW和USB接口的数据采集系统具有灵活、可靠、经济等特点.
【总页数】4页(P163-165,169)
【作者】魏勇;孙士平
【作者单位】长江大学,电子信息学院,湖北,荆州,434023;长江大学,电子信息学院,湖北,荆州,434023
【正文语种】中文
【中图分类】TP311
【相关文献】
1.基于USB和LabVIEW的虚拟仪器的设计 [J], 车新生;何永杰;张中祥
2.基于数据采集板卡USB-4704和LabVIEW的虚拟仪器测试系统 [J], 贾振岗;李炜;陈川;漆静
3.基于USB和LabVIEW开发平台的虚拟仪器的设计 [J], 杨灵;周正达;张蕴玉
4.基于FT245RL的C8051F020与LABVIEW的USB接口设计 [J], 张立勋;韩建
海;赵书尚;魏幸梅
5.NI和TI携手合作,虚拟仪器技术将传统的电源监测效率提高10倍——基于NILabVIEW软件和USB硬件的TI电源优化DSP入门套件提供电源监测功能 [J], 无
因版权原因,仅展示原文概要,查看原文内容请购买。
LabVIEW⽤NI-488.2GPIB-USB-HS+建⽴通讯步骤LabVIEW⽤NI-488.2 GPIB-USB-HS+建⽴通讯步骤。
LabVIEW是⼀款⾮常⽅便的图形化上位机编程⼯具,在⾼校实验室和公司使⽤⽐较常见,NI-488.2 GPIB-USB-HS+是将GPIB接⼝转USB接⼝的控制器,本百度经验分享给⼤家如何使⽤LabVIEW通过NI-488.2 GPIB-USB-HS+控制器与仪器建⽴通讯连接。
⼯具/原料LabVIEWNI-VISA⼯具包NI-488.2 GPIB-USB-HS+控制器和驱动程序⽅法/步骤1.安装LabVIEW、NI-VISA和NI-488.2软件。
PC连接GPIB-USB接⼝⾄GPIB设备,安装新NI GPIB硬件设备前必须先安装NI-488.2驱动程序,否则Windows⽆法检测到硬件。
2.安装完成后桌⾯将出现NI MAX图标。
(NI-488.2驱动程序包含Measurement & Automation Explorer (MAX)⼯具,⽀持GPIB控制器。
MAX提供⼀系列⼯具对连接的仪器进⾏搜索、与设备进⾏通信,使得GPIB仪器检测和控制更为⽅便。
)3.单击桌⾯的MAX图标或通过开始>>所有程序>>National Instruments>>Measurement & Automation打开MAX浏览器。
4.确认GPIB设备是否正确连接,展开“我的系统(My System)”下的“设备和接⼝(Devices and Interfaces)”⼦⽬录,并选择⾃⼰的GPIB控制器,然后单击“扫描仪器(Scan for Instruments)”。
5.如GPIB设备可兼容SCPI,仪器扫描结束后名称和地址将出现在“属性”选项开的主窗⼝底部。
6.双击已识别的仪器(位于窗⼝底部)可访问仪器VISA属性(VISA Properties)。
:文件类型技术指南VISA是一个高 级API用来与仪器 控制总线进行通信。
它是平台独立、总线 独立、环境独立的。
也就是说,无论是使 用LabVIEW编 程在一台运行 Windows 2000的机器上与 USB设备进行通 信,还是使用C编程 在一台运行Mac OS X的机器上与 GPIB设备进行通 信,都可以使用同样 的API。
图1:VISA DDW硬件总线窗口您可以使用这个向导 创建供 PXI/PCI、 USB或IEEE 1394设备使用的 INF文件。
由于您 在为USB设备创建 驱动程序,选择 USB并点击下一 步。
VISA DDW基本设备信息 窗口打开,如图2所 示。
图2:VISA DDW基本设备信息 窗口2、在这个步骤 中,您必须知道 USB仪器所使用的 USB厂商ID和产 品ID。
这些数字在 您安装的时候能够识 别USB设备,在您 希望进行通信的时 候,可以对设备进行 寻址。
根据USB规范,所有数字必须是 16位的十六进制数 字,必须由设备制造 商提供。
如果您不知道USB 厂商ID和产品 ID,您可以将设备 插入计算机,让计算 机识别新设备得到这 些ID。
如果找到新 硬件向导打开,选择 取消。
打开控制面板 中的设备管理器,在 列表中找到您的设备,通常它在“其他 设备”中。
可能它会 带有黄色惊叹号标 记,表示这是一个未 知设备。
双击这个设 备打开属性。
选择详 细标签,确保“设备 实例ID”显示在属 性的下拉框中。
这样将会显示类似于图3 的字符串。
“VID_”和 “PID_”右边的 四个字符分别是您的 厂商ID和产品 ID。
写下设备的字 符串,关闭设备管理 器,从计算机上拔下 设备。
或者您还可以 联系您的设备厂商获得这些信息。
1.2. 3. 图3:从设备管理器 中找到厂商ID和产 品ID对于DAQPad- 6020E而言,厂 商ID和产品ID分 别是0x3923和 0x12C0。
如果 您的设备不是NI DAQPad- 6020E,厂商 ID和产品ID对于 您的设备而言是不同 的。
基于LabVIEW的USB接口上位机设计摘要:通用串行总线(USB)作为一种灵活的高速总线接口技术,非常适合作为主机和外设之问的通信接口,但其结构复杂。
本文以一个高速数据采集系统为例,阐述USB接口应用系统的总体设计思路,在实现方法上避开传统、复杂的NI数据采集卡,另辟蹊径地给出使用NI-VISA来驱动USB接口以应用LabVIEW进行上位机的设计。
关键词:USB RAW设备;NI-VISA;LabVIEW一、数据传输USB模块1.1概述CH375是一个 USB总线的通用接口芯片,支持USB-HOST 主机方式和 USB-DEVICE/SLAVE 设备方式。
在本地端,CH375 具有 8位数据总线和读、写、片选控制线以及中断输出,可以方便地挂接到单片机/DSP/MCU/MPU 等控制器的系统总线上。
在USB 主机方式下,CH375还提供了串行通讯方式,通过串行输入、串行输出和中断输出与单片机/DSP/MCU/MPU 等相连接。
CH375 的 USB 设备方式与 CH372 芯片完全兼容,CH375 包含了 CH372 的全部功能。
本手册中没有提供CH375在USB设备方式下的说明,相关资料可以参考 CH372 手册CH372DS1.PDF。
CH375的 USB主机方式支持常用的USB全速备,外部单片机可以通过CH375按照相应的 USB 协议与 USB 设备通讯。
CH375 还内置了处理 Mass-Storage 海量存储设备的专用通讯协议的固件,外部单片机可以直接以扇区为基本单位读写常用的USB 存储设备。
1.2 USB硬件电路图其中USB设备采用5V供电,其他采用3.3V供电,DE0板子上I/O口处有5V和3.3V,因此直接用DE0板子上供电。
二、LabVIEW的上位机2.1 数据采集概述高速的数据采集产品多通过PCI或PXI等总线实现与PC机之间的通信。
PCI总线的数据采集卡易受PC机机箱内高频干扰的影响,无法消除高频电磁干扰,从而降低了采样精度。
基于LabVIEW的USB实时数据采集处理系统的实现基于LabVIEW的USB实时数据采集处理系统的实现摘要介绍了以图形化编程语言LabVIEW为应用程序开发平台的USB数据采集处理系统的设计,并给出了LabVIEW对外部动态链接库的调用方法以及USB驱动程序的设计方法。
关键词USB LabVIEW 数据采集通用串行总线USB(Universal Serial Bus)作为一种新型的数据通信接口在越来越广阔的领域得到应用。
而基于USB接口的数据采集卡与传统的PCI卡及ISA卡相比具有即插即用、热插拔、传输速度快、通用性强、易扩展和性价比高等优点。
USB的应用程序一般用Visual C++编写,较为复杂,花费的时间较长。
由美国国家仪器(VI)公司开发的LabVIEW语言是一种基于图形程序的编程语言,内含丰富的数据采集、数据信号分析分析以及控制等子程序,用户利用创建和调用子程序的方法编写程序,使创建的程序模块化,易于调试、理解和维护,而且程序编程简单、直观。
因此它特别适用于数据采集处理系统。
利用它编制USB应用程序,把LabVIEW语言和USB总线紧密结合起来的数据采集系统将集成两者的优点。
USB总线可以实现对外部数据实时高速的采集,把采集的数据传送到主机后再通过LabVIEW的功能模块顺利实现数据显示、分析和存储。
1 USB及其在数据采集设备中的应用USB自在Comdex上亮相以来,已广泛地为各PC厂家所支持。
现在生产的PC几乎都配置了USB接口,Micro soft的Windows98、NT以及Mac OS、Linux等流行操作系统都增加对USB的支持。
USB具有速度快、设备安装和配置容易、易于扩展、能够采用总线供电、使用灵活等主要优点,应用越来越广泛。
一个实用的USB数据采集系统硬件一般包括微控制器、USB通信接口以及根据系统需要添加的A/D转换器和EPROM、SRAM 等。
为了扩展其用途,还可以加上多路模拟开关和数字I/O端口。
USB Instrument Control Tutorial OverviewThis tutorial is meant as a starting point for using NI-VISA to communicate with a USB device.It is not intended as a starting point for learning about USB architecture or the various protocols used in USB communication.After reading this tutorial,you should be able to install a USB device and use NI-VISA to communicate with that device,as long as you understand the device communication protocol.B and VISA BackgroundVISA is a high-level API used to communicate with instrumentation buses.It isplatform independent,bus independent,and environment independent.In otherwords,the same API is used regardless of whether a program is created tocommunicate with a USB device with LabVIEW on a machine running Windows2000or with a GPIB device with C on a machine running Mac OS X.USB is a message-based communication bus.This means a PC and a USB device communicate by sending commands and data over the bus as text or binary data.Each USB device has its own command set.You can use NI-VISA Read and Write functions to send these commands to an instrument and read the response from an instrument.Check with your instrument manufacturer for a list of valid commands for your instrument.Starting with version3.0,NI-VISA supports USB communication.Two classes of VISA resources are supported:USB INSTR and USB RAW.USB devices that conform to the USB Test and Measurement Class(USBTMC)protocol use the USB INSTR resource BTMC devices conform to a protocol that the VISA USB INSTR resource class can understand.No configuration is necessary to communicate with a USBTMC device.To communicate with a USBTMC instrument, refer to section3.For more information about the USBTMC specification,refer to the USB Implementers Forum Web page linked below.USB RAW instruments are any USB instrument other than those instruments that specifically conform to the USBTMC specification.If you are using a USB RAW device,follow the instructions in section2to configure NI-VISA to control your device.Contact your instrument manufacturer for details about the communication protocol and the command set your instrument uses.For specific information about the NI-VISA API,refer to the NI-VISA Help.This document is included with NI-VISA and is available through the link at the end of this tutorial.2.Configuring NI-VISA to Control Your USB DeviceThis section walks through the steps for configuring a USB RAW device to be controlled by NI-VISA3.0on a Windows-based computer.If you are using a USBTMC-compatible device,connect your device and skip to section2.3. At this point,NI-VISA already should be installed on your computer,and your USB device should not be connected.Furthermore,you should not have a driver for your USB device installed.There are three steps to configure your USB device to use NI-VISA:1.Create the INF file using the Driver Development Wizard.2.Install the INF file and the USB device using the INF file.3.Test the device with NI-VISA Interactive Control.For the purposes of this tutorial,an NI DAQPad-6020E is used as an example USB device and is installed on a Windows XP system.Because this tutorial is intended to explain the configuration of a generic USB device,details specific to the DAQPad-6020E are not discussed.Remember that NI-DAQ is the only supported driver for a DAQPad-6020E.2.1.Create the INF File Using the Driver Development WizardTo use NI-VISA,you must first tell Windows to use NI-VISA as default driver for the device.In the Windows environment,you can do this with an INF file.NI-VISA3.0and higher includes the VISA Driver Development Wizard (DDW)to create an INF file for your USB device.1.To open the DDW,select Start»Programs»National Instruments»VISA»VISA Driver Developer Wizard.Figure 1shows the open screen.Figure1.VISA DDW Hardware Bus WindowYou can use this wizard to create an INF file for a PXI/PCI,USB,or IEEE1394device.Because you are creating the driver for a USB device,click USB and Next.The VISA DDW Basic Device Information window opens as shown in Figure2.Figure2.VISA DDW Basic Device Information Window2.For this step,you must know the USB vendor ID and product ID for your USB instrument.These numbers identify your USB device when you install it and address your device when you want to communicate with it.According to the USB specification,both numbers are16-bit hexadecimal numbers and should be provided by the device manufacturer. If you do not know the USB vendor ID and product ID,you can get them by plugging the device into the computer and allowing the computer to recognize the new device.Cancel out of the Found New Hardware Wizard if it starts.Open the Device Manager from the Control Panel and find your device on the list,usually under"Other Devices."It may show a yellow exclamation mark indicating it is an unknown device.Double-click the device to open the properties. Select the Details tab and ensure that"Device Instance Id"shows in the attribute dropdown box.A string of characters will be displayed similar to Figure3.The four characters to the right of"VID_"and"PID_"are your vendor ID and product ID,respectively.Write down the characters for your device,close the Device Manager,and unplug the device from the computer.Alternatively,you can contact your device vendor to obtain this information.Figure3.Finding the Vendor ID and Product ID from the Device ManagerFor the DAQPad-6020E,the vendor ID and product ID are0x3923and0x12C0,respectively.If your device is not a NI DAQPad-6020E,the vendor ID and product ID are different for your device.Note:Before proceeding with the Driver Development Wizard,make sure the device has been removed from the computer.Enter the vendor ID,product ID,manufacturer name,and model name for your device in their respective fields.Click Next.The Output Files Properties window is displayed as shown in Figure4.Figure4.VISA DDW Output Files Properties Window3.The USB Instrument Prefix is simply a descriptor you use to identify the files used for this device.Enter a USB instrument prefix,select the desired directory in which to place these files,and click Next.The next window will provide you installation options.The default selection is to install the setup information for the operating system and is usually the best option.Once you select an option,click Finish to exit the wizard.The INF file is created in the directory you specified in the output file directory field in the previous window.2.2.Install the INF files and the USB device.The installation of the INF files is different for each version of Windows.When the DDW creates an INF file, installation instructions are included in a header at the top of the INF file.Because INF files are ASCII text files,they can be read in any text editor such as Notepad.For detailed information about installing your INF file,open your INF file in a text editor and follow the instructions at the top of the file.This tutorial assumes you are using Windows XP. 1.Copy the INF file to the INF folder.On Windows XP,this folder is usually at C:\WINDOWS\INF.This foldermay be hidden,so you may need to change your folder options to view hidden files.2.Right-click on the INF file in C:\WINDOWS\INF and click Install.This process creates a PNF file for yourdevice.You are now ready to install your USB device.3.Connect your USB device.Because USB is hot pluggable,Windows should be able to detect your USB device,andthe Add New Hardware Wizard should open automatically as soon as you connect it to the USB port.Follow the onscreen instructions for the wizard.When you are prompted to select a driver for this device,browse to the INF folder and select the INF file you created using the DDW.Note:In some cases,Windows may already have a default driver associated with your USB device.If this is the case, Windows will look to install that driver first.Once you've plugged in your USB device and Windows has installed the default driver,right-click on My Computer and select Properties.In the Properties window go to the Hardware tab and click on Device Manager.Once Device Manager is open,expand the"Human Interface Devices"tree.Then find out which instance of"USB Human Interface Device"(shown in Figure5)corresponds to your USB device byright-clicking and selecting Properties and checking the Details tab for the matching VID and PID.Figure5.Finding the Correct Instance of USB Human Interface Device for Your USB DeviceOnce you've found the"USB Human Interface Device"that has the matching VID and PID of your USB Device, right-click on it and go to Update Driver as shown in Figure6.Figure6.Update the Driver for Your USB DeviceOn the first screen,select"No,not at this time"then click Next.On the second screen,select"Install from a list or specific location(Advanced)"then click Next.On the third screen,select"Don't search.I will choose the driver to install."The fourth screen will look similar to Figure7where the highlighted driver is the driver you've created.Once you've selected your driver click next.When the driver has finished installing click Finished.Figure7.Select the VISA Driver for Your USB Device2.3.Test Communication with VISA Interactive Control.1.Open Measurement&Automation Explorer(MAX).Select Tools»Refresh to refresh the view.Your USB device should be listed as a USB Device under Devices and Interfaces as shown in Figure8.Your USB device is now installed and configured to use NI-VISA.If you select your USB device,the device information is displayed in the USB Settings ing this window, you can access information such as the manufacturer ID,model code,and serial number for your device.B Device Shown in MAX2.To communicate with your device using VISA,use the VISA instrument descriptor for your device.The instrument descriptor format for a USB INSTR device is USB[board]::manufacturer ID::model code::serial number[::USB interface number]::INSTR.The instrument descriptor format for a USB RAW device is USB[board]::manufacturer ID:: model code::serial number[::USB interface number]::RAW.According to the USBTMC specification,all USBTMC devices must have a serial number.Some USB RAW devices may not have serial numbers.If your device does not have a serial number,NI-VISA automatically assigns a VISA specific serial number for that device.The format for the serial number is NI-VISA-#,where#is an automatically generated number.Some USB devices have multiple interfaces.This is similar to the way a PCI device can have multiple functions.If your device only supports one interface,you do not need to include the USB interface number.The DAQPad-6020E uses the RAW class,and the manufacturer code and model code are0x3923and0x12C0, respectively.For the DAQPad-6020E,the instrument descriptor is USB0::0x3923::0x12C0::00B50DAE::RAW.To test communication with this device,open MAX.Select Tools»NI-VISA»VISA Interactive Control.A window similar to that shown in Figure9should open.Figure9.VISA Interactive Control3.The VISA Interactive Control(VISAIC)is a utility program used to communicate easily with any VISA resource. After your USB device is configured to use VISA,it should be listed in the USB branch.Double-click on your device to open a VISA session to the device.The window shown in Figure10should open.Figure10.VISA Interactive Control Open VISA SessionWhen you open a VISA Session with VISAIC,the Template tab and the Property Node(Set)tab are automatically selected.To read a property,select the Property Node(Get)tab,and choose the desired property and click Execute.The current value of the property specified in Attribute Name is displayed in the Current Value indicator.In Figure10, the Resource Name property was read.For more information about using VISAIC,refer to Developer Zone:VISA Interactive Control(VISAIC).For information about the NI-VISA API,review the NI-VISA Help.Both are available through the links at the end of this tutorial.For a list of valid commands for your USB instrument,contact your instrument’s manufacturer.ing NI-VISA to Communicate with Your USB DeviceThis section explains how to communicate with your USB device using NI-VISA3.0and above.Recall that there are two classes of USB devices.The method of communication depends on the class of your device.3.1USB INSTR Class(USBTMC)Devices that conform to the USB Test and Measurement Class(USBTMC)use the NI-VISA USB INSTR class.These devices use488.2style communication.For these devices,you can simply use the VISA Open,VISA Close,VISARead,and VISA Write functions in the same way you would if you were communicating with GPIB instruments.Figure11illustrates a LabVIEW VI that communicates with a USBTMC device.In this example,a VISA session is opened to a USB device.A command is written to the device,and the response is read back.In this example,the specific command being sent is the ID query for the device.Check with your device manufacturer for your device command set.After all communication is complete,the VISA session is closed.BTMC LabVIEW Example Block Diagram3.2USB RAW ClassCommunicating with the USB RAW class is more complicated because each device may use its own communication protocol.Contact your device vendor for details about the communication protocol for your device.USB communicates using four types of pipes or endpoints:control,bulk,interrupt,and isochronous.Each type of pipe transfers a different type of information.Furthermore,any number of endpoints can be of any endpoint type.Think of an endpoint as a communication socket.For specific details about USB architecture,review the USB specification linked below.NI-VISA supports three types of USB pipes:control,bulk,and interrupt.When NI-VISA detects your USB instrument, it automatically scans your instrument for the lowest available endpoint for each type.When VISA detects the lowest available endpoint,it assigns that value to the appropriate VISA attribute.The bulk in endpoint and bulk out endpoint are stored in the VI_ATTR_USB_BULK_IN_PIPE attribute and theVI_ATTR_USB_BULK_OUT_PIPE attribute,respectively.The interrupt in endpoint is stored in theVI_ATTR_USB_INTR_IN_PIPE attribute.A value of-1indicates that a USB device does not support that type of pipe. For the control pipe,only endpoint zero is supported.If you are using the C API,use the viSetAttribute function to change endpoints.In LabVIEW,use a Write VISA Property node.NI-VISA includes four functions to transfer data through USB pipes.Before you can communicate with your device using these functions,you need to set up the communication protocol using the VISA USB attributes.The following list describes the available functions.•Use VISA USB Control In and VISA USB Control Out to transfer data using the control pipe.•To transfer data using a bulk pipe,use VISA Read and VISA Write.If you are using LabVIEW,VISA includes an additional function to use the interrupt pipe:VISA Get USB Interrupt Data.In the C API,you can do this by accessing the VI_ATTR_USB_RECV_INTR_SIZE andVI_ATTR_USB_RECV_INTR_DATA attributes of the VI_EVENT_USB_INTR event object.See the NI-VISA Help for more information about VISA Events.B on Linux®and Mac4.1LinuxNI-VISA relies on a Linux kernel feature for its USB support.This feature is called usbfs,and on older Linux kernels was referred to as usbdevfs.For NI-VISA to support USB devices,this feature must be present and mounted(like a virtual file system).This is supported in most major Linux distributions such as Red Hat,SuSE,and Mandrake.You may use the mount command to display what file systems are currently mounted to see if your system currently supports this feature.Also,the VISA user must have write access to the file that represents the USB device,which is typically somewhere in a subdirectory within/proc/bus/usb.If this is not the case,the USB device is not accessible by VISA(it will not be found using viFindRsrc,and viOpen will fail).The default configuration on most systems is that the root user has write access;however,no other user has this access.There are several options for providing a nonroot user access to a USB device.•Use the hotplug package.This package is installed by default on most distributions including Red Hat,SuSE,and Mandrake.The hotplug package allows the user to run scripts for a specific USB device based on characteristics such as Vendor ID(VID)and Product ID(PID).If the hotplug package exists,the NI-VISA Installer by default will install scripts to give all users write access to all USB TMC devices and a framework for USB RAW devices.To add write permissions for a specific USB RAW device,run the included script:<VXIPNPPATH>/linux/NIvisa/USB/AddUsbRawPermissions.shFor more information about the hotplug package,refer to the following Web site:/.•usbfs(formerly known as usbdevfs)may be mounted with the option devmode=0666.This gives all users read and write access to all USB devices.•The root user may add write permissions to the file that represents the USB device,which is typically somewhere in a subdirectory within/proc/bus/usb.Unfortunately,these permissions are lost if the device is unplugged.Therefore,this approach is not recommended.4.2Mac OS XAs long as no other driver on the system claims the USB device,you can use NI-VISA to access it.No special setup is required.Related Links:Return to the Instrument Control Fundamentals HomepageProduct Reference:NI-VISA HelpDeveloper Zone:VISA Interactive Control(VISAIC)Developer Zone:Using the VISA Driver Development Wizard and NI-VISA to Register-Level Program a PXI/PCI Device under WindowsUSB Implementers Forum:USB2.0Specification:/developers/docsUSB Implementers Forum:Approved Class Specification Documents:/developers/devclass_docs Developer Zone:USB RAW Control Communication in LabVIEWDeveloper Zone:USB RAW Bulk Communication with LabVIEWDeveloper Zone:VISA USB RAW Mode Get Interrupt Data ExampleLinux®is the registered trademark of Linus Torvalds in the U.S.and other countries.。
虚拟仪器平台LabVIEW下USB总线的应用开发
黄姗;马燕;夏睿
【期刊名称】《青海电力》
【年(卷),期】2007(026)0z1
【摘要】文章提出了基于USB总线在虚拟仪器开发平台LabVIEW下程序设计方案和关键实施要点.虚拟系统的USB接口硬件使用FTDI公司的FT245BM芯片,并利用其驱动程序中D2XX动态链接库文件,采用插入外部代码调用标准API库函数的形式,成功开发了USB接口在LabVIEW平台下的驱动子系统.采用"模块化"思想,在LabVIEW下调用此子系统,即可开发出面向用户接口、总线接口和数据处理的虚拟仪器软件,亦可满足虚拟仪器设计的需要及模块化设计、协同工作的需求.
【总页数】4页(P62-64,70)
【作者】黄姗;马燕;夏睿
【作者单位】海东供电公司,青海,平安,810600;南京电力设计研究院,江苏,南
京,210013;南京电力设计研究院,江苏,南京,210013
【正文语种】中文
【中图分类】TP311.52
【相关文献】
1.虚拟仪器平台LabVIEW下USB总线的应用开发 [J], 黄姗;马燕;夏睿
2.基于USB总线的虚拟仪器传感器测控实验平台设计 [J], 赵京
3.基于USB和LabVIEW开发平台的虚拟仪器的设计 [J], 杨灵;周正达;张蕴玉
4.基于LabVIEW多功能虚拟仪器的应用开发 [J], 邝永明
5.基于嵌入式计算平台和USB总线技术的虚拟仪器的设计 [J], 吴小红
因版权原因,仅展示原文概要,查看原文内容请购买。
LabVIEW是一种基于图形程序的虚拟仪器编程语言,在测试与测量、数据采集、仪器控制、数字信号分析、工厂自动化等领域得了广泛的应用。
LabVIEW 程序采用方框图编程,具有友好的人界面,在前面板中有用于模拟真实仪器面板的控件可供调用,可用于设置输入数值、观察输出值以及实现图表、文本等显示。
实现LabVIEW对数据的采集和处理,传统的是采用数据采集卡,但是这些数据采集设备存在安装不便、价格昂贵、受计算机插槽数量、地址、中断资源的限制,可扩展性差,同时在一些电磁干扰性强的测试现场,可能无法专门对其做电磁屏蔽,从而导致采集的数据失真。
在LabVIEW 下使用USB 总线,可以同样实现数据采集,并且弥补了采集卡的不足。
B底层驱动程序设计VISA(Virtual Inst rument Software Architecture )是一个用来与各种仪器总线进行通讯的高级应用编程接口(API)。
他不受平台、总线和环境的限制。
通用串行总线(USB)是一个基于信息的通讯总线。
这表示PC 机与USB 设备通过发送指令和数据进行通讯,而这些指令和数据是通过总线以文本或二进制数据的形式发送的。
每个USB 设备都有各自的指令集。
可以使用NI2VISA 的读写功能向仪器发送这些指令,并读取仪器的反馈。
NI2VISA 从3. 0版开始支持USB 通讯,他有2种VI2SA 类函数( Resource Class) ,可以控制2类USB 设备:USB INSTR 设备与USB RAW 设备。
符合USB 测试和测量类(USBTMC)协议的USB 设备可以通过使用USBINSTR 类函数控制,他们使用488. 2标准通讯。
对于这些设备,只需以与GPIB 仪器通讯同样的方式,使用“VISAOpen”,“VISA Close”,“VISA Read”和“VISA Write”功能。
USBTMC 设备符合VISA USB INSTR 类函数能够理解的协议。
ic技术资料:NI-VISA及LabVIEW USB接口使用设计方案富电电子发布了cem9435a,数量16000 厂商cem 批号00+ 封装soic-8/3.9mm ,购买cem9435a请来这里咨询cem9435a价格引言usb(universal serial bus)接口是近年来使用在pc领域新品接口技术信息。
它单一总线接口技术信息来足够几种使用领域需求;它即插即用,支持热插拔,易于扩展等特征极大地方便了用户运用,已逐渐成为现代数据输出发展趋势。
传统研发usb使用系统步骤是,先用windowsddk(设备软件驱动程序研发包)或第三方研发工具(如driverst ljdic))研发ljsb软件驱动程序,然后用visual c++编写dll(动态连接库),最后再调有dll来研发应用程序软件。
显然,这对windows编程代码不熟悉人来说有一定难度,何况usb 软件驱动程序研发难度很大。
本文说明一种简单,迅速研发usb接口使用系统方法。
它直接在labview环境下通过ni-visa研发能软件驱动用户usb系统应用程序软件,完全避开了对前研发usb软件驱动程序复杂性,大大缩短了研发周期。
1 n1-visa介绍ni-visa(virtual instrument software architecture,对下简称为"visa")是美国国家仪器ni(national1nstrllrnent)公司研发一种用来及各种仪器总线进行通信高级使用编程代码接口。
visa总线1/()软件是一个综合软件包,不受平台,总线与环境限制,可用来对usb,gpib,串口,vxi,pxi与对太网系统进行设置,编程代码与调试。
visa是虚拟仪器系统i/o接口软件。
自底向上构造模型visa创造了一个统一形式i/o控制函数集。
一方面,对初学者或是简单任务设计方案者来说, visa供应了简单易用控制函数集,在使用形式上相当简单;另一方面,对复杂系统组建者来说,visa供应了非常强大仪器控制功能及资源管理。
作者简介:黄姗(1978-),女,从事电力系统自动化工作。
收稿日期:2007-04-16虚拟仪器平台LabV IEW 下U SB 总线的应用开发黄 姗1,马 燕2,夏 睿2(1:海东供电公司,青海平安810600;2:南京电力设计研究院,江苏南京210013)摘 要:文章提出了基于U SB 总线在虚拟仪器开发平台L abV IEW 下程序设计方案和关键实施要点。
虚拟系统的U SB 接口硬件使用FT DI 公司的FT 245BM 芯片,并利用其驱动程序中D2XX 动态链接库文件,采用插入外部代码调用标准API 库函数的形式,成功开发了U SB 接口在LabV IEW 平台下的驱动子系统。
采用/模块化0思想,在LabV IEW 下调用此子系统,即可开发出面向用户接口、总线接口和数据处理的虚拟仪器软件,亦可满足虚拟仪器设计的需要及模块化设计、协同工作的需求。
关键词:L abVI EW ; 通用串行总线; 动态链接库; A PI;中图分类号:T P311.52 文献标识码:B 文章编号:1006-8198(2007)增-0062-03Application and Development of USB Bus UnderVirtual Instrument Platform LabVIEWHUANG Shan 1,MA Yan 2,XIA Rui2Abstract :T he paper puts for ward the progr am design scheme and key implementing points under vir tual instrument platform LabVI EW on USB bus.T he U SB interface hardware o f vir tual system uses FT 245BM chip of F T DI Com -pany,and utilizes D2XX in driver pro gram o f dynamic link libr ar y file,inserting external code to call API standard librar y function,and successfully develops U SB interface .s driv er subsystem under L abV IEW platform.Adopting t he idea of -mo dular ization .,calling the subsystem on L abV IEW,can dev elop the v irtual instrument softw ar e of facing user interface,bus inter face and data treatment,and can be satisfied w ith the need of v irtual instrument and t he demand of modularization design and cooperative wor k.Keywords :L abV IEW,U SB,dynamic link library ,AP I随着计算机网络技术、虚拟仪器技术的发展,以远程仪器控制技术为基础的远程试验成为研究热门,这要求仪器都带有通信接口,如:RS-232、GPIB 总线。
USB 端口已成为如今PC 机上的标准配置,目前主流操作系统上都支持,虽然在测量和自动化方面刚刚才得到普及,但USB 拥有的高速率、热拔插功能、内嵌式操作系统配置,还有多点布线技术,让其在仪器应用领域表现极为出色。
U SB 为数据采集设备P 仪器与PC 机间的连接提供了费用低廉、简单易用的方案。
1 虚拟仪器技术和仪器总线技术111 虚拟仪器平台LabV IEWN I 公司的LabVIEW 是目前国际上应用最广泛的虚拟仪器开发平台之一。
LabVIEW 采用强大的图形化语言(G 语言)编程,面向测试工程师而非专业程序员,具有编程方便、界面友好和强大的数据分析能力和可视化仪器控制能力的优点112。
为了弥补平台不能实现底层操作这一缺陷,LabVIEW 提供了大量的外部代码连接机制,实现与外部程序代码或软件系统(如EXCEL 、C 语言、Window sAPI 、MATLAB)的链接,将其自身无法实现或不易实现的硬件接口访问任务通过外部代码来实现122。
本文利用LabV IEW 的动态链接库机制进行USB 接口的虚拟仪器驱动编程。
112 仪器总线技术当前仪器总线运用技术上,GPIB 通用接口总第26卷增刊 青 海 电 力 Vol.26 2007年12月 QINGHAI ELECTRIC POWER Dec.,2007线系统和VXI 仪器总线系统是最通常的选择,前者建立在已为所有的仪器厂家所接受的GPIB 接口基础上,以至用户可以在世界范围内不分厂家国别,从测试的角度出发选择最理想仪器来组建系统。
后者以VXI 模件的形式出现在专用的VXI 机箱中,仪器之间的总线连接通过背板实现。
PXI (面向仪器的PCI 扩展,PCIeXtensions for Instrumentation)规范扩展了用于测量和自动化应用的CompactPCI 。
使用PXI 系统,能实现所有PC 系统的功能,而且结合了面向仪器扩展的工业化坚固结构,具有高性能和高灵活性,在建立仪器平台、自动化测试系统、工业自动化系统和建立数据采集系统方面,PXI 都能有效降低系统总成本,提高系统性能并简化系统集成。
但以上几类系统主要应用于工业级的仪表测量和自动化设备领域,在成本上极大程度限制了它们在民用和中小企业中的应用。
113 USB 总线接口与计算机和外设之间的其他接口相比,U SB 总线包含的几个特点使得其作为虚拟仪器系统中测试设备与PC 主机之间的通信接口占有相当明显的优势。
使用USB 连接的设备具有热拔插功能,在添加或拆除设备时不需要关机。
该总线还具有自动探测设备的功能,这意味着用户插入设备后无须对其进行手工配置。
操作系统软件会自行探测到这些设备并进行安装。
U SB 提供的4种传输方式:控制传输、同步传输、中断传输和批量传输,使其在数据格式、传输方向、数据包容量限制、总线访问限制等方面有着各自不同的特征。
U SB 设备的软件一般包括主机的驱动程序、应用程序和Firmw are 固件。
尽管操作系统能够提供很多标准接口函数,但编制驱动程序依旧是U SB 开发中最困难的一件事。
本文基于FT DI 公司的FT 245BM 这块高性能USB 芯片,提出了简洁高效的USB 驱动设计方案。
首先,在固件软件设计时,由于FT245BM 内部集成了U SB 到并口的协议转换,使得单片机程序的编写变得非常简单。
其次,在上位机驱动软件的设计上,FTDI 公司也提供了完善的支持。
可从其官方网站下载两种驱动程序,一种是虚拟串口VCP(Virtual COM Port)驱动,另一种是D2XXUSB 驱动,分别有Window s98P 2000P XP 等不同操作系统版本。
使用虚拟串口VCP 驱动程序,可以把虚拟串口(VCP)当作一个标准的串口去访问,只需编写针对虚拟串口通信的应用程序。
在这种方式下,最大传输速率可达300kbit P s,比普通的串口要快很多。
2 LabV IEW 的C 代码调用机制LabVIEW 与其他应用程序的链接可以通过.NET 技术、ActiveX 技术、动态数据交换、外部代码调用、库函数调用、运行外部程序等方式。
尽管LabVIEW 具有开发效率高、内置函数丰富等优势,但在图形表达、对底层的驱动等方面确不如C 语言功能强大。
调用库函数节点,使用标准共享库函数可在增加LabVIEW 程序接口驱动的同时,具备模块化设计、升级维护方便以及节省内存空间等优点。
本文设计在LabV IEW7.1下选择CLFN 方式作为应用程序的外部代码接口,以此利用DLL 所引入的众多优良特性满足虚拟仪器设计的需要和模块化设计、协同工作的要求132。
如图1所示,LabV IEW 调用FTDI 公司提供的FTD2XX.DLL,来使用其标准API 函数。
在这种方式下,USB 端口的最大传输速率可达1M bit P s 。
使用了DLL 后,在程序的可执行文件中,存放的是在DLL 中所要调用的函数的内存地址,这样当一个或多个应用程序运行时,再把程序代码和被调用的函数代码链接起来,从而节省了内存资源。
图1 基于DLL 的U SB 接口虚拟仪器系统框图3 采用DLL 开发USB 驱动程序实例在LabVIEW 开发环境中使用功能模板中的/Advanced 0子模板里的/CallLibraryFunctionNode (调用库函数节点)0提供对DLL 调用的支持。
把U SB 驱动程序分解成16个步骤,由于LabVIEW 是图形化编程界面,本文描述其中比较重要的步骤的程序框图,并标出各个子框图的执行顺序。
在每个子框图中,都调用了相应的VI 子程序,在VI 子程序中,调用了D2XX 驱动程序63增刊 马惠萍等:青海省电力公司创一流同业对标管理系统的设计开发的DLL,并使用了库中的API函数。
1)根据设备索引值取得设备描述符。
设备索引值是从0开始的。
由于本系统中只有一个U SB设备,因此设备索引值为0。
如果增加U SB 设备,对应索引值将依次增加。
我们用到了FT_ ListDevices这个API函数,它实现的功能是根据设备索引打开设备描述符。
也可以用它实现其它功能,如打开设备的序列号、打开设备的位置ID 等。
2)根据设备描述符打开设备。
根据第一步的设备描述符,打开相应的USB设备。
用到的API函数是FT)OpenEx,它是FT)Open的扩展,可以根据设备描述符、序列号、位置ID打开相应设备。
设备打开后,返回一个句柄(H andle)。
这个句柄是一个包含区别不同设备信息的结构,后面每一个步骤都需要用到它。
3)复位设备。
根据H andle,复位相应U SB 设备,用到的API函数是FT)ResetDevice。
4)设置超时。
设定若USB发送和接收数据时限,以毫秒为单位。
用到的API函数是FT) SetTimesOut。
5)设置事件触发条件。
程序可以在这里设定一些事件发生的条件,当一个事件发生时允许线程阻塞。
比如,打开设备时,创建超时事件,被复位事件标志为:当一旦超时条件达到,即可触发,由应用程序处理后续动作,此处调用了FT)SetEventNotification。
6)读取当前状态。