Categorygithub.com/mrzwzw/OPC-DA
modulepackage
1.0.0
Repository: https://github.com/mrzwzw/opc-da.git
Documentation: pkg.go.dev

# README

Go 中的 OPC DA

DA从 OPC 服务器在 Go 中获取和写入流程和自动化数据,用于监控和数据分析目的(OPC DA 协议)。

编译运行前准备

1、下载opc核心包 OPC Core Components Redistributable (x86) 3.00.108.msi并安装

2、在C:\Windows\SysWOW64安装OPCDAAuto.dll,以管理员身份执行Regsvr32 OPCDAAuto.dll

3、运行时环境搭建,GOARCH=386

安装

go get github.com/mrzwzw/opc

代码示例

package main

import (
	"fmt"
	"github.com/konimarti/opc"
)

func main() {
	client, _ := opc.NewConnection(
		"opcserversim.Instance.1", // ProgId
		[]string{"localhost"}, //  OPC servers nodes
		[]string{"numeric.sin.int64", "numeric.saw.float"}, // slice of OPC tags
	)
	defer client.Close()

	// read single tag: value, quality, timestamp
	fmt.Println(client.ReadItem("numeric.sin.int64"))

	// read all added tags
	fmt.Println(client.Read())
}

OPC DA数据类型

值(十进制)类型描述
0VT_EMPTY默认/空(无)
2VT_I22字节有符号整数
3VT_I44字节有符号整数
4VT_R44字节实数
5VT_R88字节实数
6VT_Ccurrency
7VT_DATE日期
8VT_BSTR文本文本
10VT_ERROR错误代码
11VT_BOOL布尔值(TRUE=-1,FALSE=0)
17VT_I11个字节有符号字符
18VT_UI11个字节无符号字符
19VT_UI22字节无符号整数
20VT_UI44字节无符号整数
+8192VT_ARRAY值数组(即8200=文本值数组)

# Packages

No description provided by the author

# Functions

CollectTags traverses tree and collects all tags in string slice.
Debug will set the logger to print to stderr.
ExtractBranchByName return substree with name.
NewDataModel returns an OPC Data struct.
PrettyPrint prints tree in a nice format.
SetLogWriter sets a user-defined writer for logger.
StartMonitoring exposes /metrics to Prometheus.

# Constants

OPCDataSource defines constants for Sources when reading data from OPC: Default implementation is OPCCache.
From the device.
OPCServerState defines the state of the server: Disconnected.
Failed.
Noconfig.
OPCQuality defines the quality of the OPC items: Bad.
Good.
No description provided by the author
Maks.
Uncertain.
Running.
Suspended.
Test.

# Structs

Item stores the result of an OPC item from the OPC server.
Leaf contains the OPC tag and forms part of the Tree struct for the OPC browser.
Tree creates an OPC browser representation.

# Interfaces

Collector interface.
Connection represents the interface for the connection to the OPC server.