当前位置:首页 > Labview串口Word资料-中英文
Labview串口Word资料-中英文
先是英文资料,后面有详细的中文资料。http://zone.ni.com/devzone/cda/tut/p/id/2897 Serial Instrument Control Tutorial目录 Overview of Serial Bus
Connecting and Setting up a Serial Instrument Control System How to Create a VISA Resource for the Instrument in MAX Instrument Control Software Articles and Related Links Overview of Serial Bus
Serial is a common device communication protocol for instrument control because most computers and many remote instruments include at least one serial port. Single applications can be used across a variety of instruments with few modifications, reducing programming and test time.
For more information on the serial protocol, including information on transfer speeds and important parameters, please refer to Serial Communication Overview.
Connecting and Setting up a Serial Instrument Control System
Engineers typically use serial to transmit American Standard Code for Information Interchange (ASCII) data. All data types are converted to strings of ASCII characters and then transmitted bit by bit across the serial bus. For two ports to communicate, both the instrument and the controlling computer must have the same baud rate, data bit size, stop bits, and parity.
A basic serial instrument control system consists of four parts: 1. PC 2. Serial cable 3. Serial instrument
As mentioned, most computers include a serial port. The only hardware setup required is connecting the serial cable to the serial port on the PC and the serial port on the instrument. The serial instrument may include some hardware drivers or software utilities for communication, and should include documentation on the baud rate, packet size, stop bits, and parity bits that the instrument will use. Additionally, check the National Instruments Instrument Driver Network to see if LabVIEW drivers already exist for yout instrument, as well has tutorials on how to use them.
To confirm that the serial port on your computer is working properly, refer to Serial Communication Starting Point, to see how to perform a serial loop back test.
How to Create a VISA Resource for the Instrument in MAX
With NI-VISA, communicating with your serial instrument is easy. To confirm that you are able to communicate with your instrument, open Measurement & Automation Explorer (MAX) found at Start>>Programs>>National Instruments>>Measurement & Automation.
Figure 1. MAX Main Menu
Expand the “Devices and Interfaces” subdirectory below “My System,” then expand “Serial & Parallel.” Below it you should see all the serial and parallel ports on your computer. In this example the computer has one serial port (“COM1”) and one parallel port (“LPT1”). Figure 2 shows the directory path to the serial port and the configuration window when COM1 is selected.
1
Figure 2. Serial Port Configuration Window
From this configuration window you can change the VISA Resource Name for easier identification and you can also “Open VISA Test Panel” to send and receive communication from your serial instrument. Your instrument should have specific commands for collecting and transmitting data, and sending those commands to the instrument from the VISA Test Panel will confirm that you have a connection.
Using NI-VISA to Communicate with Your Serial Instrument
NI-VISA makes serial instrument programming fast and easy. VISA Open, VISA Read, VISA Write, and VISA Close are the basic VISA functions in LabVIEW used in the example VI in Figure 3. This example opens a VISA session to a serial 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.
Figure 3. LabVIEW Serial Program Using NI-VISA
http://digital.ni.com/public.nsf/allkb/9F439B3D68D9072F4825703000383197
串口通信的基本概念
问题: 我从那里能够学到串口通信的基本知识解答: 串口通信的基本概念
1,什么是串口?2,什么是RS-232?3,什么是RS-422?4,什么是RS-485?5,什么是握手? 1,什么是串口?
串口是计算机上一种非常通用设备通信的协议(不要与通用串行总线Universal Serial Bus或者USB混淆)。大多数计算机包含两个基于RS232的串口。串口同时也是仪器仪表设备通用的通信协议;很多GPIB兼容的设备
2
也带有RS-232口。同时,串口通信协议也可以用于获取远程采集设备的数据。
串口通信的概念非常简单,串口按位(bit)发送和接收字节。尽管比按字节(byte)的并行通信慢,但是串口可以在使用一根线发送数据的同时用另一根线接收数据。它很简单并且能够实现远距离通信。比如IEEE488定义并行通行状态时,规定设备线总常不得超过20米,并且任意两个设备间的长度不得超过2米;而对于串口而言,长度可达1200米。
典型地,串口用于ASCII码字符的传输。通信使用3根线完成:(1)地线,(2)发送,(3)接收。由于串口通信是异步的,端口能够在一根线上发送数据同时在另一根线上接收数据。其他线用于握手,但是不是必须的。串口通信最重要的参数是波特率、数据位、停止位和奇偶校验。对于两个进行通行的端口,这些参数必须匹配:
a,波特率:这是一个衡量通信速度的参数。它表示每秒钟传送的bit的个数。例如300波特表示每秒钟发送300个bit。当我们提到时钟周期时,我们就是指波特率例如如果协议需要4800波特率,那么时钟是4800Hz。这意味着串口通信在数据线上的采样率为4800Hz。通常电话线的波特率为14400,28800和36600。波特率可以远远大于这些值,但是波特率和距离成反比。高波特率常常用于放置的很近的仪器间的通信,典型的例子就是GPIB设备的通信。
b,数据位:这是衡量通信中实际数据位的参数。当计算机发送一个信息包,实际的数据不会是8位的,标准的值是5、7和8位。如何设置取决于你想传送的信息。比如,标准的ASCII码是0~127(7位)。扩展的ASCII码是0~255(8位)。如果数据使用简单的文本(标准 ASCII码),那么每个数据包使用7位数据。每个包是指一个字节,包括开始/停止位,数据位和奇偶校验位。由于实际数据位取决于通信协议的选取,术语“包”指任何通信的情况。
c,停止位:用于表示单个包的最后一位。典型的值为1,1.5和2位。由于数据是在传输线上定时的,并且每一个设备有其自己的时钟,很可能在通信中两台设备间出现了小小的不同步。因此停止位不仅仅是表示传输的结束,并且提供计算机校正时钟同步的机会。适用于停止位的位数越多,不同时钟同步的容忍程度越大,但是数据传输率同时也越慢。
d,奇偶校验位:在串口通信中一种简单的检错方式。有四种检错方式:偶、奇、高和低。当然没有校验位也是可以的。对于偶和奇校验的情况,串口会设置校验位(数据位后面的一位),用一个值确保传输的数据有偶个或者奇个逻辑高位。例如,如果数据是011,那么对于偶校验,校验位为0,保证逻辑高的位数是偶数个。如果是奇校验,校验位位1,这样就有3个逻辑高位。高位和低位不真正的检查数据,简单置位逻辑高或者逻辑低校验。这样使得接收设备能够知道一个位的状态,有机会判断是否有噪声干扰了通信或者是否传输和接收数据是否不同步。
2,什么是RS-232?
RS-232(ANSI/EIA-232标准)是IBM-PC及其兼容机上的串行连接标准。可用于许多用途,比如连接鼠标、打印机或者Modem,同时也可以接工业仪器仪表。用于驱动和连线的改进,实际应用中RS-232的传输长度或者速度常常超过标准的值。RS-232只限于PC串口和设备间点对点的通信。RS-232串口通信最远距离是50英尺。
DB-9针连接头 ------------- \\ 1 2 3 4 5 / \\ 6 7 8 9 / -------
从计算机连出的线的截面。 RS-232针脚的功能: 数据:
TXD(pin 3):串口数据输出 RXD(pin 2):串口数据输入 握手:
RTS(pin 7):发送数据请求 CTS(pin 8):清除发送 DSR(pin 6):数据发送就绪 DCD(pin 1):数据载波检测 DTR(pin 4):数据终端就绪 地线:
GND(pin 5):地线
3
其他 RI(pin 9):铃声指示 3,什么是RS-422?
RS-422(EIA RS-422-A Standard)是Apple的Macintosh计算机的串口连接标准。RS-422使用差分信号,RS-232使用非平衡参考地的信号。差分传输使用两根线发送和接收信号,对比RS-232,它能更好的抗噪声和有更远的传输距离。在工业环境中更好的抗噪性和更远的传输距离是一个很大的优点。 4,什么是RS-485?
RS-485(EIA-485标准)是RS-422的改进,因为它增加了设备的个数,从10个增加到32个,同时定义了在最大设备个数情况下的电气特性,以保证足够的信号电压。有了多个设备的能力,你可以使用一个单个RS-422口建立设备网络。出色抗噪和多设备能力,在工业应用中建立连向PC机的分布式设备网络、其他数据收集控制器、HMI或者其他操作时,串行连接会选择RS-485。RS-485是RS-422的超集,因此所有的RS-422设备可以被RS-485控制。RS-485可以用超过4000英尺的线进行串行通行。
DB-9 引脚连接 ------------- \\ 1 2 3 4 5 / \\ 6 7 8 9 / -------
从计算机连出的线的截面。 RS-485和RS-422的引脚的功能 数据:TXD+(pin 8),TXD-(pin 9),RXD+(pin 4),RXD-(pin 5) 握手:RTS+(pin 3),RTS-(pin 7),CTS+(pin 2),CTS-(pin 6) 地线:GND (pin 1) 5,什么是握手?
RS-232通行方式允许简单连接三线:Tx、Rx和地线。但是对于数据传输,双方必须对数据定时采用使用相同的波特率。尽管这种方法对于大多数应用已经足够,但是对于接收方过载的情况这种使用受到限制。这时需要串口的握手功能。在这一部分,我们讨论三种最常用的RS-232握手形式:软件握手、硬件握手和Xmodem。
a,软件握手:我们讨论的第一种握手是软件握手。通常用在实际数据是控制字符的情况,类似于GPIB使用命令字符串的方式。必须的线仍然是三根:Tx,Rx和地线,因为控制字符在传输线上和普通字符没有区别,函数SetXModem允许用户使能或者禁止用户使用两个控制字符XON和OXFF。这些字符在通信中由接收方发送,使发送方暂停。
例如:假设发送方以高波特率发送数据。在传输中,接收方发现由于CPU忙于其他工作,输入buffer已经满了。为了暂时停止传输,接收方发送XOFF,典型的值是十进制19,即十六进制13,直到输入buffer空了。一旦接收方准备好接收,它发送XON,典型的值是十进制17,即十六进制11,继续通信。输入buffer半满时,LabWindows发送XOFF。此外,如果XOFF传输被打断,LabWindows会在buffer达到75%和90%时发送XOFF。显然,发送方必须遵循此守则以保证传输继续。
b,硬件握手:第二种是使用硬件线握手。和Tx和Rx线一样,RTS/CTS和DTR/DSR一起工作,一个作为输出,另一个作为输入。第一组线是RTS(Request to Send)和CTS(Clear to Send)。当接收方准备好接收数据,它置高RTS线表示它准备好了,如果发送方也就绪,它置高CTS,表示它即将发送数据。另一组线是DTR(Data Terminal Ready)和DSR(Data Set Ready)。这些现主要用于Modem通信。使得串口和Modem通信他们的状态。例如:当Modem已经准备好接收来自PC的数据,它置高DTR线,表示和电话线的连接已经建立。读取DSR线置高,PC机开始发送数据。一个简单的规则是DTR/DSR用于表示系统通信就绪,而RTS/CTS用于单个数据包的传输。
在LabWindows,函数SetCTSMode使能或者禁止使用硬件握手。如果CTS模式使能,LabWindows使用如下规则:
当PC发送数据:RS-232库必须检测CTS线高后才能发送数据。 当PC接收数据:
如果端口打开,且输入队列有空接收数据,库函数置高RTS和DTR。 如果输入队列90%满,库函数置低RTS,但使DTR维持高电平。 如果端口队列近乎空了,哭喊数置高RTS,但使DRT维持高电平。 如果端口关闭,库函数置低RTS和DTR。
c,XModem握手:最后讨论的握手叫做XModem文件传输协议。这个协议在Modem通信中非常通用。尽
4
共分享92篇相关文档