Git Product home page Git Product logo

opcda's Introduction

Go OPC DA Client

OPC_DA_WIN codecov Go Report Card Go Reference

English | 简体中文

This is an OPC DA client written in Go language, allowing you to communicate with OPC DA servers and retrieve data. OPC DA is a commonly used industrial automation communication protocol that enables data exchange between devices and control systems.

Features

  • Get all OPC DA servers
  • Connect to OPC DA server
  • Browse tags on OPC DA server
  • Synchronously read tag values
  • Asynchronously read tag values
  • Synchronously write tag values
  • Asynchronously write tag values
  • Subscribe to real-time data changes of tags

Prerequisites

Before using this client, make sure you meet the following prerequisites:

  • Windows operating system with amd64/i386 architecture
  • Go version 1.20 or higher

Go 1.20 is the last version that supports Microsoft Windows 7 / 8 / Server 2008 / Server 2012. To ensure compatibility, this client will continue to support Go 1.20.

Testing is done with both Go 1.20 and the latest version of Go, covering both 32-bit and 64-bit testing.

Installation

Use the following command to install this client:

go get github.com/huskar-t/opcda

Types

This client provides support for the following types:

OPC Type Go Type Description
VT_BOOL bool Boolean value
VT_I1 int8 8-bit signed integer
VT_I2 int16 16-bit signed integer
VT_I4 int32 32-bit signed integer
VT_I8 int64 64-bit signed integer
VT_UI1 uint8 8-bit unsigned integer
VT_UI2 uint16 16-bit unsigned integer
VT_UI4 uint32 32-bit unsigned integer
VT_UI8 uint64 64-bit unsigned integer
VT_R4 float32 32-bit floating point number
VT_R8 float64 64-bit floating point number
VT_BSTR string String
VT_DATE time.Time Date time
VT_ARRAY|VT_BOOL []bool Boolean array
VT_ARRAY|VT_I1 []int8 8-bit signed integer array
VT_ARRAY|VT_I2 []int16 16-bit signed integer array
VT_ARRAY|VT_I4 []int32 32-bit signed integer array
VT_ARRAY|VT_I8 []int64 64-bit signed integer array
VT_ARRAY|VT_UI1 []uint8 8-bit unsigned integer array
VT_ARRAY|VT_UI2 []uint16 16-bit unsigned integer array
VT_ARRAY|VT_UI4 []uint32 32-bit unsigned integer array
VT_ARRAY|VT_UI8 []uint64 64-bit unsigned integer array
VT_ARRAY|VT_R4 []float32 32-bit floating point number array
VT_ARRAY|VT_R8 []float64 64-bit floating point number array
VT_ARRAY|VT_BSTR []string String array
VT_ARRAY|VT_DATE []time.Time Date time array

Other types are not currently supported.

Usage Examples

API Documentation

All APIs can be found in the API documentation.

Why Choose This Client

  1. There is currently no mature OPC DA client in the Go language ecosystem, and this client was developed to fill this gap.
  2. This client is written purely in Go language and supports both 32-bit and 64-bit architectures.
  3. This client also provides relatively complete functionality, including reading, writing, and subscribing to real-time data changes of tags.
  1. konimarti/opc uses the OPC DA Automation Wrapper interface, which cannot be modified for bug fixes. For example, using the Graybox DA Automation Wrapper cannot compile for 64-bit operation (HIGHENTROPYVA is enabled by default, leading to out-of-bounds memory address conversion within the Wrapper).
  2. There are memory leaks when reading string types.
  3. Insufficient functionality, such as inability to subscribe to real-time data changes of tags.
  4. go-ole has not been updated #252, making it unable to obtain millisecond timestamps.

Frequently Questions

  1. Cross-platform support

    This client only supports the Windows operating system.

  2. Multi-platform compilation

    This client cannot be compiled on non-Windows platforms because it relies on Windows platform COM interfaces. If the program needs to support multiple platforms, interfaces can be encapsulated, and non-Windows platform interfaces can be set to empty implementations.

  3. Memory leaks

    This client uses COM interfaces, and memory release has been handled internally, with fatigue testing done for all supported types. However, if memory leak issues are found during use, you can submit an issue and provide reproduction steps.

opcda's People

Contributors

huskar-t avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

opcda's Issues

运行example/subscribe/main.go观察到内存快速增长现象

Golang

go1.22.4 windows/amd64

OS

Windows 11 X64 23H2
OS build 22631.3737

OPC DA Server

MatrikonOPCSimulation_v1.7.1.0

操作步骤

将example/subscribe/main.go下载后,执行go build --ldflags "-s -w" .编译为exe可执行程序文件并运行

现象

刚运行时,内存占用2M
image
运行10分钟后,内存占用6M
image

后续还修改了example/read/main.go使之持续运行,也观察到同样的内存使用增加情况,不知道是否与Item的Release方法为空有关?

opcda/opcitem.go

Lines 228 to 230 in 3c352b9

// Release Releases the OPCItem object
func (i *OPCItem) Release() {
}

Class not registered

Hello, I am currently testing your project and encountered a panic error. Could you please confirm if additional system configurations are required to run the test program? Thank you.

panic: Invalid class string

连接除了本机地址以外的ip地址就会报这个错误,我发现是因为clsid, err := windows.GUIDFromString(progID)返回的是{00000000-0000-0000-0000-000000000000},为什么会这样呢?是我的环境没装对吗还是其它什么原因?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.