您好,欢迎光临本网站![请登录][注册会员]  
文件名称: MXOPCServerVer5.00-Using an OPC Server From VB Manual.pdf
  所属分类: 制造
  开发工具:
  文件大小: 139kb
  下载次数: 0
  上传时间: 2019-07-08
  提 供 者: haj***
 详细说明:本文介绍如何通过VB代码实现三菱MX OPC的操作。MX OPC是为三菱官方OPC软件,支持三菱全系列PLC产品。A2 Prerequisites You will need: Visual Basic- the examples in this document were developed with Visual Basic 6 Service Pack 5, but could also be used with other applications that will support VBa (Visual Basic for Applications) OPC automation support files (OPCdaAuto. dll and OP Cenum. exe)-these must be correctly installed in e.g. the directory, and must be registered with REGSVR32 An installed OPC server, e.g. Mitsubishi. MXOPC Mitsubishi electric A-3 A3 Terminology Term Description OPC OLE for Process Control-an open standard for connecting to process control equipment such as PLCs and scada databases. oPc is intended to solve the problem of every SCADa package needing a difterent driver for every PLC to which it connects With OPC, only one driver needs to be developed and each scada package connects to the oPc driver using the same interface Automation interface A simplified OPC interface designed for integration programs IiKe VIs asic a ipting languages like VBA (Visual Basic for Applications OPCServer The top level interface to OPC. This provides a way to find out which oPc servers are installed on a pc. and OPCBrowser This is the object used to list the items defined in the OPC S OPC Group a group of items to be read from the OPc server OPC Groups Used to add groups to an oPc server and iterate through the available groups. OPCItem A single item of data in the OPC server, usually one OPCItem Used to add items to an oPc group and iterate hrough the available items Server handle a unique number used by the oPc server to identify a single item Client handle A number used by the client to identify an OPC Quality This gives a measure of confidence in the data read from the server. In normal usage, most applications quality value OPC QUALITY GOOD(&HCO)and treat any other value as an indication that the data is invalid Mitsubishi electric A-4 A 4 Adding the OPC Libraries to Your Project Before you can use the OPC automation libraries, they must be included in your project. To do this, select References'from the ' menu File Edit Mew Projed Format Debug Run Query Djagram ‖E·,1AEom Add MDI Form we add Module Add Class Module E Add user Control 向 Add Property Page add user Document Add Data Environment Add Mcrosoft UserConnedion Add Fi Remove modoPCoonst bas RtlerelILt Components,. ctr+T prjOPCperfarm Properties. In the list that appears, check 'OPC DA Automation Wrapper'and'OPCenum' to include the OPC automation libraries in your project, then click OK. References-OPCsamp le vbp Available References K A Visual Basic For applicatians Cancel visual Basic runtime objects and procedures Visual Basic objects and procedures OLE Automation Browse OPC DA Automatin wrapper 2. 02 IA5 Helper coM Component 1. 0 Type ubrary IAS RADUS Probocd 1. Type Librar Prionity Acrobat Access 3.0 Type Library Help AgrolEHeber 1.0 Type Library Acive DS Type Lbrary Active Setup Control Library Ativex Dll to ner fom Miration nF ms rennsitory v-V OpcEnum 11 Type Library ocation: C: \WINDOWS\system 32\OpcEnum, exe Language: standard Mitsubishi electric A-5 A.5 OPC constants Some of the more useful opc constants are shown below in a format that can be cut and pasted into a new module in a visual Basic project Data source constants-get cached value, or read direct from device Public const opc ds cache Public const oPc ds device= 2 Quality and status Public Const OPC QUALITY GOoD=&HCO Public Const OPC QUALITY MASK=&HCO Public const oPc status mask =&HFC Public const oPc lIMit mask=&H Public Const OPC QUALITY BAD=&HO Public Const OPC QUALITY UNCERTAIN =&H40 Public Const OPC QUALITY CONFIG ERRoR =&H4 Public Const OPC QUALITY NOT CONNECTED=&H8 Public Const OPC QUALITY DEVICE FAILURE =&HC Public Const OPC QUALITY SEnSOR FAILURE =&H10 Public Const OPC QUALITY LAST KNOWn =&H14 Public Const OPC QUALITY COMM FAILURE =&H18 Public Const OPC QUALITY OUT OF SERVICE=&H1C Public Const OPC QUALITY LAST USAblE=&H44 Public Const OPC QUALITY SENSOR CAL =&H50 Public Const OPC QUALITY EGU EXCEEDED =&H54 Public Const oPC QUALITY SUB Normal =&H58 Public Const OPC QUALITY LOCAL OVERRidE=&HD8 Limit constants Public Enum toPclimits OPC LIMIT OK =0 OPC LIMIT LOW =1 OPC LIMIT HIGH= 2 OPC LIMIT CONST =3 End enum 'toPClimits Server states Public enum sErver State OPC STATE RUNNING =1 OPC STATE FAILED 2 OPC STATE NOCONFIG =3 OPC STATE SUSPENDED 4 OPC STATE TEST=5 OPC STATE DISCONNECTED =6 End enum sErver State Mitsubishi electric A-6 A 6 Listing installed oPc servers To find out which OPC servers are installed, create a new OPCServer object and call the GetoPCServers( function. This returns an array of strings giving the names of installed servers For Visual Basic purposes, the variable used should be a Variant The name of the Mitsubishi OPC server is Mitsubishi. MXOPC 5 but when connecting to a server the shorter name 'Mitsubishi. MXoPC' can also be used. this will connect to the latest available version of the MX oPc server Dim obsErver as OPCServer OPC server object Dim VAllServers as Variant Temporary to build list of servers D -p a Dim strs As String String to build list of servers Create an OPC server object Set obServer =New OPCServer Use the server object to populate the list of available OPC servers VAllServers obj Server. GetOPCServers Display the name of each server For intL-p= LBound(VAlIServers)To UBound(VAll Servers) Add name to list strS= strs& VAllServers(intL-p)& vbCrLf Next Server Displa MsgBox strS,,"List of servers Clean up Not Mitsubishi electric A-7 A 7 Connecting to an opc server To connect to an OPC server, create an OPCServer object and call the 'Connect method, passing it the name of the server. This name can be found from the GetoPCServerso function Dim obj server as OPCServer OPC server object Create server object if necessary If obsErver Is Nothing Then Set obsErver=New OPCServer If already connected, disconnect first If obsErver. ServerState= OPC STATE RUNNING Then obsErver. Disconnect Connect to the server observer. Connect Mitsubishi. MXOPC Check server is running Debug Assert observer Server State= OPC STATE RUNNING Show server version and details MsgBox "Server: observer. Vendorlnfo (& Format(obsErver. Major Version)&. " Format(obj Server. Minor'Version)&") 'Connected to server Mitsubishi electric A-8 A 8 Browsing the OPC server items The example below will show how to browse the list of items defined on the server hierarchically writing the results into a treeview control called tvw Browse. a subroutine is used to browse the structure recursively, and for leaf ( tag) items the tags item id (which is needed to read its value from the server)will be stored in the leaf node's. Key' property Browsing for tags is not always necessary. If you already know which tags the application needs to read, you can use their IDs directly with the read and write functions(see sections Reading data values from the server and Writing data values to the server). For the MX OPC server, hese item IDs are built from the device name followed by any group names and finally the tag name, with each part separated by period characters. Typical examples would be Dev01. Tag001'(without groups)orDev02 Group001.Tag001'(with one group) The IDs for dynamic tags are built differently, using a backwards slash(\)as the separator, and with the tag name in a format which also gives the address and type for example Devo1D50 l' for a dynamic tag reading address D50 as an integer, or Dev01\G1 D100. S10 for a 10 character string under a group called 'G1 Constants for treeview nodes-will be put in the Tag propel Const TREE ROOT As String=0 Const TREE BRANCH As String=" Const TREE LEAF As String=2 Constant for root node's key Const strRootKey As String="ROOT Name Description: Fill treeview with items and branches from OPC hierarchy. Will call itself recursively to get the details Inputs: tvwT -Treeview to fill objBrw -OPc browser object at current position (initially root) n Parent node to fill under (initially a new, root, node) NA Private Sub FillBranches(By Ref tvwT As Treeview ByRef obj Brw As opcBrowser By Ref nodAr As Node Declare variables Dim intLp As Integer Loop counter Dim nod As node Used for node creation Find branches at this level objBrw Show Branches For intL= 1 To objBrw Cc Skip register hints branch, no readable tags If objBrw Item(ngLp)<>"Register Hints"Then Add branch node(no key, not unique for bra Set nodN =tvwT Nodes Add (nodAr, tvw Child nod. Tag= TREE BRANCH End lf Not register hints branch Next intl Branch Mitsubishi electric A-9 Find child at this level Brw. Sho For intLp= 1 To objBrw Count Add leaf node Set nodn= tvwT Nodes Add(nodAr, tvwChild objBrw. GetltemI D(objBrw Item(intL-p)), objBrw. Item(intLp) nodN. Tag= TREE LEAF xt intL Lea Now go back and recursively fill the branches we just created because each call to show branches overwrites the data Only interested in branch If nodN.Tag= TREE BRANCH Then Move down into this branch ob i Brw Move down non. Text Fill in details recursively FillBranches tvwT, objBrw, nooN Move back up objBrw MoveUp End if Branch node Next node Set non non Next Clean up object references End Sub FillBrancheso Mitsubishi electric A-10
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 输入关键字,在本站1000多万海量源码库中尽情搜索: