Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
OPCClientToolKit
src
test
CMakeLists.txt
PluginOpc.txt
README.md
README_CN.md
libPluginOPC.dll

README.md

OPC Plugin

1. Build

  1. Install MinGW. It is supposed that your version of MinGW contains the COM library.
  2. Move libDolphinDB.dll to the build direcotry.
  3. Move CMakeLists.txt to the DolphinDBPlugin directory and build with clion.

2. API

OPC Plugin supports OPC 2.0 protocol.

2.1 Get OPC Server

Syntax

opc::getServerList(host)

Arguments

  • 'host' is a string indicating the IP address.

Details

Get the OPC server. It returns a table of two columns. The first column is progID indicating the identification of server and the second column is CLSID.

Example

opc::getOpcServerList("desk9")

2.2 Connect to OPC Server

Syntax

opc::connect(host, serverName,[reqUpdateRate_ms=100])

Arguments

  • 'host' is a string indicating the IP address.

  • 'serverName' is a string indicating the name of OPC server.

  • 'reqUpdateRate_ms' is an integer. It is used to requested update rate.It is optional,default is 100 ms.

Details

Connect to OPC Server. It returns an connection object which can be explicitly called to close the close function, or it can be automatically released when the reference count is 0. .

Example

connection=opc::connect(`127.0.0.1,`Matrikon.OPC.Simulation.1,100)

2.3 Read a Tag Synchronously

Syntax

opc::readTag(connection, tagName,[table])

Arguments

  • 'connection' is an object generated by function opc::connect.

  • 'tagName' is a string indicating the name of tag.

  • 'table' is a table or an array of tables ,the number of tables must be the same as the number of tags when it is an array, It is used to store the result of the reading. If the table is one, all the values ​​of the tags are inserted into this table. If there are multiple tables, the values ​​read by each tag are inserted into these tables. If you do not enter a table, the return value is a table, and the record of the table is the tag value read.

Details

Read the values of the tags synchronously.An OPC connection needs to be established before.

Example

t = table(200:0,`time`value`quality, [TIMESTAMP, DOUBLE, INT])
opc::readTag(conn, "testwrite.test9",t)
tm = table(200:0,`time`tag1`quality1`tag2`quality2, [TIMESTAMP,STRING, INT,INT,INT])
opc::readTag(conn, ["testwrite.test1","testwrite.test4"],tm) 
t1 = table(200:0,`time`value`quality, [TIMESTAMP, STRING, INT])
t2 = table(200:0,`time`value`quality, [TIMESTAMP, INT, INT])
t3 = table(200:0,`time`value`quality, [TIMESTAMP, DOUBLE, INT])
opc::readTag(conn, ["testwrite.test1","testwrite.test4", "testwrite.test9"],[t1,t2,t3]) 

Details

Read the values of the tags synchronously. It returns a table.

Example

t = table(200:0,`time`value`quality, [TIMESTAMP, DOUBLE, INT])
opc::readTag(conn, "testwrite.test9",t)
tm = table(200:0,`time`tag1`quality1`tag2`quality2, [TIMESTAMP,STRING, INT,INT,INT])
opc::readTag(conn, ["testwrite.test1","testwrite.test4"],tm) 
t1 = table(200:0,`time`value`quality, [TIMESTAMP, STRING, INT])
t2 = table(200:0,`time`value`quality, [TIMESTAMP, INT, INT])
t3 = table(200:0,`time`value`quality, [TIMESTAMP, DOUBLE, INT])
opc::readTag(conn, ["testwrite.test1","testwrite.test4", "testwrite.test9"],[t1,t2,t3]) 

2.4 Write a Tag Synchronously

Syntax

opc::writeTag(connection, tagName, value)

Arguments

  • 'connection' is an object generated by function opc::connect.

  • 'tagName' is a string or a string array indicating the name of tag.

  • 'value' is the values of the tags.

Details

Write the values to the tags. If the datatype is incompatible, it will throw an exception.

Example

opc::writeTag(conn,"testwrite.test1",[1.112,0.123,0.1234])
opc::writeTag(conn,["testwrite.test5","testwrite.test6"],[33,11])

2.5 Subscribe

Syntax

opc::subscribe(connection, tagName, handler)

Arguments

  • 'connection' is an object generated by function opc::connect.

  • 'tagName' is a string or string array indicating the name of tag.

  • 'handler' is a function or a table or a table array. It is used to process the subscribed data.

Details

subscribe the values of the tags from the OPC server.

Example

//loadPlugin("PluginOPC.txt")
t1 = table(200:0,`time`value`quality, [TIMESTAMP, STRING, INT])
conn1=opc::connect(`desk9,`Matrikon.OPC.Simulation.1,100)
opc::subscribe(conn1,".testString",  t1)
t2 = table(200:0,`time`value`quality, [TIMESTAMP, INT, INT])
t3 = table(200:0,`time`value`quality, [TIMESTAMP, DOUBLE, INT])
conn20 = opc::connect(`127.0.0.1,`Matrikon.OPC.Simulation.1,10)
opc::subscribe(conn20,[".testINT2",".testReal8"], [t2, t3])
def callback1(mutable t1, d) {
	t1.append!(d)
}
t4 = table(200:0,`time`value`quality, [TIMESTAMP, BOOL, INT])
conn10 = opc::connect(`127.0.0.1,`Matrikon.OPC.Simulation.1,10)
opc::subscribe(conn10,".testBool",   callback1{t4})

2.6 Unsubscribe

Syntax

opc::unsubscribe(connection)

Arguments

  • 'connection' is an object generated by function OPC::connect.

Details

Unsubscribe from the OPC server.

Example

opc::unsubcribe(connection)

2.7 Close the connection

Syntax

opc::close(connection)

Arguments

  • 'connection' is an object generated by function opc::connect.

Details

Close the connection to the opc server.

Example

opc::close(connection)
You can’t perform that action at this time.