机械外文翻译文献翻译--使用LabVIEW中的TCPIP和UDP协议

合集下载

LabVIEW与通信技术实现数据传输与网络通信

LabVIEW与通信技术实现数据传输与网络通信

LabVIEW与通信技术实现数据传输与网络通信随着科技的不断发展,数据传输与网络通信在现代社会中起着至关重要的作用。

LabVIEW(Laboratory Virtual Instrument Engineering Workbench)作为一种基于图形化编程的开发环境,已经成为许多工程领域中的首选工具。

LabVIEW与通信技术的结合,为实现高效的数据传输和稳定的网络通信提供了一种可行的解决方案。

一、LabVIEW在数据传输中的应用在大规模的数据传输过程中,快速而可靠地传输数据是至关重要的。

LabVIEW提供了丰富的功能和工具,可以帮助用户轻松实现数据传输。

以下是LabVIEW在数据传输中的几个主要应用:1. 串口通信:通过串口通信,LabVIEW可以与各种设备进行连接,并实现数据的相互传输。

通过LabVIEW的串口通信模块,用户可以方便地编写程序,实现与串口设备的数据交互。

2. 数据采集:LabVIEW作为一种虚拟仪器工作环境,可以通过各种传感器和测量设备,对实时数据进行采集和监控。

LabVIEW提供了丰富的数据采集工具和函数库,可以帮助用户完成数据采集的任务。

3. 数据处理:通过LabVIEW强大的图形化编程能力,用户可以对采集到的数据进行处理和分析。

LabVIEW提供了多种数学和信号处理函数,可以帮助用户完成各种数据处理任务。

4. 数据存储:LabVIEW可以将采集到的数据保存在本地或者远程的数据库中,以便后续的分析和处理。

LabVIEW提供了与各种数据库系统集成的功能,可以方便地将数据存储到数据库中。

二、LabVIEW在网络通信中的应用随着互联网的普及和发展,网络通信已经成为人们日常生活中不可或缺的一部分。

LabVIEW通过与各种通信协议的集成,为实现稳定快速的网络通信提供了强大的支持。

以下是LabVIEW在网络通信中的几个主要应用:1. TCP/IP通信:LabVIEW可以通过TCP/IP协议与其他设备或者远程服务器进行通信。

LabVIEW中的网络通信和远程控制

LabVIEW中的网络通信和远程控制

LabVIEW中的网络通信和远程控制在当今科技迅速发展的时代,网络通信和远程控制在各个行业中扮演着重要的角色。

而在工程和科学领域中,一款被广泛应用的工具就是LabVIEW(Laboratory Virtual Instrument Engineering Workbench)。

LabVIEW是一种图形化编程语言,旨在帮助工程师和科学家设计、测试和控制各种各样的硬件系统。

本文将重点介绍LabVIEW中的网络通信和远程控制功能,探讨它们在实际应用中的重要性和优势。

首先,LabVIEW提供了一系列强大的工具和函数,使得通过网络进行通信变得简单而高效。

LabVIEW支持常见的网络协议,例如TCP/IP、UDP等,可以轻松地实现网络间的数据交换和通信。

通过LabVIEW的网络通信功能,用户可以通过局域网或互联网实现分布式数据采集和远程控制。

这对于分布式监测系统、基于云计算的数据处理和远程设备控制具有重要意义。

其次,LabVIEW的网络通信模块使得多个LabVIEW应用程序之间的数据传输变得简单。

用户可以通过使用基于网络的VI(虚拟仪器)进行数据共享、远程仪表配置和远程数据分析。

这对于大规模的实验室研究、远程教学和协作开发具有重要价值。

同时,通过网络通信,用户还可以将LabVIEW应用程序连接到其他编程语言,实现与其他系统的数据交换和协同工作。

此外,LabVIEW还提供了灵活的远程控制功能,使得用户可以远程访问和控制硬件设备。

通过LabVIEW的远程控制模块,用户可以编写控制程序并将其部署到远程设备上,实现对设备的远程监控和控制。

例如,用户可以通过LabVIEW远程控制模块连接到一个实验设备,读取传感器数据、操控执行器,并实现对设备参数的调整。

这在很多需要实时远程控制的场景中非常有用,如远程实验、远程诊断和远程设备维护。

