forked from konimarti/opc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connection.go
68 lines (60 loc) · 1.35 KB
/
connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package opc
import (
"time"
ole "github.com/go-ole/go-ole"
)
const (
//OPCDataSource defines constants for Sources when reading data from OPC:
//Default implementation is OPCCache.
//From the cache
OPCCache int32 = 1
//From the device
OPCDevice int32 = 2
//OPCQuality defines the quality of the OPC items:
//Bad
OPCQualityBad int16 = 0
//Good
OPCQualityGood int16 = 192
OPCQualityGoodButForced int16 = 216
//Maks
OPCQualityMask int16 = 192
//Uncertain
OPCQualityUncertain int16 = 64
//OPCServerState defines the state of the server:
//Disconnected
OPCDisconnected int32 = 6
//Failed
OPCFailed int32 = 2
//Noconfig
OPCNoconfig int32 = 3
//Running
OPCRunning int32 = 1
//Suspended
OPCSuspended int32 = 4
//Test
OPCTest int32 = 5
)
// Connection represents the interface for the connection to the OPC server.
type Connection interface {
Add(...string) error
Remove(string)
Read() map[string]Item
ReadItem(string) Item
ReadVariant(string, ole.VT) Item
Tags() []string
Write(string, interface{}) error
Close()
}
// Item stores the result of an OPC item from the OPC server.
type Item struct {
Value interface{}
Quality int16
Timestamp time.Time
}
// Good checks the quality of the Item
func (i *Item) Good() bool {
if i.Quality == OPCQualityGood || i.Quality == OPCQualityGoodButForced {
return true
}
return false
}