Compare commits
6 Commits
v0.0.1
...
1c8ea53e87
| Author | SHA1 | Date | |
|---|---|---|---|
| 1c8ea53e87 | |||
|
|
0377201fc9 | ||
|
|
a77c072cb5 | ||
| 8c260d4061 | |||
|
|
f79cf0243b | ||
| 4a82e6f652 |
58
client.go
58
client.go
@@ -1188,11 +1188,11 @@ func (mc *ModbusClient) readRegistersWithFunctionCode(addr uint16, quantity uint
|
||||
unitId: mc.unitId,
|
||||
}
|
||||
|
||||
if functionCode != fcCustomize {
|
||||
err = ErrUnexpectedParameters
|
||||
mc.logger.Errorf("unexpected function code (%d)", functionCode)
|
||||
return
|
||||
}
|
||||
// if functionCode != fcCustomize {
|
||||
// err = ErrUnexpectedParameters
|
||||
// mc.logger.Errorf("unexpected function code (%d)", functionCode)
|
||||
// return
|
||||
// }
|
||||
|
||||
if functionCode == 0 {
|
||||
err = ErrUnexpectedParameters
|
||||
@@ -1232,21 +1232,53 @@ func (mc *ModbusClient) readRegistersWithFunctionCode(addr uint16, quantity uint
|
||||
}
|
||||
|
||||
// validate the response code
|
||||
// switch {
|
||||
// case res.functionCode == req.functionCode:
|
||||
// // make sure the payload length is what we expect
|
||||
// // (1 byte of length + 2 bytes per register)
|
||||
// if len(res.payload) != 1+2*int(quantity) {
|
||||
// err = ErrProtocolError
|
||||
// return
|
||||
// }
|
||||
|
||||
// // validate the byte count field
|
||||
// // (2 bytes per register * number of registers)
|
||||
// if uint(res.payload[0]) != 2*uint(quantity) {
|
||||
// err = ErrProtocolError
|
||||
// return
|
||||
// }
|
||||
|
||||
// // remove the byte count field from the returned slice
|
||||
// bytes = res.payload[1:]
|
||||
|
||||
// case res.functionCode == (req.functionCode | 0x80):
|
||||
// if len(res.payload) != 1 {
|
||||
// err = ErrProtocolError
|
||||
// return
|
||||
// }
|
||||
|
||||
// err = mapExceptionCodeToError(res.payload[0])
|
||||
|
||||
// default:
|
||||
// err = ErrProtocolError
|
||||
// mc.logger.Warningf("unexpected response code (%v)", res.functionCode)
|
||||
// }
|
||||
|
||||
switch {
|
||||
case res.functionCode == req.functionCode:
|
||||
// make sure the payload length is what we expect
|
||||
// (1 byte of length + 2 bytes per register)
|
||||
if len(res.payload) != 1+2*int(quantity) {
|
||||
err = ErrProtocolError
|
||||
return
|
||||
}
|
||||
// if len(res.payload) != 1+2*int(quantity) {
|
||||
// err = ErrProtocolError
|
||||
// return
|
||||
// }
|
||||
|
||||
// validate the byte count field
|
||||
// (2 bytes per register * number of registers)
|
||||
if uint(res.payload[0]) != 2*uint(quantity) {
|
||||
err = ErrProtocolError
|
||||
return
|
||||
}
|
||||
// if uint(res.payload[0]) != 2*uint(quantity) {
|
||||
// err = ErrProtocolError
|
||||
// return
|
||||
// }
|
||||
|
||||
// remove the byte count field from the returned slice
|
||||
bytes = res.payload[1:]
|
||||
|
||||
Reference in New Issue
Block a user