组态王与 OPC的AB软件 - 图文

更新时间:2024-03-31 11:40:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

在组态王

与Rockwell Automation PLC的连接。

Rockwell Automation 的A-B PLC是一个著名的可编程控制器产品。其产品体系基本上涵盖了工业控制产品的各个领域,并以产品的可靠而著称。在国内的PLC市场的占有率将近30%。

由于A-B的PLC的种类繁多,且各种类型的PLC支持的通信协议不尽相同,使得第三方的HMI软件都不能很好的与A-B PLC进行连接。RSLinx软件是A-B PLC通用的通信配置软件(2.2以上的版本支持对以太网的网关配置),目前主要有以下几个版本:RSLinx OEM、 RSLinx Professional 、RSLinx Gateway、 RSLinx SDK四个版本。且均支持OPC服务(2.3版以上支持OPC2.0版)。

组态王软件已内嵌了OPC服务功能,支持OPC客户端和OPC服务器的工作方式。这样组态王就可以很方便的与A-B PLC进行通信。 具体的配置方法如下:

在组态王与A-B PLC进行OPC的配置是必须要有A-B PLC及相关的通讯附件。 1、 安装A-B PLC 、通讯卡、相关的软件,并作物理连接 2、 使用RSLinx连接A-B PLC的通讯网络。

配置通讯卡(参加图-1),选择ConFigure Drivers。

图-1

弹出入下的配置窗口(参见图-2)。

图-2

选择对应的通讯卡,并进行端口配置(可参照附带的安装手册),配置成功后将显示所配置的设备的运行状态。

使用RSWho命令查找连接的PLC设备(参见图-3)。

参见图-3

RSWho命令成功的执行后,将在设备列表中列出与本机连接的所有硬设备。 使用Topic Configoration来进行OPC服务的配置(参见图-4)。

图-4

在Date Source配置框中配置Topic,选择一个物理设备(PLC),按New按钮即可建立一个Topic,单击Done即可(参见图-5)。

图-5

3、 在组态王中建立y与OPC设备的连接。

添加OPC设备。在组态王的工程器中选择设备?OPC服务器?新建,则弹出如下的窗口(参见图-6)。在OPC服务器列表中选择RSLinx OPC Server?选择确定即可。

参见图-6

在数据字典里加入IO点(参见图-7)

在组态王的工程器中选择数据库?数据字典?新建。确定变量名、变量类型等变量属性,在连接设备中选择RSLinx OPC Server ;手工键入寄存器地址,地址的格式为:”[Topic名]变量别名”或”Topic名:变量寄存器地址”。单击确认即可。

图-7

4、 附加的文档,A-B提供的说明文件。

Public Groups RSLinx does not support public groups. Public groups are an optional part of the OPC specifications. However, behind the scenes, if two clients request the same information from a single instance of RSLinx, RSLinx will not read the data twice from the target processor. It will provide the same data to both clients, which is similar in effect to public groups. As of v2.31, RSLinx does not support OPC within the .NET framework. The current Automation Interface conforms to the Visual Basic automation interface standards used in previous versions of Visual Basic. VB.NET uses different underlying technology.

Future development is planned, but Rockwell Automation, like other OPC servers, must wait for an OPC .NET interface specification from the OPC Foundation.

This document will provide a comparison between RSData and the RSLinx OPC Automation interface and is intended to provide guidelines for converting an existing application. For the purpose of this document, the PokeNRequest example was converted from an RSData application to an RSLinx OPC Automation Application. Both applications are attached to this technote for your review and are provided as-is for demonstration purposes only.

This document applies to the following software versions. There may be slight differences in functionality with other revisions.

? ? ? ?

RSData 1.60.01

RSJunctionBox 1.60.01

RSLinx SDK 2.30.02 (Build 79)

VisualBASIC 6.0 with Service Pack 5

PLEASE NOTE: RSLinx SDK (9355WABCENE) provides documentation on how to use the Automation Interface, development support, and samples. All other flavors of RSLinx provide the Automation interface as-is (no documentation, no support, no samples).

A key difference between the two is that RSData (and the other RSTools) is an ActiveX control, which provides a user interface, properties, methods and events. The RSLinx OPC Automation Interface is an Object Interface which provides properties, methods and events but no user interface. The RSTools ActiveX controls are also data-bound controls which enable you to link directly to a database with little or no additional code. The OPC Automation Interface does not have this capability. You will need to write code to link to a database.