此外,LabVIEW还提供了在网络通信和远程控制中常用的安全机制。

LabVIEW支持数据加密、身份验证和访问控制,以确保数据的安全性和保密性。

LabVIEW网络通信

LabVIEW网络通信

在LabVIEW 中采用TCP/IP 协议实现网络通信1 设计任务本例利用TCP 协议进行双机通信。

采用服务器/客户机模式进行双机通信,是在LabVIEW 中进行网络通信的最基本的结构模式。

本例由服务器产生一组随机波形,通过局域网送至客户机进行显示。

2 任务实现在服务器的框图程序中,首先指定网络端口,并用侦听TCP 节点建立TCP 侦听器,等待客户机的连接请求,这是初始化的过程。

程序框图采用了两个写入TCP 数据节点来发送数据:第一个写入TCP 数据节点发送的是波形数组的长度;第二个写入TCP 数据节点发送的是波形数组的数据。

这种发送方式有利于客户机接收数据。

服务器的前面板及程序框图如图12-23和图12-24所示。

与服务器框图程序相对应,客户机程序框图也采用了两个读取TCP 数据节点读取服务器送来的波形数组数据。

第一个节点读取波形数组数据的长度,然后第二个节点根据这个长度将波形数组的数据全部读出。

这种方法是TCP/IP 通信中常用的方法,可以有效的发送、接图12-23 TCP 通信服务器程序前面板图12-24 TCP 通信服务器程序框图收数据,并保证数据不丢失。

建议用户在使用TCP 节点进行双机通信时采用这种方法。

在用TCP 节点进行通信时,需要在服务器框图程序中指定网络通信端口号,客户机也要指定相同的端口,才能与服务器之间进行正确的通信,如上例中的端口值为2600.端口值由用户任意指定,只要服务器与客户机的端口保持一致即可。

在一次通信连接建立后,就不能更改端口的值了。

如果的确需要改变端口的值,则必须首先断开连接,才能重新设置端口值。

还有一点值得注意的是,在客户机框图程序中首先要指定服务器的名称才能与服务器之间建立连接。

服务器的名称是指计算机名。

若服务器和客户机程序在同一台计算机上同时运行,客户机框图程序中输入的服务器的名称可以是localhost ,也可以是这台计算机的计算机名,甚至可以是一个空字符串。

LabVIEW常用中英文词汇对照表

LabVIEW常用中英文词汇对照表
LabVIEW常用中英文词汇对照表
—-LabVIEW高级编程与虚拟仪器工程应用随书光盘
前面板菜单栏 Panel Menu
文件File
新建VI New VI
新建New
打开Open
关闭Close
关闭全部Close All
保存Save
另存为Save As…
保存全部Save All
保存为前期版Save As Earlier Stage Edition
接线端类型This Connection Is
工具选板 Tools Palette
操作值Operate Value
定位/调整大小/选择Position/Size/Select
编辑文本Edit Text
进行连线Connect Wire
对象快捷菜单Object ShortcutMenu
滚动窗口Scroll Window
还原Revert
新建项目New Project
保存项目Save Project
关闭项目Close Project
页面设置Page Setup
打印Print
打印窗口Print Window
VI属性VI Properties
近期项目Recently Opened Projects
近期文件Recently Opened Files
水平滚动条Horizontal Scrolling Bar
带边框颜色盒Framed Color Box
布尔Boolean
开关按钮Push Button
翘板开关Rocker
垂直翘板开关Vert Rocker
圆形指示灯Round LED
水平摇杆开关Horizontal Toggle Switch

虚拟仪器基本TCPIP通信(机译)

虚拟仪器基本TCPIP通信(机译)

Basic TCP/IP Communication in LabVIEW虚拟仪器基本TCP / IP通信Internet Protocol (IP), User Datagram Protocol (UDP), and Transmission Control Protocol (TCP) are the basic tools for network communication. The name TCP/IP comes from two of the best-known protocols of the internet protocol suite, the Transmission Control Protocol and the Internet Protocol. With TCP/IP you can communicate over single networks or interconnected networks (Internet).互联网协议(IP),用户数据报协议(UDP)和传输控制协议(TCP)是网络通信的基本工具。

TCP / IP的名称来自于两个最有名的协议网际协议套件,传输控制协议和网络协议。

