Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device identification #75

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Bit access:
* Read/Write Multiple Registers
* Mask Write Register
* Read FIFO Queue

* Read Device Identification
Supported formats
-----------------
* TCP
Expand Down Expand Up @@ -73,6 +73,25 @@ client := modbus.NewClient(handler)
results, err := client.ReadDiscreteInputs(15, 2)
```

```go
// Read device identification
results, err := client.ReadDeviceIdentification(1, 0)

if err == nil {
objNumber := results[0]

currStart := byte(1)
for i := byte(0); i < objNumber; i++ {
currID := results[currStart]
currLen := results[currStart+byte(1)]
currObj := results[currStart+byte(2) : currStart+byte(2)+currLen]
currStart += byte(2) + currLen
fmt.Printf("Object ID % x\n Object LEN: % x\nCurr OBJ = %s\n", currID, currLen, currObj)
}
}
```

References
----------
- [Modbus Specifications and Implementation Guides](http://www.modbus.org/specs.php)
- [Modbus Application Protocol](https://modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf)
4 changes: 4 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ type Client interface {
// ReadHoldingRegisters reads the contents of a contiguous block of
// holding registers in a remote device and returns register value.
ReadHoldingRegisters(address, quantity uint16) (results []byte, err error)

ReadDeviceIdentification(devIdCode byte, objectId byte) (results []byte, err error)
GetDeviceIdentification(devIdCode byte, objectId byte) (results DeviceIdentification, err error)

// WriteSingleRegister writes a single holding register in a remote
// device and returns register value.
WriteSingleRegister(address, value uint16) (results []byte, err error)
Expand Down
Loading