The following RSData Properties are NOT SUPPORTED with the RSLinx OPC Automation Interface. Display Related Properties AutoColumns BackColor BackStyle BevelHeight BevelHighlight BevelShadow BevelStyle BevelWidth BorderColor BorderInner BorderInnerColor CaptionTransparent CaptionX CaptionY CausesValidation DecimalPlaces DisplayCaption GridOn GridWidth Height HelpContextID Index Left ScrollTopRow TabIndex TabStop Tag ToolTipText Top TopBorders TrailingZeros ValueBackColor ValueColor ValuePadDownload DisplayCaptionVertical LeftBorder DisplayPicture DisplayValue DragIcon DragMode LinkTip LinkTipBackColor LinkTipForeColor LinkTipText BorderStyle BorderWidth BottomBorder Caption CaptionBackColor CaptionColor CaptionShadow DrawDisabledShadow Picture Enabled FlashEnabled FlashOn FlashSpeed FlashTime Font PicturePath PictureStretch RightBorder ScreenPriority ScrollColumnHeight ScrollColumnWidth ScrollFirstColumn ValueShadow ValueShadowColor ValueTransparent ValueX ValueY Visible WhatsThisHelpID Width CaptionShadowColor GridColor Database Related Properties DataBindings DataField DataFormat DataMember DataSource DataUpdate Other Unsupported Properties EndValue StartValue UseStartEndValue ExpressionForRead ExpressionForWrite WriteValue PokeType LinkErrorDisplay Symbol

The following RSData Events are NOT SUPPORTED with the RSLinx OPC Automation Interface. Display Related Events Click DblClick DragDrop DragOver GotFocus KeyDown KeyPress KeyUp LostFocus MouseDown MouseMove MouseUp Other Unsupported Events LinkError LinkItemSupported LinkOutOfMemory ScrollPosChanged Validate LinkItemNotSupported LinkNotify LinkServerDisconnected LinkUnableToConnectToServer

The following RSData Methods are NOT SUPPORTED with the RSLinx OPC Automation Interface. Display Related Methods AboutBox Drag Move SetFocus ShowValuePad ShowWhatsThis

The following tables list the RSData Properties, Events and Methods that have an equivalent in the RSLinx OPC Automation Interface. In the following table, the information in italics is a code sample of the Property, Event or Method.

RSData RSLinx OPC Automation Interface Equivalent Properties LinkServer MyRSData.LinkServer = \ OPCServer.Connect OpcServer.Connect \