使用TCP / IP可以交流在单一网络或互联网络(互联网)。

TCP/IP communication provides a simple user interface that conceals the complexities of ensuring reliable network communications. Refer to the Using LabVIEW with TCP/IP and UDP Application Note (linked below) for more information about how TCP/IP communication works. Refer to the TCP specification (linked below) for technical details about TCP.TCP / IP通信提供了一个简单的用户界面,隐藏的复杂性确保可靠的网络通信。

LabVIEW的网络通信与数据共享

LabVIEW的网络通信与数据共享

LabVIEW的网络通信与数据共享LabVIEW是一种强大的图形化编程语言,用于实时数据采集、控制和分析。

其灵活性和可扩展性使其成为各种工程领域中的首选工具。

LabVIEW支持网络通信和数据共享,使用户能够轻松地在不同的设备和系统之间传输数据,并实现远程监控和控制。

一、LabVIEW的网络通信功能LabVIEW具有丰富的网络通信功能,可以通过各种协议和技术进行数据传输。

以下是一些常见的网络通信功能:1. TCP/IP通信LabVIEW支持TCP/IP协议,可以通过TCP/IP Socket VIs(虚拟仪器)进行数据传输。

用户可以方便地建立起主机和设备之间的通信连接,并进行数据的收发和处理。

2. UDP通信除了TCP/IP通信,LabVIEW还支持UDP协议。

UDP是一种无连接的通信协议,适用于实时性要求较高的应用。

通过LabVIEW的UDP功能,用户可以快速地传输数据,实现实时监测和控制。

3. 套接字编程LabVIEW提供了强大的套接字编程支持,允许用户自定义网络通信的行为。

用户可以使用LabVIEW的Socket VIs创建和管理套接字,实现高度灵活的网络通信方案。

4. 互联网通信借助LabVIEW的互联网通信功能,用户可以通过网络连接实现设备和系统之间的数据传输。

无论是在本地网络中还是通过互联网远程连接,LabVIEW都提供了便捷的方法和工具。

二、LabVIEW的数据共享功能LabVIEW不仅支持网络通信,还提供了丰富的数据共享功能。

以下是一些常见的数据共享功能:1. 共享变量LabVIEW的共享变量可以将数据在多个LabVIEW应用程序之间共享。

用户可以使用共享变量进行数据传输和共享,实现实时监测、数据录制和控制操作。

2. 数据库连接LabVIEW支持与各种常见数据库的连接,如MySQL、Oracle和Microsoft SQL Server等。

通过数据库连接,用户可以将实时数据存储到数据库中并进行查询和分析。

基于LabVIEW和ModBus TCP的一种PLC通讯方法

基于LabVIEW和ModBus TCP的一种PLC通讯方法

专题与综述Topics and reviews0 引言在开发产品的自动测试机时,如果没有特殊要求,PLC 是个非常优秀的选择。

相比于电路板较长的开发时间以及较高的开发难度,PLC功能全面,设计维护方便,可靠性高,抗干扰能力强,占据了相当的优势。

为了从PLC中读取数据和控制PLC的输出,则需要上位机与PLC进行通讯,对相应的寄存器进行操作。

常用的PLC通讯接口有RS-232,RS-422/485和以太网。

本文将以S7-200 SMART系列PLC为例,设计一个适用于测试机的ModBus TCP通讯程序[1]。

1 以太网通讯协议设计一个完整的通讯网络包括硬件和软件。

对于S7-200 SMART PLC,其自带一个以太网口,可以很方便的插上网线进行通讯。

并且,由于该型号PLC有内置ModBus TCP协议,这就使得硬件和软件都不需要额外的工作,可以直接使用基于LabVIEW和ModBus TCP的一种PLC通讯方法杨晨宇(上海交通大学电子信息与电气工程学院,上海 200030)摘要:文章中介绍了使用LabVIEW和PLC通过以太网进行数据交互的一种应用方法及程序的实现。

此方法是基于ModBus TCP协议的,对于几乎所有支持ModBus TCP的设备,都可以使用文中的方法进行数据交互,且可使用字符串直接进行操作,简单方便。

试验运行结果表明,该方法运行稳定,程序易于编写,满足设计要求。

