OPC Client-EXCEL/VBA sample
It accesses the OPC server via the automation wrapper of OPC.
Declare OPC Objects (OPC Server / OPC Group / OPC Item)
For hooking events of OPC Server, add to "WithEvents" in dimension statement or event handler named "OBJECTNAME_EVENTNAME".
Connect and Browse
It is able to get device name registered in OPC Server by using OPC Server object. You can make the Group under device and OPC Server object is enabled to access this lower layer.
Create OPC Group Object and Add Tags
It is necessary to create the group object in the OPC server to acquire real data from the outside.The data update cycle can be set to the group object, and usually register the device accessed by the same synchronization to the group. Because the threads of each group are created in the OPC server, please note CPU load increase by subdivision too much.
Advise and Callback
Implements event handler of OPC Group object for advice mode. The OPC Server read data for each cycle and if changing the value, callback to client application. The quality flag is normally '0xC0', when occurred error, it will be turn to other value.
Sync Read/Write and ASync Read/Write
The OPC has two ways of data access, Synchronize and Asynchronous. In Synchronize, the client application must be wait for completing server work. But the client application can confirm server transaction is normally completed because the OPC Server returns the result on completing the communication work. This is a normally style of procedure.
In Asynchronous mode, the OPC Server turns the handle to client as soon as receiving the request and proceed the transaction on background. After completing this work, calls handler of client application. Asynchronous mode cut down wait time for communication and be able to run client application.
Caution: Asynchronous access is enabled under advice mode.