Skip to content

Commit 66aa1fd

Browse files
committed
fix: print original function code for exceptions
Fixes #46.
1 parent d6cde5f commit 66aa1fd

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

modbus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (e *Error) Error() string {
8989
default:
9090
name = "unknown"
9191
}
92-
return fmt.Sprintf("modbus: exception '%v' (%s), function '%v'", e.ExceptionCode, name, e.FunctionCode)
92+
return fmt.Sprintf("modbus: exception '%v' (%s), function '%v'", e.ExceptionCode, name, e.FunctionCode&0x7F)
9393
}
9494

9595
// ProtocolDataUnit (PDU) is independent of underlying communication layers.

test/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func ClientTestReadFIFOQueue(t *testing.T, client modbus.Client) {
132132
results, err := client.ReadFIFOQueue(address)
133133
// Server not implemented
134134
if err != nil {
135-
AssertEquals(t, "modbus: exception '1' (illegal function), function '152'", err.Error())
135+
AssertEquals(t, "modbus: exception '1' (illegal function), function '24'", err.Error())
136136
} else {
137137
AssertEquals(t, 0, len(results))
138138
}

0 commit comments

Comments
 (0)