MATLAB串口操作官方教程(2014版)v1.2

所需积分/C币:50 2016-04-12 10:58:35 1.45MB PDF
25
收藏 收藏
举报

MATLAB串口操作官方操作教程,详细的介绍了在Matlab2014中如何开发串口相关代码
Serial Port devices MATLAB R2012b 目录:教程和实例 Examples and how to Introduction介绍 Overview of the serial port串口总览 · Getting Started with Serial lyo开始串口工作 Creating a Serial Port Object建立一个串囗对象 Connecting to the device连接设备 Configuring Communication Settings配置通讯参数 WI d Reading Data读写数据 Events and callbacks事件和回调用 Using Control Pins使用控制针脚 Debugging: Recording Information to Disk调试:将信息记录在磁盘上 Saving and Loading保存和装载 Disconnecting and Cleaning Up断开和清空 · Property Reference属性参考 Properties= Alphabetical List属性一按字母表排序 Serial Port devices MATLAB R2012b 介绍 troduction On this page…,本节包含内容: What| s the matlaB serial Port interface?什么是 MATLAB串囗接囗 Supported Serial Port Interface Standards支持的串口标ⅶ准 Supported Platforms支持的平台 sing the Examples with Your Device使用你的设备的例程 What is the matlab seria| Port interface?什么是 MATLAB 串口接口 MAπLAB串口接口提供了一个对外围设备的直接访问。比如连接在你的计算机上的 moden 打印机和其他技术设备。这个接口实际上建立在你的串口对象上,串口对象支持你的函数和 功能,让你可以实现以下的操作: Configure serial port communications完成串口的通信 Use serial port control pins使用串口控制指针 Write and read data读写数据 Use events and callbacks使用事件和回调 Record information to disk记录信息到磁盘 设备控制工具箱提供了一个增强的串口功能包,在命令行的基础上,它提供图形化的用户界 面,叫做测试和测量工具。你可以用它来与你的串口设备连接,通信,配置,传输数据等操 作,而不需要敲入代码。测试测量工具箱可以帮助你生成代码,让你用把代码用在那些需要 代码的场合,比如GUI设计。工具箱还包含了增强的串口操作功能,包括串口对參的建立, 配置,设备的通信等等。你可以用它来和GPIB或者ⅥSA兼容的设备通信 如果你想和ρc兼容的数据釆集硬件通信,比如多功能的Io板,你就需要数据采集工具箱 软件。 Serial Port devices MATLAB R2012b 你可以访问产品中心:ht://www.mathworks.com/products Supported Serial Port Interface Standards支持的串口标准 多年以来,有很多串口通信的标准,被开发出来。比如RS-232,RS-422, and rs-485,这 些标准都是被 MATLAB支持的。在他们当中最广泛使用的要数RS232标准。 这个向导文件,假设你使用的是RS232标准,在“串口总览”部分也默认使用RS232标准。 请参考你的计算机和设备文档,弄清楚你在使用哪种标准。 Supported Platforms支持的平台 ● Linux32-bit Linux 64-bit Mac oS x ● Mac os x64-bit Microsoft windows 32-bit Microsoft windows 64-bit Using the Examples with Your Device使用你的设备的例程 这里我们提供的很多例程都是针对特定的外围设备的,我们使用的是 Tektronix③TDS210 双通道示波器连接在COM1接口上,运行在 Windows平台上,因此,很多文字的命令是 针对这个平台和设备的。如果你在使用不同的平台或者使用不同的外围设备,或者使用不同 的串口号,请按照你的设备修改例程。 4 Serial Port devices MATLAB R2012b 串口总览 Overview of the serial port On this page.本节包含内容 ntroduction介绍 What s serial communication?什么是串口通信 The serial port interface standard串口通信标准 Connecting TWo Devices with a Serial Cable用串口线连接两个设备 Serial Port Signals and Pin assignments串口信号和针脚分布 Serial data format串囗数据格式 Finding Serial Port Information for Your Platform为你的平台找到串口的信息 Using virtual USB Serial Ports使用虚拟USB-串口 Selected Bibliography参考书目 1介绍 对于许多串口通信的应用来讲,你不需要知道串口具体的工作机制,就可以和目标设备进行 通信。如果你对上述条目已经很熟悉,你不需要再阅读本章节,你可以直接阅读 Getting Started with serial i/O开始串口工作”章节。 2什么是申口通信 串口通信是适用于—个或多个设备之间的,底层通信协议。通常一个设备是一个计算机,其 他设备是一个猫或者一个打印机或者计算机,或者科学技术外围设备,比如示波器,函数信 号发生器等等。 此部分有电子或计算机基础的人都已经很熟悉,就暂时跳过这里,请百度或参考源网址 http://www.mathworks.com/help/matlab/matlab_external/overview-of-the-serial-port.html 3串口通信标准 暂时跳过 4用串口线连接两个设备 暂时跳过 5 Serial Port devices MATLAB R2012b 5串口信号和针脚分布 Serial ports consist of two signal types: data signals and control signals. To support these signal types as well as the signal ground the rs-232 standard defines a 25-pin connection. However, most Windows and UNIX 1 platforms use a g-pin connection. In fact, only three pins are required for serial port communications: one for receiving data, one for transmitting data, and one for the signal ground The following diagram shows the pin assignment scheme for a 9-pin male connector on a dtE The pins and signals associated with the 9-pin connector are described in the following table. Refer to the Rs-232 standard for a description of the signals and pin assignments used for a 25-pin connector Serial Port Pin and signal Assignments In Label Signal Name Signal Type CD Carrier Detect Control RD Received data Data Transmitted Data Data DTR Data Terminal read Control GND Signal Ground Ground DSR Data set read Control RTS Request to Send Control CTS Clear to send Control Ring Indicato Control The term data set is synonymous with modem or device, while the term data terminal is synonymous with computer. Note The serial port pin and signal assignments are with respect to the dtE. For example data is transmitted from the td pin of the dte to the rd pin of the dce Signal States Signals can be in either an active state or an inactive state. An active state corresponds to the binary value 1, while an inactive state corresponds to the binary value 0. An active signal state is often 6 Serial Port devices MATLAB R2012b described as logic 1, on, true, or a mark. An inactive signal state is often described as logic 0, off, false, or a space For data signals, the on state occurs when the receive nal voltage is more negative than 3 volts while the off state occurs for voltages more positive than 3 volts For control signals, the on state occurs when the received signal voltage is more positive than 3 volts, while the off state occurs for voltages more negative than-3 volts. The voltage between -3 volts and +3 volts is considered a transition region and the signal state is undefined To bring the signal to the on state, the controlling device unasserts(or lowers) the value for data pins and asserts(or raises)the value for control pins. Conversely, to bring the signal to the off state,the controlling device asserts the value for data pins and unasserts the value for control pins The following diagram shows the on and off states for a data signal and for a control signal Data sigmal ontro] Signal 0 The data pins Most serial port devices support full-duplex communication meaning that they can send and receive data at the same time. Therefore, separate pins are used for transmitting and receiving data. For these devices, the TD, RD, and gnd pins are used. However, some types of serial port devices support only one-way or half-duplex communications. For these devices, only the td and Gnd pins are used. This guide assumes that a full-duplex serial port is connected to your device The td pin carries data transmitted by a dte to a dCE. the rd pin carries data that is received by a DtE from a dce The Control pins The control pins of a 9-pin serial port are used to determine the presence of connected devices and control the flow of data. The control pins include ● The rts and cts pins The dtr and dsr pins The cd and ri pins The RTS and cTs Pins. The rts and cts pins are used to signal whether the devices are ready to send or receive data. This type of data flow control-called hardware handshaking-is used to prevent data loss during transmission When enabled for both the dtE and dCE, hardware handshaking using RTS and cts follows these steps 1. The dtE asserts the Rts pin to instruct the dCe that it is ready to receive data 2. The dCE asserts the cts pin indicating that it is clear to send data over the TD pin. If data can no longer be sent, the Cts pin is unasserted 3. The data is transmitted to the dte over the td pin. If data can no longer be accepted, the rts pin is unasserted by the dtE and the data transmission is stopped Serial Port devices MATLAB R2012b To enable hardware handshaking in MATLAB software, see Controlling the Flow of Data: Handshaking The DTR and DSR Pins. Many devices use the DSR and dTR pins to signal if they are connected and powered. Signaling the presence of connected devices using dtr and dsr follows these steps 1. The dtE asserts the dtR pin to request that the dce connect to the communication line. 2. The dCE asserts the dsr pin to indicate it is connected 3. dCe unasserts the dsr pin when it is disconnected from the communication line The dtR and dsr pins were originally designed to provide an alternative method of hardware handshaking. However, the Rts and Cts pins are usually used in this way, and not the DSR and DTR pins. Refer to your device documentation to determine its specific pin behavior. The CD and ri Pins. The cd and ri pins are typically used to indicate the presence of certain signals during modem-modem connections. A modem uses a CD pin to signal that it has made a connection with another modem, or has detected a carrier tone. CD is asserted when the dce is receiving a signal of a suitable frequency. CD is unasserted if the dce is not receiving a suitable signal The ri pin is used to indicate the presence of an audible ringing signal. i is asserted when the dce is receiving a ringing signal. RI is unasserted when the dce is not receiving a ringing signal (e. g, it is between rings) 6串口数据格式 暂时跳过 7为你的平台找到串口的信息 暂时跳过 8使用虚拟UsB-串口转接器 暂时跳过 9参考书目 暂时跳过 Serial Port devices MATLAB R2012b 开始串口工作 Getting Started with Serial IO On this page.本节包含内容 EXample: Getting Started例程:开始 The serial Port session串口对象会话 Configuring and Returning Properties配置和返回属性 Example: Getting started例程:开始 这个例子包含了一些基本的串口命令,注意是基于 windows平台的。如果你有一个连接在 COM1上的串口设备,要设置波特率在4800,可以使用以下的代码 s= serial( COM1) set(s, BaudRate4800)i (s); fprintf(s,*IDN? out fscanf(s) fclose(3 delete(s) clear s ■西■■■■mm 上面代码中*DN?是向设备发送查询身份的信息,如果你使用的设备不支持,可能无法得 到返回数据到out中清根据你的设备进行相应修改。杋IDN?是可编程设备标准命令(ScPI) 语言支持的命令,很多 moden设备支持,参考你的设备文档,看是否支持SCP语言。(译 者按:如有疑问,请继续看串口会话部分,配置相应的参数。 The seria| Port session串口对象会话 这一部分例程提供了一些你从头到尾都要用到的对串口会话的操作,这些步骤包括 建立一个串口对象-使用s∈ria1创建函数对一个特定的串口创建串口对象 在这里,你可能要用到属性配置,比如波特率,数据位数等等。 ·对设备进行连接一要使用fp=:函数来实现串口对象与设备的连接。当设备连接以后可以通 过切换合适的值,读或写数据,来更换必要的设备。

