《组态王与AB PLC通过OPC的连接-精品文档资料.doc》由会员分享,可在线阅读,更多相关《组态王与AB PLC通过OPC的连接-精品文档资料.doc(9页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、组态王与AB 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四个版本。且
2、均支持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选择对应的通讯卡,并进行端口配置(可参照附带的安装手册),配置成功后将显示所配置的设备的运行状态
3、。使用RSWho命令查找连接的PLC设备(参见图-3)。参见图-3RSWho命令成功的执行后,将在设备列表中列出与本机连接的所有硬设备。使用Topic Configoration来进行OPC服务的配置(参见图-4)。图-4在Date Source配置框中配置Topic,选择一个物理设备(PLC),按New按钮即可建立一个Topic,单击Done即可(参见图-5)。图-53、 在组态王中建立y与OPC设备的连接。添加OPC设备。在组态王的工程器中选择设备OPC服务器新建,则弹出如下的窗口(参见图-6)。在OPC服务器列表中选择RSLinx OPC Server选择确定即可。参见图-6在数据字典里
4、加入IO点(参见图-7)在组态王的工程器中选择数据库数据字典新建。确定变量名、变量类型等变量属性,在连接设备中选择RSLinx OPC Server ;手工键入寄存器地址,地址的格式为:”Topic名变量别名”或”Topic名:变量寄存器地址”。单击确认即可。图-74、 附加的文档,A-B提供的说明文件。Public GroupsRSLinx does not support public groups. Public groups are an optional part of the OPC specifications. However, behind the scenes, if tw
5、o 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 c
6、urrent 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 specific
7、ation 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 applicati
8、on 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
9、.60.01 RSJunctionBox 1.60.01 RSLinx SDK 2.30.02 (Build 79) VisualBASIC 6.0 with Service Pack 5PLEASE 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
10、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 eve
11、nts 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 P
12、roperties are NOT SUPPORTED with the RSLinx OPC Automation Interface. Display Related PropertiesAutoColumnsCaptionTransparentGridOnScrollTopRowBackColorCaptionXGridWidthTabIndexBackStyleCaptionYHeightTabStopBevelHeightCausesValidationHelpContextIDTagBevelHighlightDecimalPlacesIndexToolTipTextBevelSh
13、adowDisplayCaptionLeftTopBevelStyleDisplayCaptionVerticalLeftBorderTopBordersBevelWidthDisplayPictureLinkTipTrailingZerosBorderColorDisplayValueLinkTipBackColorValueBackColorBorderInnerDragIconLinkTipForeColorValueColorBorderInnerColorDragModeLinkTipTextValuePadDownloadBorderStyleDrawDisabledShadowP
14、ictureValueShadowBorderWidthEnabledPicturePathValueShadowColorBottomBorderFlashEnabledPictureStretchValueTransparentCaptionFlashOnRightBorderValueXCaptionBackColorFlashSpeedScreenPriorityValueYCaptionColorFlashTimeScrollColumnHeightVisibleCaptionShadowFontScrollColumnWidthWhatsThisHelpIDCaptionShado
15、wColorGridColorScrollFirstColumnWidthDatabase Related PropertiesDataBindingsDataFormatDataSourceDataFieldDataMemberDataUpdateOther Unsupported PropertiesEndValueExpressionForReadWriteValueLinkErrorDisplayStartValueExpressionForWritePokeTypeSymbolUseStartEndValueThe following RSData Events are NOT SU
16、PPORTED with the RSLinx OPC Automation Interface. Display Related EventsClickGotFocusLostFocusScrollPosChangedDblClickKeyDownMouseDownValidateDragDropKeyPressMouseMoveDragOverKeyUpMouseUpOther Unsupported EventsLinkErrorLinkItemSupportedLinkOutOfMemoryLinkItemNotSupportedLinkNotifyLinkServerDisconne
17、ctedLinkUnableToConnectToServerThe following RSData Methods are NOT SUPPORTED with the RSLinx OPC Automation Interface. Display Related MethodsAboutBoxMoveShowValuePadDragSetFocusShowWhatsThisThe following tables list the RSData Properties, Events and Methods that have an equivalent in the RSLinx OP
18、C Automation Interface. In the following table, the information in italics is a code sample of the Property, Event or Method.RSDataRSLinx OPC Automation Interface EquivalentPropertiesLinkServerMyRSData.LinkServer = RSLinxOPCServer.ConnectOpcServer.Connect RSLinx OPC ServerLinkTopicMyRSData.LinkTopic
19、 = MyTopicThese two properties are combined in the AddItems Method of the OPCGroup object.OpcGroup.OPCItems.AddItem PLCS:23, 1LinkItemMyRSData.LinkItem = S:23LinkModeMyRSData.LinkMode = 1, 2, or 3These three properties are combined in the IsSubscribed Property of the OPCGroup object.OPCGroup.IsSubsc
20、ribedOpcGroup.IsSubscribed = TrueThe IsSubscribed property must be set to true to enable callbacks and thus events for the OPCGroup object.The OPCGroup Object must be declared WithEvents as well.IsSubscribed = True is equivalent to LinkMode = 1, CommunicationMode = Asynchronous and AllowChangeEvent
21、= 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.CommunicationModeM
22、yRSData.CommunicationMode = Synchronous, AsynchronousAllowChangeEventMyRSdata.AllowChangeEvent = True, FalseRequestLengthMyRSData.RequestLength = 6There is no equivalent of these properties in the RSLinx OPC Automation Interface but some parameters of the OPCGroups SyncRead and AsyncRead Methods can
23、 be used to replicate this behavior.Specifically:RequestLength = lNumItems parameterRequestStartIndex 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. T
24、he code snippets below demonstrate this.RequestStartIndexMyRSData.RequestStartIndex = 0UseInRequestMyRSData.UseInRequest = True, FalsePokeLengthMyRSData.PokeLength = 6There is no equivalent of these properties in the RSLinx OPC Automation Interface but some parameters of the OPCGroups SyncWrite and
25、AsyncWrite Methods can be used to replicate this behavior.Specifically:PokeLength = lNumItems parameterPokeStartIndex 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 withi
26、n the group. The code snippets below demonstrate this.PokeStartIndexMyRSData.PokeStartIndex = 0UseInPokeMyRSData.UseInPoke = True, FalseMethodsLinkPokeMyRSData.LinkPokeThe Write method of the OPCItem ObjectMyOPCItem.Write valueDoPokeMyRSData(0).PokeStartIndex = 0MyRSData(0).PokeLength = 6For i% = 0
27、To 5MyRSData(i%).UseInPoke = TrueNext i%MyRSData(0).DoPokeThe SyncWrite Method of the OPCGroup Object(Use this method if you have the RSData.CommunicationMode property set to Synchronous)lNumitems = MyOPCGroup.OPCItems.CountReDim arHandles(1 To lNumitems)ReDim arValues(1 To lNumitems)For i = 1 To lN
28、umitemsarHandles(i) = MyOPCGroup.OPCItems(i).ServerHandlearValues(i) = txtData(MyOPCGroup.OPCItems(i).ClientHandle).TextNextMyOPCGroup.SyncWrite lNumitems, arHandles, arValues, arErrorsThe AsyncWriteMethod of the OPCGroup Object(Use this method if you have the RSData.CommunicationMode property set t
29、o Asynchronous)lNumitems = MyOPCGroup.OPCItems.CountReDim arHandles(1 To lNumitems)ReDim arData(1 To lNumitems)For i = 1 To lNumitemsarHandles(i) = MyOPCGroup.OPCItems(i).ServerHandlearData(i) = txtData(MyOPCGroup.OPCItems(i).ClientHandle).TextNext iMyOPCGroup.AsyncWrite lNumitems, arHandles, arData
30、, arErrors, lTransID, lCancelIDLinkRequestMyRSData.LinkRequestThe Read method of the OPCItem ObjectMyOPCItem.Read OPC_DS_CACHE, vValue, vQuality, vTimeStampDoRequestMyRSData(0).RequestStartIndex = 0MyRSData(0).RequestLength = 6For i% = 0 To 5MyRSData(i%).UseInRequest = TrueNext i%MyRSData(0).DoReque
31、stThe SyncRead method of the OPCGroup Object(Use this method if you have the RSData.CommunicationMode property set to Synchronous)lNumitems = MyOPCGroup.OPCItems.CountReDim arHandles(1 To lNumitems)For i = 1 To lNumitemsarHandles(i) = MyOPCGroup.OPCItems(i).ServerHandleNext i/* Read Group data from
32、CacheMyOPCGroup.SyncRead OPC_DS_CACHE, lNumitems, arHandles, arValues,arErrors, arQualities, arTimeStampsThe AsyncRead Method of the OPCGroup Object(Use this method if you have the RSData.CommunicationMode property set to Asynchronous)lNumitems = MyOPCGroup.OPCItems.CountReDim arHandles(1 To lNumite
33、ms)For i = 1 To lNumitemspass in server handlesarHandles(i) = MyOPCGroup.OPCItems(i).ServerHandleNext iMyOPCGroup.AsyncRead lNumitems, arHandles, arErrors, lTransID, lCancelIDEventsChangePrivate Sub MyRSData_Change(ByVal sValue As String, ByVal iIndex As Integer)You would write code here to parse th
34、e valuesEnd SubDataChange Event of the OPCGroup ObjectPrivate Sub MyOPCGroup_DataChange(ByVal TransactionID As Long, ByVal NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long, TimeStamps() As Date)You would write code here to evaluate and display the values, quali
35、ties, and timestamps of the dataEnd SubPokeCompletedPrivate Sub MyRSData_PokeCompleted(ByVal iRet As Integer)You would write code here that was dependant on the poke completing.End SubAsyncWriteComplete Event of the OPCGroup ObjectPrivate Sub MyOPCGroup_AsyncWriteComplete (TransactionID As Long, Num
36、Items As Long, ClientHandles() As Long, Errors() As Long)You would write code here to handle any errors that occured during the write processEnd SubNOTE: Since Errors() are returned in the AsyncWriteComplete Event, you no longer need to monitor a LinkError event separately. Any code in the RSData Li
37、nkError Event could be moved to these events when using Asynchronous Group communications. When using Synchronous Communications, the Method returns the errors which would need to be processed in the same routine following the call to the method.RequestCompletedPrivate Sub MyRSData_RequestCompleted(
38、ByVal iRet As Integer)You would write code here to evalueate the values returned by the read.End SubAsyncReadComplete Event of the OPCGroup ObjectPrivate Sub MyOPCGroup_AsyncReadComplete (TransactionID As Long, NumItems As Long, ClientHandles() As Long, ItemValues() As Variant, Qualities() As Long,
39、TimeStamps() As Date, Errors() As Long)You would write code here to evaluate and display the values, qualities, timestamps and errorsEnd SubNOTE: 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 Asynchronous Group communications. When using Synchronous Communications, the Method returns the errors which would need to be processed in the same routine following the call to the method.