关键字:LabVIEW;PLC;ModBus TCP中图分类号:TB69 文献标识码:A文章编号:2095-6487(2019)12-0122-02除从电源线进入系统或芯片的干扰信号以及该印刷板或芯片产生的干扰信号。

2.1.4 地线抗干扰的措施与单片机控制系统关联的地线具有一定的阻抗,各种电路的电源受到地线阻抗的影响,导致电压降现象,形成地线干扰。

然而,消除地线干扰的最佳方法是将各电路的地线接地。

2.1.5 复位电路的抗干扰分析单片机复位端口的干扰因素主要为电源或按钮传输线串入的噪声,该干扰因素可能导致整个控制系统的功能复位,甚至破坏单片机内CPU程序状态字的某些位的状态。

使用LabVIEW进行数据通信实现可靠的数据传输和网络通信

使用LabVIEW进行数据通信实现可靠的数据传输和网络通信

使用LabVIEW进行数据通信实现可靠的数据传输和网络通信LabVIEW是一款强大的工程软件,可以用于实现数据通信以及网络通信。

在大数据时代,准确、可靠的数据传输和网络通信对于各行各业都至关重要。

本文将介绍如何使用LabVIEW来实现可靠的数据传输和网络通信。

一、LabVIEW简介LabVIEW(Laboratory Virtual Instrument Engineering Workbench)是一种图形化的开发环境,由美国国家仪器公司(National Instruments)开发。

它允许用户通过将函数和连接它们的线连接在一起创建程序。

这种可视化编程的方法使得非专业编程背景的人员也可以轻松地进行软件开发。

LabVIEW广泛应用于控制系统、数据采集、实验室仪器控制和数据分析等领域。

二、数据传输1. 数据读取与写入LabVIEW提供了丰富的函数库和工具箱,可以轻松地进行数据的读取和写入操作。

通过使用合适的模块和函数,我们可以连接各种传感器、设备或者数据库来实现数据的采集和存储。

2. 数据处理与分析LabVIEW提供了强大的数据处理和分析功能。

用户可以使用图形化编程的方式,通过拖拽和连接不同的函数块来实现数据的处理和分析。

这使得数据的处理变得更加直观、高效和可靠。

3. 数据传输协议LabVIEW支持多种常用的数据传输协议,包括TCP/IP、UDP、HTTP等。

用户可以根据具体需求选择合适的协议来进行数据传输。

同时,LabVIEW还支持自定义的数据传输协议,可以根据实际情况进行定制。

三、网络通信1. 建立网络连接LabVIEW提供了丰富的网络通信工具,可以方便地建立网络连接。

用户可以使用TCP/IP或者UDP协议来建立客户端和服务器之间的通信。

LabVIEW还支持Web服务,可以通过Web浏览器与LabVIEW程序进行交互。

2. 实时监控与控制LabVIEW可以实时监控和控制网络上的各种设备。

用户可以通过连接传感器和执行器等设备,实时地获取数据并进行控制。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

中文3078字使用LabVIEW中的TCP/IP和UDP协议前言互联网络协议(IP),用户数据报协议(UDP)和传输控制协议(TCP)是网络通信的基本的工具。

TCP与IP的名称来自于一组最著名的因特网协议中的两个--传输控制协议和互联网络协议。

你能使用TCP/IP来进行单一网络或者互连网络间的通信。

单独的网络会被大的地理距离分隔。

TCP/IP把数据从一个子网网络或者因特网连接的计算机发送到另一个上。

因为TCP/IP 在大多数计算机上是可用的,它能在多样化的系统中间传送信息。

LabVIEW和TCP/IP你能在所有平台上的LabVIEW中使用TCP/IP。

LabVIEW包含了TCP和UDP程序还有能让你建立客户端或者服务器程序的功能。

IPIP执行低层次的计算机间的数据传送。

在组成部分里的IP数据包称为数据报。

一个数据报包含表明来源和目的地地址的数据和报头字。

IP为通过网络或者因特网把数据发送到指定的目的地的数据报确定正确的路径。

IP协议并不能保证发送。

事实上,如果数据报在传输中被复制,IP可能多次传送一个单独的数据报。

所以,程序很少用IP而是用TCP或者UDP代替。

UDPUDP在计算机进程中提供简单而低层次的通信。

进程通过把数据报发送到一个目的地计算机或者端口进行通信。

一个端口是你发送数据的位置。