LinkTopic MyRSData.LinkTopic = \ LinkItem MyRSData.LinkItem = \ LinkMode MyRSData.LinkMode = 1, 2, or 3 CommunicationMode MyRSData.CommunicationMode Synchronous, Asynchronous AllowChangeEvent MyRSdata.AllowChangeEvent = True, False These two properties are combined in the AddItems Method of the OPCGroup object. OpcGroup.OPCItems.AddItem \ These three properties are combined in the IsSubscribed Property of the OPCGroup object. OPCGroup.IsSubscribed = OpcGroup.IsSubscribed = True The IsSubscribed property must be set to true to enable callbacks and thus events for the OPCGroup object. The OPCGroup Object must be declared \as well. IsSubscribed = True is equivalent to LinkMode = 1, CommunicationMode = Asynchronous and AllowChangeEvent = True. IsSubscribed = False is equivalent to LinkMode = 2, CommunicationMode = Synchronous and AllowChangeEvent = False. NOTE: LinkMode = 3 (LinkNotify) is not supported with the RSLinx OPC Automation Interface. Also, you can perform Synchronous I/O when IsSubscribed is set to True. RequestLength MyRSData.RequestLength = 6 RequestStartIndex MyRSData.RequestStartIndex = 0 UseInRequest MyRSData.UseInRequest False = True, There is no equivalent of these properties in the RSLinx OPC Automation Interface but some parameters of the OPCGroup's SyncRead and AsyncRead Methods can be used to replicate this behavior. Specifically: RequestLength = lNumItems parameter RequestStartIndex and UseInRequest = arHandles (an Array containing the Item Handles for all Items you wish to Read) NOTE: With the RSLinx OPC Automation Interface you must read and write all items within the group. The code snippets below demonstrate this. PokeLength MyRSData.PokeLength = 6 PokeStartIndex MyRSData.PokeStartIndex = 0 There is no equivalent of these properties in the RSLinx OPC Automation Interface but some parameters of the OPCGroup's SyncWrite and AsyncWrite Methods can be used to replicate this UseInPoke behavior. PokeLength = lNumItems parameter PokeStartIndex and UseInPoke = arHandles (an Array containing the Item Handles for all Items you wish to Write) NOTE: With the RSLinx OPC Automation Interface you must read and write all items within the group. The code snippets below demonstrate this. Methods MyRSData.UseInPoke = True, False Specifically: LinkPoke MyRSData.LinkPoke DoPoke MyRSData(0).PokeStartIndex = 0 MyRSData(0).PokeLength = 6 For i% = 0 To 5 MyRSData(i%).UseInPoke = True Next i% MyRSData(0).DoPoke The Write method of the OPCItem Object MyOPCItem.Write value The SyncWrite Method of the OPCGroup Object (Use this method if you have set the to RSData.CommunicationMode Synchronous) lNumitems = MyOPCGroup.OPCItems.Count ReDim arHandles(1 To lNumitems) ReDim arValues(1 To lNumitems) For i = 1 To lNumitems arHandles(i) MyOPCGroup.OPCItems(i).ServerHandle arValues(i) Next MyOPCGroup.SyncWrite arValues, arErrors lNumitems, arHandles, = txtData(MyOPCGroup.OPCItems(i).ClientHandle).Text = property The AsyncWriteMethod of the OPCGroup Object (Use this method if you have set the to RSData.CommunicationMode Asynchronous) lNumitems = MyOPCGroup.OPCItems.Count ReDim arHandles(1 To lNumitems) ReDim arData(1 To lNumitems) For i = 1 To lNumitems arHandles(i) MyOPCGroup.OPCItems(i).ServerHandle arData(i) Next 'i MyOPCGroup.AsyncWrite LinkRequest MyRSData.LinkRequest DoRequest lNumitems, arHandles, arData, arErrors, lTransID, lCancelID The Read method of the OPCItem Object MyOPCItem.Read vQuality, vTimeStamp The SyncRead method of the OPCGroup Object this method if you have the MyRSData(0).RequestStartIndex = 0 (Use OPC_DS_CACHE, vValue, = txtData(MyOPCGroup.OPCItems(i).ClientHandle).Text = property MyRSData(0).RequestLength = 6 For i% = 0 To 5 Next i% MyRSData(0).DoRequest RSData.CommunicationMode Synchronous) property set to MyRSData(i%).UseInRequest = True lNumitems = MyOPCGroup.OPCItems.Count ReDim arHandles(1 To lNumitems) For i = 1 To lNumitems arHandles(i) MyOPCGroup.OPCItems(i).ServerHandle Next 'i '/* Read Group data from Cache MyOPCGroup.SyncRead lNumitems, arHandles, arValues, arErrors, arQualities, arTimeStamps OPC_DS_CACHE, = The AsyncRead Method of the OPCGroup Object (Use this method if you have set the to RSData.CommunicationMode Asynchronous) lNumitems = MyOPCGroup.OPCItems.Count ReDim arHandles(1 To lNumitems) For i = 1 To lNumitems 'pass in server handles arHandles(i) MyOPCGroup.OPCItems(i).ServerHandle Next 'i MyOPCGroup.AsyncRead Events Change Private String, ByVal iIndex As Integer) the values End Sub PokeCompleted Private iRet As Integer) dependant on the poke completing. End Sub MyRSData_PokeCompleted(ByVal DataChange Event of the OPCGroup Object Sub Private Sub MyOPCGroup_DataChange(ByVal lNumitems, arHandles, arErrors, lTransID, lCancelID = property MyRSData_Change(ByVal sValue As TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, 'You would write code here to evaluate and display the values, qualities, and timestamps of the data End Sub AsyncWriteComplete Event of the OPCGroup Object Sub Private Sub MyOPCGroup_AsyncWriteComplete (TransactionID As Long, NumItems As Long, ClientHandles() As Long, Errors() As Long) occured during the write process End Sub NOTE: Since Errors() are returned in the AsyncWriteComplete Event, you no longer need to monitor a LinkError event separately. Any code in the RSData LinkError Event could be moved to these events when using When Asynchronous using Group communications. Synchronous 'You would write code here to parse Qualities() As Long, TimeStamps() As Date) 'You would write code here that was 'You would write code here to handle any errors that Communications, the Method returns the errors which would need to be processed in the same routine following the call to the method. RequestCompleted Private iRet As Integer) AsyncReadComplete Event of the OPCGroup Object Sub Private Sub MyOPCGroup_AsyncReadComplete MyRSData_RequestCompleted(ByVal (TransactionID As Long, NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, 'You would write code here to Qualities() As Long, TimeStamps() As Date, Errors() evalueate the values returned by the As Long) read. End Sub 'You would write code here to evaluate and display the values, qualities, timestamps and errors End Sub NOTE: Since Errors() are returned in the AsyncReadComplete Event, you no longer need to monitor a LinkError event separately. Any code in the RSData LinkError Event could be moved to these events when using When Asynchronous using Group communications. Synchronous Communications, the Method returns the errors which would need to be processed in the same routine following the call to the method.

本文来源:https://www.bwwdw.com/article/ae1r.html

Top