Skip to content

Commit a5a6311

Browse files
author
ylliu
committed
tested
1 parent ec41da5 commit a5a6311

File tree

7 files changed

+55
-6
lines changed

7 files changed

+55
-6
lines changed

go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
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=

main_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

test/asciiclient_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"os"
1010
"testing"
1111

12-
"github.com/goburrow/modbus"
12+
"github.com/shift0ogg/modbus"
1313
)
1414

1515
const (

test/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ package test
77
import (
88
"testing"
99

10-
"github.com/goburrow/modbus"
10+
"github.com/shift0ogg/modbus"
1111
)
1212

1313
func ClientTestReadCoils(t *testing.T, client modbus.Client) {

test/rtuclient_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import (
99
"os"
1010
"testing"
1111

12-
"github.com/goburrow/modbus"
12+
"github.com/shift0ogg/modbus"
1313
)
1414

1515
const (
16-
rtuDevice = "/dev/pts/6"
16+
rtuDevice = "COM1"
1717
)
1818

1919
func TestRTUClient(t *testing.T) {
2020
// Diagslave does not support broadcast id.
2121
handler := modbus.NewRTUClientHandler(rtuDevice)
22-
handler.SlaveId = 17
22+
handler.SlaveId = 1
2323
ClientTestAll(t, modbus.NewClient(handler))
2424
}
2525

test/tcpclient_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"testing"
1111
"time"
1212

13-
"github.com/goburrow/modbus"
13+
"github.com/shift0ogg/modbus"
1414
)
1515

1616
const (

0 commit comments

Comments
 (0)