...展开详情
试读 72P MATLAB串口操作官方教程(2014版)v1.2
立即下载
限时抽奖 低至0.43元/次
身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
关注 私信
上传资源赚钱or赚积分
最新推荐
MATLAB串口操作官方教程(2014版)v1.2 50积分/C币 立即下载
1/72
MATLAB串口操作官方教程(2014版)v1.2第1页
MATLAB串口操作官方教程(2014版)v1.2第2页
MATLAB串口操作官方教程(2014版)v1.2第3页
MATLAB串口操作官方教程(2014版)v1.2第4页
MATLAB串口操作官方教程(2014版)v1.2第5页
MATLAB串口操作官方教程(2014版)v1.2第6页
MATLAB串口操作官方教程(2014版)v1.2第7页
MATLAB串口操作官方教程(2014版)v1.2第8页
MATLAB串口操作官方教程(2014版)v1.2第9页
MATLAB串口操作官方教程(2014版)v1.2第10页
MATLAB串口操作官方教程(2014版)v1.2第11页
MATLAB串口操作官方教程(2014版)v1.2第12页
MATLAB串口操作官方教程(2014版)v1.2第13页
MATLAB串口操作官方教程(2014版)v1.2第14页
MATLAB串口操作官方教程(2014版)v1.2第15页

试读结束, 可继续读5页

50积分/C币 立即下载