5
5
[ ![ Go Report Card] ( https://goreportcard.com/badge/github.com/aldas/go-modbus-client )] ( https://goreportcard.com/report/github.com/aldas/go-modbus-client )
6
6
[ ![ Codecov] ( https://codecov.io/gh/aldas/go-modbus-client/branch/main/graph/badge.svg )] ( https://codecov.io/gh/aldas/go-modbus-client )
7
7
8
- Modbus client (TCP/RTU) over TCP/Serial for Golang.
8
+ Modbus client (TCP/RTU) over TCP/UDP/ Serial for Golang.
9
9
10
10
* Modbus TCP/IP specification: http://www.modbus.org/specs.php
11
11
* Modbus TCP/IP and RTU simpler description: http://www.simplymodbus.ca/TCP.htm
@@ -34,7 +34,7 @@ go get github.com/aldas/go-modbus-client
34
34
## Goals
35
35
36
36
* Packets separate from Client implementation
37
- * Client (TCP/RTU) separated from Modbus packets
37
+ * Client (TCP/UDP + RTU) separated from Modbus packets
38
38
* Convenience methods to convert register data to/from different data types (with endianess/word order)
39
39
* Builders to group multiple fields into request batches
40
40
@@ -43,15 +43,17 @@ go get github.com/aldas/go-modbus-client
43
43
Higher level API allows you to compose register requests out of arbitrary number of fields and extract those
44
44
field values from response registers with convenience methods
45
45
46
+ Addresses without scheme (i.e. ` localhost:5020 ` ) are considered as TCP addresses. For UDP unicast use ` udp://localhost:5020 ` .
47
+
46
48
``` go
47
- b := modbus.NewRequestBuilder (" localhost:5020" , 1 )
49
+ b := modbus.NewRequestBuilder (" tcp:// localhost:5020" , 1 )
48
50
49
51
requests , _ := b.Add (b.Uint16 (18 ).UnitID (0 ).Name (" test_do" )).
50
52
Add (b.Int64 (18 ).Name (" alarm_do_1" ).UnitID (0 )).
51
53
ReadHoldingRegistersTCP () // split added fields into multiple requests with suitable quantity size
52
54
53
55
client := modbus.NewTCPClient ()
54
- if err := client.Connect (context.Background (), " localhost:5020" ); err != nil {
56
+ if err := client.Connect (context.Background (), " tcp:// localhost:5020" ); err != nil {
55
57
return err
56
58
}
57
59
for _ , req := range requests {
@@ -76,6 +78,8 @@ for _, req := range requests {
76
78
77
79
RTU examples to interact with serial port can be found from [ serial.md] ( serial.md )
78
80
81
+ Addresses without scheme (i.e. ` localhost:5020 ` ) are considered as TCP addresses. For UDP unicast use ` udp://localhost:5020 ` .
82
+
79
83
### Low level packets
80
84
81
85
``` go
0 commit comments