首页 基于VB的上位机与PLC通信系统实现

基于VB的上位机与PLC通信系统实现

举报
开通vip

基于VB的上位机与PLC通信系统实现 机电工程技术 2009年第 38卷第 01期机电工程技术 2009年第 38卷第 01期 基于 VB的上位机与 PLC通信系统实现 葛新锋, 晋景涛 (许昌学院电信学院, 河南许昌 461000) 收稿日期: 2008-07-16 摘要: 在开发的汽车车桥性能检测的试验系统中, 需要无级变速的交流电机作为动力输入。 为实现对交流电机的控制检测, 采用 了一种利用 VB6.0 串口通信控件 MsComm 实现计算机与 PLC 之间进行通信的方法, 来实现计算机对 PLC 的参数传递、 运行以及对 其进行...

基于VB的上位机与PLC通信系统实现
机电工程技术 2009年第 38卷第 01期机电工程技术 2009年第 38卷第 01期 基于 VB的上位机与 PLC通信系统实现 葛新锋, 晋景涛 (许昌学院电信学院, 河南许昌 461000) 收稿日期: 2008-07-16 摘要: 在开发的汽车车桥性能检测的试验系统中, 需要无级变速的交流电机作为动力输入。 为实现对交流电机的控制检测, 采用 了一种利用 VB6.0 串口通信控件 MsComm 实现计算机与 PLC 之间进行通信的方法, 来实现计算机对 PLC 的参数传递、 运行以及对 其进行实时监控, 从而实现对交流电机的控制。 实验结果 关于同志近三年现实表现材料材料类招标技术评分表图表与交易pdf视力表打印pdf用图表说话 pdf 明, 利用 VB 自身提供的串口通信控件 MsComm 很好的实现了上位工 控机对交流电机的监控。 关键词: 串行通信; 变频器; VB6. 0 中图分类号: TN915.02 文献标识码: A 文章编号: 1009-9492 (2009) 01-0053-04 图 1 ADAM4520 将 RS-232 接口转换为 RS-485 接口 工业控制 PLC 是工业常用的控制设备之一, 在工业现场, 经常 要用 PLC 去控制交流电机的转速、 转向等状态。 为提高系 统的自动化程度, 常采用上位机对 PLC 进行自动监控。 针 对这一需要, 一些公司 (如德国西门子、 日本东芝、 三菱 等公司) 推出了带有 RS-485 通信接口的 PLC, 使用户能 灵活方便地选择 PLC 来设计各自的工业控制系统。 在我们 开发的汽车车桥性能试验系统中, 需要无级变速的交流电 机作为动力输入, 以便车桥在不同转速下运转, 来检测车 桥在不同工况下的性能。 而保证 PLC 与上位工控机之间数 据的稳定传输是系统可靠运行的关键。 在这里我们介绍了 西门子 S7-200PLC 和 PC 机上提供的 RS-232 接口之间实 现串行数据传输的方法 [1]。 1串行通信的实现 1.1接口转换 一台 PC 机的一个串口可以连接一台 PLC, 也可以连 接多台 PLC, 如采用 PLC 最多可以连接 32 台 PLC。 通用 的计算机一般只具有 RS-232 接口, 而工控设备大多采用 RS-485 接口, 为了实现两者之间的通信, 需要一块接口 转换器, 来实现 RS-232 与 RS-485 之间的转换, 这比另 外增加 RS-485 接口方便而且便宜。 我们选用台湾研华公 司的 ADAM4520 转换模块, 该模块一端直接插在计算机串 口上, 另一端提供一个半双工的 RS-485 接口, 其内置的 电路可以自动地控制信号的传输方向 (如图 1 所示)。 这 种 RS-485 接口控制对用户是完全透明的, 使得对 RS-232 编写的软件可以不加修改地用在这里。 该模块需要外加一 个+10V~+30V 直流电源, 可以隔离 3000V 的高电压, 传输 速率最高可达 115.2kbit / s。 1.2 PC机和 PLC的连接图和硬件图 通用的计算机一般只具有 RS-232 接口, 而工控设备 大多采用 RS-485 接口。 ADAM4520 输出端为带有十个螺 钉接口的端子排, 从端子排出来和带有水晶头的双绞网线 连接, 水晶头可以直接插在变频器的 PU 接口上, 端子排 和双绞网线连接方法如图 2 所示。 1.3通信 方案 气瓶 现场处置方案 .pdf气瓶 现场处置方案 .doc见习基地管理方案.doc关于群访事件的化解方案建筑工地扬尘治理专项方案下载 Visual Basic (以下简称 VB) 是 Windows 环境下简单、 易学的可视化编程语言开发系统。 其可视化界面设计风格 和面向对象的程序设计等优点 , 已广泛地应用于各个领 域, 是很多计算机软件开发人员采用的开发工具。 VB 不 但提供了良好的界面设计能力, 而且在计算机串口通信方 面也有很强的功能。 采用 VB 开发 windows 下的数据采集 和工业控制应用软件十分方便, 特别是软件界面设计非常 便捷, 编程工作量较小, 开发周期短。 特别适合非计算机 专业的工程技术人员掌握和使用 [2]。 MsComm 是 Microsoft 提供的简化 Windows 下串行通信 编程的一个 ActiveX 控件, 它的核心内容是组建对象模型 53 机电工程技术 2009年第 38卷第 01期机电工程技术 2009年第 38卷第 01期 图 2 ADAM4520 端子缆连接图 表 1 MsComm 控件常用属性及其意义 属性 CommPort Settings PortOpen Rthreshold inputMode output Input InBuffercount 描述 设置或返回通信连接端口号。 默认值为 l, 即对 COMl 进行操作。 设置初始化参数。 此属性默认值为 “9600, N, 8, l”, 即串口波特率为 9600bit / s, N标识不作奇偶校验, 8位数据位, 1个停止位。 设置或传回通信端口的状态。 此值为 true 即打开端口, false 为关闭。 设置或传回引发 OnComm 事件中接收事件的字符数, 即引起接收事件的 “门槛值”。 设置或传回 Input属性取回的数据形式。 值为 0, 则以文本形式读取数据, 值为 l, 则以二进制形式读取数据。 将一个字符串写入输出寄存器, 即写端口。 从输入寄存器传回并移除字符, 即读端口。 设置接收寄存器等待读取的字符数,若其值为 0, 则清空接收寄存器区 起始字符 数据字节数 数据区 校验码 结束字符 工业控制 COM (Component Object Mode1), 是以属性和事件的形式 提 供 的 对 Windows 通 信 驱 动 程 序 API 函 数 的 接 口 。 MsComm 控件提供了事件驱动和查询两种处理通信的方法, 其中事件驱动方法在硬件上要求必须采用 Modem 方式连 接 , 并通过设置 CommEvent、 Rthreshold 等属性实现对 MsComm 控件的 OnComm 事件驱动; 查询方式则通常通过 OutPut 属性直接写输出缓冲区, 且通过 Input 属性直接读 输入缓冲区实现 。 使用 MsComm 控件开发串行通信程序 时, 一般先在窗体中添加一个 MsComm 控件, 然后对其相 关属性进行必要的设置, 再设计 OnComm 事件过程或读取 MsComm 输入缓冲区的通用过程即可 [3]。 在串口通信程序 开发中常用的属性及其意义如表 1 所示。 2 VB 下用 MsComm 实现计算机与 PLC 的 串行通信 如前所述, MsComm 控件处理接收信息的方式可以采 用事件驱动法或查询法。 用事件驱动法设计程序时, 每当 有新字符到达、 端口状态改变或发生错误时, MsComm 控 件将产生 OnComm 事件, 而应用程序在捕获该事件后, 通 过检查 MsComm 控件 CommEvent 属性可以获知所发生事件 或错误, 从而采取相应的操作。 而查询法是每当应用程序 执行完某一串口操作后, 将不断检查某一事件是否发生。 例如, 当程序向串口发送某个命令后, 等待收到一个 PLC 的特定响应串 [4]。 因为查询方式占用 CPU 的时间太多, 本例采用事件驱 动方式。 通信的界面包括一个发送按钮和一个文本框。 采 用主从方式通信, 计算机作主机, PLC 作从机。 单击 “发 送” 按钮, 计算机发送数组 Array 中的数据。 计算机接收 到可编程序控制器返回的数据后存放在数组 rcv 内, 并在 文本框内显示出来。 2.1串口及通信参数的初始化 Dim rcvlenth Dim recv () As Byte Private SubForm_load () With MSComm1 .CommPort=2 .Settings=″19200,n,8,1″ .InputMode=cominputModeBinary .RThreshold=1 .InputLen=0 .OutBufferCount=0 .InBufferCount=0 End With If Not MSComm1.PortOlsen Then MSComm1.PortOpen=True End If End Sub 2.2发送程序 要发送报文的格式为: 约定起始字符为 0, 结束字符为十六进制数 &HFF。 校验码为报文中第二个字节与数据区内各字节的异或和。 下面是发送程序的代码: Private Sub Command 1_Cick () Rcvlenth=-1 Sdata=Array (1, 2, 3) 54 机电工程技术 2009年第 38卷第 01期机电工程技术 2009年第 38卷第 01期 图 3 软件窗口 工业控制 Dim nByte () As Byte ReDim nByte (UBound (sdata) +4) nByte (0) =0 nByte (1) =UBound (sdata) +1 fcs=nByte (1) For i=2 TO UBound (sdata) +2 nByte (i) =sdata (I-2) fcs=fcs Xor nByte (i) Next nByte (i) =fcs nByte (i+1) =&HFF MSComm1.Output=nByte End Sub 2.3收数据 PLC 只有在接收到计算机发送的信息后 , 才发送数 据, 故可以将发送完成后接收到的第一个字节作为接收报 文的开始, 直到串口无接收事件时认为报文结束。 Private Sub Command 1_OnComm () Dim rcvtemp () As Byte ReDim PreservenV (100) As Byte Text1= “ ” Select Case MSComm1.CommEvent Case ComEvReceive rcvtemp=MSComm1.Input For i=LBound (rcvtemp) TO UBound (rvtemp) Rcvlenth=rcvlenth+1 Rcv (rcvlenth) =rcvtemp (i) Next i ReDim Preserve 3编程及电机调速功能实现 我们用一个简单读写的例子来说明如何应用串口实现 通信: 在 VB 工程环境下建立一个新工程, 在 Form1 中分别 添加 5 个对象 : Text1 文本 , 用来输入要传输的信息 ; Command1 按钮, 用来发送数据, 将 Text1 中的字符写入传 输寄存器; Command2 按钮, 用来接收数据, 即从串口的 寄存器中读取数据并删除字符; List1 列表框依次显示从串 口寄存器中读取的数据; Mscomml 控件, 利用它的属性进 行串口通讯 [5]。 实现数据传输的部分源代码如下: Private Sub Command1 Click () ‘向变频器发送 数据函数按钮 Dim TempStr1,TheCodeStr, StrOutput, As String ‘定 义三个字符串变量 TempStr1 = Data2Hex ((Text1.Text ) ‘将 Text1.Text 中的数据转换为十六进制 TempStr1 = ″00EE1″ + TempStr1 ‘00EE1 为变 频器号+指令代码 TheCodeStr = CodeSum (TempStr1) ‘CodeSum 子 函数实现总和校验功能 StrOutput = Chr$ (&H5) & TempStr1 + TheCodeStr + vbCr ‘要发送到变频器的字符串 StrOutput If MSComm1.PortOpen Then ‘关闭串行口 MSComm1.PortOpen = False End If If MSComm1.OutBufferCount = 0 Then ‘检测输出 缓冲区是否有数据 MSComm1.Output = StrOutput ‘将 StrOutput 字符串发送到变频器 End If End Sub ‘结束 Private Sub Command2 Click () ' 判断串口是否打 开, 如果没有打开, 打开串口并初始化 If Mscomm1.PortOpen =False Then Mscomm1.PortOpen =True Mscomm1.Settings=″9600, n, 8, 1” '9600 波特率, 无 校验, 8 位数据位, 1 位停止位 Mscomm1.InputLen=1 ‘设定串口读入 的字符串长度为 1 Mscomm1.RThreshold=1 ‘当接收寄存器达到 1 个字符时, 引发接收事件 End If End Sub Private Sub Form Load () ‘窗体装载函数 Mscomm1.CommPort= 2 ‘设定 Com2 用 来进行串口通讯 If Mscomm1.PortOpen=False Then Mscomm1.PortOpen=True End If Mscomm1.OutBufferCount=0 ‘清空发送缓冲区 55 机电工程技术 2009年第 38卷第 01期机电工程技术 2009年第 38卷第 01期 图 6 主程序流程图 图 7 循迹子程序流程图 Mscomm1.InBufferCount=0 ‘清空接收缓冲区 End Sub Private Sub Mscomm1 _OnComm () ‘显示接收 数据函数 Dim buffer As String ‘定义 buffer 为字符串 buffer=Mscomm1.Input ‘将接收寄存器 中的字符赋值给 buffer List1.Addltem buffer ' 将 buffer 的值加入 到列表框中显示出来 End Sub 以上是简单的原理代码, 读者可以结合自己的需要设 计一些其他的控件和对象, 就可以实现很多功能。 作者就 是利用该控件的串口和工控机连接, 实现了电机的无级调 速、 正反转运行及状态监测等功能。 4结束语 本文以西门子 S7-200 PLC 为例, 介绍了一种运用 VB 自身提供的串口通信控件 MsComm 实现上位机与 PLC 之间 的通信方法, 并将其应用于我们开发的汽车车桥性能试验 系统中, 很好的实现了上位工控机对 PLC 的控制监测。 系 统在进行实时控制任务时, 控制处理能力强、 工作可靠稳 定。 本方法对于其它类型 PLC 及类似设备与上位机的串口 通信也有一定的参考价值。 参考文献: [1] 范逸之, 陈立元. Visual Basic 与 RS.232 串行通信控制最新 版 [M] . 北京: 中国青年出版社, 2000. [2] 张正华, 杜宇人. 在 VB 下智能仪器和 PC 机之间的数值通信 [J] . 计算机应用, 2001 (1): 3-4. [3] 葛新锋, 董永强. 串口通信数据传输及其在变频器控制中的 应用 [J] . 继电器, 2007 (17): 72-75. [4] 高钦和. 可编程序控制器应用技术与设计实例 [M] . 北京: 人民邮电出版社, 2004. [5] 葛新锋, 晋景涛. 串口通信数据在变频器中实现传输的方法 [J] . 许昌学院学报, 2007 (5): 33-36. 第一作者简介: 葛新锋, 男, 1978 年生, 河南许昌人, 硕士研究 生, 讲师。 研究领域: 机电控制。 已发表论文 7 篇。 (编辑:吴智恒) !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (上接第 15 页) 工业控制 运行时能够基本满足要求。 汽车智能控制看似一个简单的 电控问题, 却也涉及声、 光、 电等多个领域, 如与单片机 相结合, 通过软件优化, 控制可更便捷、 有效。 参考文献: [1] 马淑华, 王凤文. 单片机原理与接口技术 [M] . 北京: 北京 邮电大学出版社, 2005. [2] 孙涵芳. MCS-51 / 96 单片机原理及应用 [M] . 北京: 北京航 空航天大学出版社, 2005. [3] 赵亮, 侯国锐. 单片机 C 语言编程与实例 [M] . 北京: 人民 邮电出版社, 2003. [4] 张洪润, 傅瑾新. 传感器应用电路 200 例 [M] . 北京: 北京 航空航天大学出版社, 2006. [5] 赵巧娥. 自动检测与传感器技术 [M] . 北京: 中国电力出版 社, 2005. [6] 童诗白. 模拟电子技术基础 [M] . 北京: 高等教育出版社, 2000. 第一作者简介: 张 拓, 男, 1984 年生, 湖南临湘人, 硕士研究 生。 研究领域: 嵌入式系统、 智能控制。 (编辑:吴智恒) 56 114 Abstracts characteristics air suspension system, through different operating point, establish the reference model based on the optimum regulating control, thus realizing linearization. Considering the air spring characteristics, the dynamic correction is made for its rigidity K. At the same time, the inter-conversion issue of the active control suspension controlling strategy and the semi- active control strategy question is also discussed. The realization plan is proposed based on TMS320C2406 DSP controller of TI Corporation. air suspension; reference model adaption; optimum regulator; TMS320C2406 A STEP7 and WinCC based method of controlling PID is introduced. The PID control is realized by the FB41 function of S7-300 PLC. In this way, the real-time monitoring system can run based on WinCC. This method has advantages of direct-viewing display of graphical and easy setup of parameters, etc. real-time supervisory; WinCC configuration; PID; PLC; programming Fuzzy control is a newly arisen control strategy, providing an effective way of the control of many objects which are hard to model. Many successful applications with fuzzy control show that it is an effective control method. Central air- conditioning is a huge energy-consumer in modern city, considering operation characteristics of central air- conditioning and it is suitable that fuzzy control is applied in central air conditioning system. According to the structure and operation principle of central air-conditioning cooling water system, design a fuzzy controller. Practice shows that cooling water system can work stably and effectively. central air-conditioning, cooling water; fuzzy control This article introduces the role and the principle of work of DEC’s control system of passim cigarette maker, and expounds the drawbacks of original DEC’s control system of passim cigarette maker. At the same time the improved proposal is made to aim at the drawbacks. At last discourses the principle of work and advantages of the improved DEC’s control system. PASSIM cigarette maker; DEC; control system; improvement The microprocessor service power f st cutting device is used to inhibit misoperation in introduction, in order to simplify operation and ensure continuous power supply for auxiliary equipment and safe operation. Replacement of spare automatic switch device by power fast cutting device to enhance safety reliability is used in power system. This paper illustrates kinds of automatic transfer mode in auxiliary supply system, and explains the whole transfer period in detail. Microprocessor Service Power Fast Cutting; application; analysis Electronic fuel injector tester is controlled by two single chips of AT89C52, and the user interface is realized in a computer. So it is needed to realize the communication of the computer with two single chips. The user interface is programmed with MFC, and data transmission is realized with MSComm component. The single chips are programmed in C51. Now the computer can successfully monitor the tester. serial communication; MSComm; VC++; electronic fuel injector tester In the experimental of checking and measuring the motor vehicle bridge’s function, the successive changing speed AC electromotor provide power. In order to control and monitor the AC electromotor, a method of communication between a host computer and PLC is introduced with Microsoft Communication Control based on Visual Basic 6.0, which realizes the transmission of parameters, the control of running and real-time supervision of PLC and the control of AC electromotor by the host computer. The results indicate that the host computer monitor the PLC well using Microsoft Communication Control based on Visual Basic 6.0. communication system; PLC; Visual Basic 6.0 The remote fault diagnosis system for elevator based on Internet communication technology, tracking the Fault source at the first time and send the fault data to the remote computer though Internet when elevator electronic fault happened. The on- line fault diagnosis and states monitor will be carried out by the fault diagnosis system built in the remote computer though analyzing the fault signals. elevator; rule reasoning; expert system; fault decision; fault tree The types of NC machine tools, numerical control machine tools reverse of regular machinery space, is to ensure Key words: LUO Geng-xing, NING Yu-shan Abstract: Key words: LIANG Hui -hong , SHI Bu-ha i , GONG Guan- xiang Abstract: Key words: LIU Rong-hui Abstract: Key words: LAN Ru-ping Abstract: Key words: LIU An-ning , YAO Xi-fan Abstract: Key words: GE Xin-feng, JIN Jing-tao Abstract: Key words: REN Shi-bo, LV Jia-bin, CHEN Ze-lai Abstract: Key words: LI En-xue Abstract: , a 1 2 09-01-3 09-01- 3 09-01- 09-01- 09-01- 09-01- 3 09-01- 09-01- 9 PID Control Based on WinCC and PLC 4 Research on Central Air-Conditioning Cooling Water Fuzzy Control System 46 Improvement of DEC’s Logic Control System of PASSIM Cigarette Maker 47 Application and Analysis of Microprocessor Service Power Fast Cutting Device in Power System 50 Research on Communication of Electronic Fuel Injector Tester with Computer 5 The Communication System of Host Computer Based on VB and PLC 57 The Remote Fault Diagnosis System for Elevator Based on Internet Communication 60 The Determination and Compensation of CNC Lathes Reverse Mechanical Clearance (Guangdong Songshan Polytechnic College, Shaoguan512126, China) (Automation College of Science and Engineering South China University of Technology Guangzhou 510640 China) (Wuhu Cigarette Factory, Wuhu241002, China) (Shaoguan Power Station, Shaoguan512132, China) (1.School of Mechanical Science&Engineering, Huazhong University Science and Technology, Wuhan430074, China; 2.College of Mechanical and Automotive Engineering, South China University of Technology,Guangzhou510641, China) (Xuchang University, Xuchang461200, China) (Nanjing Special Equipment Vessel Supervisory Institute, Nanjing210002, China) (Foshan Senior Technical School, Foshan528200, China) , ,
本文档为【基于VB的上位机与PLC通信系统实现】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_984377
暂无简介~
格式:pdf
大小:331KB
软件:PDF阅读器
页数:5
分类:互联网
上传时间:2011-06-10
浏览量:57