IP处理计算机对计算机的发送。

在数据报到达目的地计算机后,UDP把数据报移动到其目的端口。

如果目的端口不是开放的,UDP 将删除数据报。

UDP将发生IP的同样的发送问题。

应用程序的UDP的可靠性不强。

例如,一项应用程序能经常把大量信息的数据传送到目的地而丢失少量的数据是肯定的。

在LabVIEW中使用UDP协议因为UDP不是一个TCP似的一个以连接为基础的协议,在你发送或者收到数据之前,你不需要和目的地建立一种连接。

相反,当你每发送一个数据报时,由你指定数据目的地。

操作系统不会报告传输差错使用UDP打开功能在一个端口上打开一个UDP插口。

同时打开的UDP端口的数量仍依赖于操作系统。

UDP的打开的功能返回到网络连接时唯一识别UDP套接字。

使用这种连接在子VI程序中就是靠这个套接字。

用UDP编写功能发送数据到目的地,然后使用UDP阅读功能阅读那个数据。

每写一个操作要求一个目的地地址和端口。

每阅读一个操作包含来源地址和端口。

UDP保存你所发送的每一个命令所指定的数据报字节。

在理论上,你能发送任何大小的数据报。

然而,你最好不使用UDP来发送大的数据报,因为它不像TCP一样可靠。

当你在一个端口上结束所有通信时,使用UDP结束功能去释放系统资源。

UDP多路广播你能使用UDP的功能来与一个单独的客户端通信或者通过广播对于所有局域网上的计算机通信。

如果你想要传送成倍增加具体的计算机信息,你必须通过客户端列表构建UDP功能反复执行。

因为LabVIEW能把数据的作为一个单独的拷贝发送到每个客户端并且保存对收到数据感兴趣的客户端列表,所以运用这种技术建立完全相同的网络交换。

使用多路广播可以在网络上的进行单个的发送端和多倍的客户端之间的通信而不需要保存客户列表或者要求发送端把数据多重拷贝后发送给每个客户端。

为了通过多路广播收到数据广播,所有客户端必须加入一个多路广播组。

而发送端不需要加入该组。

发送端只需规定一个多路广播的IP地址来定义这个多路广播组。

多路广播的IP地址范围在224.0.0.0到239.255.255.255中。

当一个客户端想要加入一个多路广播组时,它只需预定这个组的多路广播的IP地址。

在客户端预定到一个多路广播组之后,客户端收到从多路广播的IP 地址发送的数据。

对于LabVIEW中的多路广播,使用UDP多路广播的打开程序有能力读、写或者读和写UDP 数据。

规定TTL为写数据,多路广播地址为读数据,多路广播端口号为读写数据。

默认TTL是1,这意味着LabVIEW仅仅把数据报发送到本地的网络上。

当一个发送方收到一个多路广播数据报时,它消耗数据报的生存时间。

如果TTL大于1,发送方把数据报转发到其它数据报。

下面的表格说明了当你规定一个TTL的值时,一个多路广播数据报的运行。

0 主机上还存留数据报1 数据报发送到每个在同一本地网络上已预定那个IP地址的客户端。

中枢/转发器和桥路/开关转发数据报。

发送方不转发数据报如果TTL为1。

如果你规定一个值大于1,数据报通过TTL-1层被发送,并且发送方转发它。

参阅在LabVIEW\例子\comm\UDP.llb中的UDP多路广播接受方程序和UDP多路广播发送方程序VI中使用UDP多路广播的例程。

TCPTCP保证在网络中的可靠的通信,按顺序发送而没有差错,损失或者重发。

TCP直到收到一个确认才转发。

系统要求在使用TCP/IP之前,确认你有必需的要求,这变化依赖于你使用的平台。

(Windows和UNIX系统)TCP/IP。

你不需要使用第三种产品连接使用TCP/IP。

如果你的网络适当地被构成,LabVIEW没有要求附加的设置。

(Mac OS系统) LabVIEW网络要求打开传送,包括Mac OS 7.5和更新的版本。

在LabVIEW中使用TCPTCP是一个以连接为基础的协议,这意味着站点必须在传送数据之前建立一种连接。

TCP许可多重、同时的连接。

你可以通过等待一种输入的连接或者通过积极地寻求一种与指定的地址连接建立连接。

