File tree 7 files changed +55
-6
lines changed 7 files changed +55
-6
lines changed Original file line number Diff line number Diff line change
1
+ module modbus
2
+
3
+ go 1.14
4
+
5
+ require (
6
+ github.com/goburrow/serial v0.1.0
7
+ github.com/shift0ogg/modbus v0.1.2
8
+ )
Original file line number Diff line number Diff line change
1
+ github.com/goburrow/serial v0.1.0 h1:v2T1SQa/dlUqQiYIT8+Cu7YolfqAi3K96UmhwYyuSrA =
2
+ github.com/goburrow/serial v0.1.0 /go.mod h1:sAiqG0nRVswsm1C97xsttiYCzSLBmUZ/VSlVLZJ8haA =
3
+ github.com/shift0ogg/modbus v0.1.2 h1:tiXATE4w6iCElIY116Pvt/YptAqM25CriADYWZU5YEA =
4
+ github.com/shift0ogg/modbus v0.1.2 /go.mod h1:vO1yzL5YEOZpm5aZmADVG4GvkimA4FtXExgvNRemy7M =
Original file line number Diff line number Diff line change
1
+ package modbus
2
+
3
+ import (
4
+ "testing"
5
+ "time"
6
+
7
+ "github.com/shift0ogg/modbus"
8
+ )
9
+
10
+ func Test1 (t * testing.T ) {
11
+ var c modbus.Client
12
+ if true {
13
+ handler := modbus .NewTCPClientHandler ("127.0.0.1:502" )
14
+ handler .Timeout = 10 * time .Second
15
+ handler .SlaveId = 0x1
16
+ c = modbus .NewClient (handler )
17
+ } else {
18
+ //
19
+ handler := modbus .NewRTUClientHandler ("COM1" )
20
+ handler .BaudRate = 9600
21
+ handler .DataBits = 8
22
+ handler .Parity = "N"
23
+ handler .StopBits = 1
24
+ handler .SlaveId = 0x1
25
+ handler .Timeout = 1000 * time .Millisecond
26
+ c = modbus .NewClient (handler )
27
+ }
28
+
29
+ bytes , err := c .ReadHoldingRegisters (0 , 10 )
30
+ if err != nil {
31
+ t .Error (bytes )
32
+ }
33
+ t .Logf ("%v" , bytes )
34
+ t .Log (bytes )
35
+ c .Close ()
36
+
37
+ }
Original file line number Diff line number Diff line change 9
9
"os"
10
10
"testing"
11
11
12
- "github.com/goburrow /modbus"
12
+ "github.com/shift0ogg /modbus"
13
13
)
14
14
15
15
const (
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ package test
7
7
import (
8
8
"testing"
9
9
10
- "github.com/goburrow /modbus"
10
+ "github.com/shift0ogg /modbus"
11
11
)
12
12
13
13
func ClientTestReadCoils (t * testing.T , client modbus.Client ) {
Original file line number Diff line number Diff line change @@ -9,17 +9,17 @@ import (
9
9
"os"
10
10
"testing"
11
11
12
- "github.com/goburrow /modbus"
12
+ "github.com/shift0ogg /modbus"
13
13
)
14
14
15
15
const (
16
- rtuDevice = "/dev/pts/6 "
16
+ rtuDevice = "COM1 "
17
17
)
18
18
19
19
func TestRTUClient (t * testing.T ) {
20
20
// Diagslave does not support broadcast id.
21
21
handler := modbus .NewRTUClientHandler (rtuDevice )
22
- handler .SlaveId = 17
22
+ handler .SlaveId = 1
23
23
ClientTestAll (t , modbus .NewClient (handler ))
24
24
}
25
25
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import (
10
10
"testing"
11
11
"time"
12
12
13
- "github.com/goburrow /modbus"
13
+ "github.com/shift0ogg /modbus"
14
14
)
15
15
16
16
const (
You can’t perform that action at this time.
0 commit comments