forked from tbrandon/mbserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exceptions.go
64 lines (59 loc) · 2.43 KB
/
exceptions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package mbserver
import "fmt"
// Exception codes.
type Exception uint8
var (
// Success operation successful.
Success Exception
// IllegalFunction function code received in the query is not recognized or allowed by slave.
IllegalFunction Exception = 1
// IllegalDataAddress data address of some or all the required entities are not allowed or do not exist in slave.
IllegalDataAddress Exception = 2
// IllegalDataValue value is not accepted by slave.
IllegalDataValue Exception = 3
// SlaveDeviceFailure Unrecoverable error occurred while slave was attempting to perform requested action.
SlaveDeviceFailure Exception = 4
// AcknowledgeSlave has accepted request and is processing it, but a long duration of time is required. This response is returned to prevent a timeout error from occurring in the master. Master can next issue a Poll Program Complete message to determine whether processing is completed.
AcknowledgeSlave Exception = 5
// SlaveDeviceBusy is engaged in processing a long-duration command. Master should retry later.
SlaveDeviceBusy Exception = 6
// NegativeAcknowledge Slave cannot perform the programming functions. Master should request diagnostic or error information from slave.
NegativeAcknowledge Exception = 7
// MemoryParityError Slave detected a parity error in memory. Master can retry the request, but service may be required on the slave device.
MemoryParityError Exception = 8
// GatewayPathUnavailable Specialized for Modbus gateways. Indicates a misconfigured gateway.
GatewayPathUnavailable Exception = 10
// GatewayTargetDeviceFailedToRespond Specialized for Modbus gateways. Sent when slave fails to respond.
GatewayTargetDeviceFailedToRespond Exception = 11
)
func (e Exception) Error() string {
return fmt.Sprintf("%d", e)
}
func (e Exception) String() string {
switch e {
case Success:
return "Success"
case IllegalFunction:
return "IllegalFunction"
case IllegalDataAddress:
return "IllegalDataAddress"
case IllegalDataValue:
return "IllegalDataValue"
case SlaveDeviceFailure:
return "SlaveDeviceFailure"
case AcknowledgeSlave:
return "AcknowledgeSlave"
case SlaveDeviceBusy:
return "SlaveDeviceBusy"
case NegativeAcknowledge:
return "NegativeAcknowledge"
case MemoryParityError:
return "MemoryParityError"
case GatewayPathUnavailable:
return "GatewayPathUnavailable"
case GatewayTargetDeviceFailedToRespond:
return "GatewayTargetDeviceFailedToRespond"
default:
return "unknown"
}
}