forked from wendy512/iec61850
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test.go
More file actions
59 lines (50 loc) · 1.38 KB
/
Copy pathclient_test.go
File metadata and controls
59 lines (50 loc) · 1.38 KB
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
package test
import (
"github.com/wendy512/iec61850"
"testing"
)
const (
AnIn1ObjectRef = "simpleIOGenericIO/GGIO1.AnIn1.mag.f"
Ind1ObjectRef = "simpleIOGenericIO/GGIO1.Ind1.stVal"
)
func TestRead(t *testing.T) {
client := createClient(t)
doRead(t, client, AnIn1ObjectRef, iec61850.MX)
doRead(t, client, Ind1ObjectRef, iec61850.ST)
}
func TestReadFloat(t *testing.T) {
client := createClient(t)
objectRef := AnIn1ObjectRef
value, err := client.ReadFloat(objectRef, iec61850.MX)
if err != nil {
t.Errorf("read %s object error %v\n", objectRef, err)
t.FailNow()
}
t.Logf("read %s float value -> %v", objectRef, value)
}
func TestReadBool(t *testing.T) {
client := createClient(t)
objectRef := Ind1ObjectRef
value, err := client.ReadBool(objectRef, iec61850.ST)
if err != nil {
t.Errorf("read %s object error %v\n", objectRef, err)
t.FailNow()
}
t.Logf("read %s bool value -> %v", objectRef, value)
}
func createClient(t *testing.T) *iec61850.Client {
client, err := iec61850.NewClient(iec61850.NewSettings())
if err != nil {
t.Errorf("create client error %v\n", err)
t.FailNow()
}
return client
}
func doRead(t *testing.T, client *iec61850.Client, objectRef string, fc iec61850.FC) {
value, err := client.Read(objectRef, fc)
if err != nil {
t.Errorf("read %s object error %v\n", objectRef, err)
t.FailNow()
}
t.Logf("read %s value -> %v", objectRef, value)
}