在建立TCP连接时,你必须指定一个地址和该地址的端口。

端口范围在0到65,535点之间。

UNIX系统为特殊的应用程序保留端口数少于1,024。

在一个给定的地址中不同的端口能识别不同的服务。

使用TCP的打开连接功能来与一个指定地址进行积极的连接。

如果连接成功,功能返回网络连接的返回数唯一识别那个连接。

使用这种连接refnum来访问子VI程序。

你能使用如下技术来等输入连接:用TCP听程序创建立一个听者并且在一个指定的端口等待一种可接受的TCP连接。

如果连接成功,VI程序返回连接数,地址和远程TCP客户端口。

TCP创建听者功创建一个听者然后用TCP的听者功能上等待的一个听者接受新的连接。

在听者功能上的TCP等待返回你所发送的功能和返回数的同样的听者ID。

当你结束等候新的连接时,用TCP关闭连接功能区关闭一个听者。

你不能对一个听者进行读写。

用第二种技术的优势是你能使用TCP关闭连接功能来取消听操作,这在你想要为了一种连接听而没有超时,但是你想要取消当另一个条件变真时的听时是很有用的。

你能在任何时间关闭听程序。

当你建立一种连接时,用TCP读功能和TCP写功能能在远程应用中队数据进行读写。

用TCP关闭连接功能区关闭远程连接。

如果没被读的仍保留着而关闭连接,你可能失去数据。

当关闭连接时,在你的计算机上使用较高层次协议。

在连接被关闭后,你不能再读写它。

TCP和UDP之间的区别在你想要可靠的数据传输时,TCP是最好的协议。

UDP是高性能的无需连接的协议,但是它不保证可靠性。

建立TCP客户端注意:请参考最近的版本LabVIEW帮助功能对这些指令和功能的细节描述。

完成如下步骤使用TCP功能建立一个TCP顾客。

1.用TCP的打开连接功能来打开一个服务器的连接。

你必须规定服务器的因特网地址和服务器的端口。

地址在网络上识别计算机。

远程端口在服务器使用听的计算机上识别一个通信通道。

当你建立一个TCP服务器时,你要规定你想要服务器为通信使用的端口。

2.用TCP的写功能把信息发送到服务器上。

3.用TCP的读功能来读发自服务器的信息。

你必须规定你想读的字节数。

4.用TCP的关闭功能来关闭与服务器的连接。

请参阅labview\examples\comm\TCP.llb中对单一数据客户端的TCP例程。

超时和差错当你设计一种网络应用时,应细心考虑失败是如何发生的。

例如,如果服务器被毁,确定如何使每个客户VI程序掌控它。

一种解决方式是确保每个客户VI程序有超时功能。

如果发生没能在一定量的时间之后生产结果,客户端继续执行。

在继续时,客户端能试图重建连接或者报告出错。

如果必要的话,客户端VI程序能关闭应用程序。

建立TCP服务器注意:请参考最近的版本LabVIEW帮助功能对这些指令和功能的细节描述。

完全如下步骤用TCP功能来建立一个TCP服务器。

1.使用TCP听程序等待连接。

你必须规定端口。

这个端口必须是客户端试图访问的同一个端口。

2.如果连接被建立,用TCP读功能从接受到信息的端口读信息。

3.用TCP写功能返回结果。

数据必须是一种客户端能接受的形式。

4.用TCP关连接功能来关闭连接。

请参阅labview\examples\comm\TCP.llb中对单一数据客户端的TCP例程。

TCP和UDP例子请参阅labview\examples\comm\TCP.llb和labview\examples\comm\UDP.llb中用TCP和UDP的VI程序和功能。

Application Note 160 Using LabVIEW™ with TCP/IP and UDP IntroductionInternet Protocol (IP), User Datagram Protocol (UDP), and Transmission Control Protocol (TCP) are basic tools for network communication. The name TCP/IP comes from two of the best-known protocols of the Internet protocol suite, the Transmission Control Protocol and the Internet Protocol.You can use TCP/IP to communicate over single networks or interconnected networks. The individual networks can be separated by large geographical distances. TCP/IP routes data from one network or Internet-connected computer to another. Because TCP/IP is available on most computers, it can transfer information among diverse systems.LabVIEW and TCP/IPYou can use the TCP/IP protocols with LabVIEW on all platforms. LabVIEW includes TCP and UDP VIs and functions you can use to create client or server VIs.IPIP performs the low-level service of moving data between computers. IP packages data into components called datagrams.A datagram contains the data and a header that indicates the source and destination addresses. IP determines the correct path for the datagram to take across the network or Internet and sends the data to the specified destination.IP cannot guarantee delivery. In fact, IP might deliver a single datagram more than once if the datagram is duplicated in transmission. Programs rarely use IP but use TCP or UDP instead.UDPUDP provides simple, low-level communication among processes on computers. Processes communicate by sending datagrams to a destination computer or port. A port is the location where you send data. IP handles thecomputer-to-computer delivery. After the datagram reaches the destination computer, UDP moves the datagram to its destination port. If the destination port is not open, UDP discards the datagram. UDP shares the same delivery problems of IP.Use UDP in applications in which reliability is not critical. For example, an application might transmit informative data to a destination frequently enough that a few lost segments of data are not problematic.LabVIEW™, National Instruments™, and ™ are trademarks of National Instruments Corporation. Product and company names mentioned herein are trademarks or trade names of their respective companies. For patents covering National Instruments products, refer to the appropriate location: Help»Patents in your software, thepatents.txt file on your CD, or /patents.342028C-01 © 2000–2004 National Instruments Corporation. All rights reserved. March 2004Using UDP in LabVIEWBecause UDP is not a connection-based protocol such as TCP, you do not need to establish a connection with a destination before you send or receive data. Instead, you specify the destination for the data when you send each datagram. Operating systems do not report transmission errors.Use the UDP Open function to open a UDP socket on a port. The number of simultaneously open UDP ports dependson the operating system. The UDP Open function returns a network connection refnum that uniquely identifies theUDP socket. Use this connection refnum to refer to this socket in subsequent VI calls.Use the UDP Write function to send data to a destination, and use the UDP Read function to read that data. Each write operation requires a destination address and port. Each read operation contains the source address and port. UDP preserves the datagram bytes that you specified for each command you send.In theory, you can send datagrams of any size. However, you typically would not use UDP to send large datagrams because it is not as reliable as TCP.When you finish all communications on a port, use the UDP Close function to free system resources.UDP MulticastYou can use the UDP functions to communicate to a single client (single-cast) or to all computers on the subnet througha broadcast. If you want to communicate to multiple specific computers, you must configure the UDP functions to iterate through a list of clients. Using this technique creates duplicate network traffic because LabVIEW sends a separate copy of the data to each client and maintains a list of clients interested in receiving the data.Use multicasting to communicate between a single sender and multiple clients on a network without requiring the sender to maintain a list of clients or send multiple copies of the data to each client. To receive data broadcast by a multicast sender, all clients must join a multicast group. The sender does not have to join a group to send data. The sender specifies a multicast IP address, which defines a multicast group. Multicast IP addresses are in the 224.0.0.0to 239.255.255.255 range. When a client wants to join a multicast group, it subscribes to the multicast IP addressof the group. After subscribing to a multicast group, the client receives data sent to the multicast IP address.To multicast in LabVIEW, use the UDP Multicast Open VI to open connections capable of reading, writing, or reading and writing UDP data. Specify the time-to-live (TTL) for writing data, the multicast address for reading data, and the multicast port number for reading and writing data. The default TTL is 1, which means LabVIEW sends the datagram only to the local subnet. When a router receives a multicast datagram, it decrements the datagram TTL. If the TTL is greater than 1, the router forwards the datagram to other routers. The following table lists what action occurs to a multicast datagram when you specify a value for the time-to-live parameter.Datagram remains on the host computer.1 Datagram sent to every client on the same local subnet that subscribes to that IP address. Hubs/repeatersand bridges/switches forward the datagram. Routers do not forward the datagram if the TTL is 1.Application Note 160 2 If you specify a value greater than 1, the datagram is sent and routers forward it through TTL-1 layers.Refer to the UDP Multicast Receiver VI and the UDP Multicast Sender VI in the labview\examples\comm\UDP.llb for examples of using UDP multicasting.TCPTCP ensures reliable transmission across networks, delivering data in sequence without errors, loss, or duplication.TCP retransmits the datagram until it receives an acknowledgment.System RequirementsBefore using TCP/IP, confirm that you have the necessary requirements, which vary depending on the platform you use.(Windows and UNIX) TCP/IP is built in. You do not need to use a third-party product to communicate using TCP/IP.If your network is configured properly, LabVIEW requires no additional setup.(Mac OS) LabVIEW networking requires Open Transport, included in Mac OS 7.5 and later.Using TCP in LabVIEWTCP is a connection-based protocol, which means that sites must establish a connection before transferring data. TCP permits multiple, simultaneous connections.You initiate a connection by waiting for an incoming connection or by actively seeking a connection with a specified address. In establishing TCP connections, you have to specify the address and a port at that address. A number between 0 and 65,535 represents a port. UNIX reserves port numbers less than 1,024 for privileged applications. Different ports at a given address identify different services at that address.Use the TCP Open Connection function to actively establish a connection with a specific address and port. If the connection is successful, the function returns a network connection refnum that uniquely identifies that connection.Use this connection refnum to refer to the connection in subsequent VI calls.You can use the following techniques to wait for an incoming connection:Use the TCP Listen VI to create a listener and wait for an accepted TCP connection at a specified port. If theconnection is successful, the VI returns a connection refnum, the address, and the port of the remote TCP client.Use the TCP Create Listener function to create a listener and use the TCP Wait on Listener function to listen for and accept new connections. The TCP Wait on Listener function returns the same listener ID you wired to the function and the connection refnum for a connection. When you finish waiting for new connections, use the TCP Close Connection function to close a listener. You cannot read from or write to a listener.The advantage of using the second technique is that you can use the TCP Close Connection function to cancel a listen operation, which is useful when you want to listen for a connection without using a timeout, but you want to cancel the listen when another condition becomes true. You can close the listen VI at any time.When you establish a connection, use the TCP Read function and the TCP Write function to read and write data to the remote application.Use the TCP Close Connection function to close the connection to the remote application. If unread data remains and the connection closes, you might lose data. Use a higher level protocol for your computer to determine when to close the connection. After a connection is closed, you cannot read from it or write to it again.© National Instruments Corporation 3 Application Note 160机械专业中英文文献翻译Deciding between TCP and UDPTCP is the best protocol to use if you want reliable data transmission. UDP is a connectionless protocol with higher performance, but it does not ensure reliable data transmission.11机械专业中英文文献翻译Creating a TCP ClientNote Refer to the LabVIEW Help for the most recent version of these instructions and details for each of thefunctions.Complete the following steps to create a TCP client using the TCP functions.1. Use the TCP Open Connection function to open a connection to a server. Y ou must specify the Internet address ofthe server and the port for the server.The address identifies a computer on the network. The remote port identifies a communication channel on the computer that the server uses to listen for communication requests. When you create a TCP server, you specify the port that you want the server to use for communication.2. Use the TCP Write function to send a message to a server.3. Use the TCP Read function to read a message from the server. Y ou must specify the number of bytes you want toread.4. Use the TCP Close Connection function to close the connection to the server.Refer to the Simple Data Client VI in the labview\examples\comm\TCP.llb for an example of a TCP client. Timeouts and ErrorsWhen you design a network application, consider carefully what should happen if something fails. For example, if the server crashes, determine how each client VI handles it.One solution is to make sure that each client VI has a timeout. If something fails to produce results after a certain amount of time, the client continues execution. In continuing, the client can try to reestablish the connection or report the error. If necessary, the client VI can shut down the application.Creating a TCP ServerNote Refer to the LabVIEW Help for the most recent version of these instructions and details for each of thefunctions.Complete the following steps to create a TCP server using the TCP functions.1. Use the TCP Listen VI to wait for a connection. You must specify the port. This port must be the same port that theclient attempts to access.2. If a connection is established, use the TCP Read function to read from that port to retrieve a message.3.Use the TCP Write function to return results. The data must be in a form that the client can accept. 4. Use theTCP Close Connection function to close the connection.Refer to the Simple Data Server VI in the labview\examples\comm\TCP.llb for an example of a TCP server. TCP and UDP ExamplesRefer to the labview\examples\comm\TCP.llb and the labview\examples\comm\UDP.llb for examples of using the TCP and UDP VIs and functions.第12 页共12 页。

相关文档
最新文档