1 Star 0 Fork 1

flyiot/flylibs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
exceptions.go 2.60 KB
一键复制 编辑 原始数据 按行查看 历史
flyrainning 提交于 2023-03-03 16:52 +08:00 . u
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 {
var str string
switch e {
case Success:
str = fmt.Sprintf("Success")
case IllegalFunction:
str = fmt.Sprintf("IllegalFunction")
case IllegalDataAddress:
str = fmt.Sprintf("IllegalDataAddress")
case IllegalDataValue:
str = fmt.Sprintf("IllegalDataValue")
case SlaveDeviceFailure:
str = fmt.Sprintf("SlaveDeviceFailure")
case AcknowledgeSlave:
str = fmt.Sprintf("AcknowledgeSlave")
case SlaveDeviceBusy:
str = fmt.Sprintf("SlaveDeviceBusy")
case NegativeAcknowledge:
str = fmt.Sprintf("NegativeAcknowledge")
case MemoryParityError:
str = fmt.Sprintf("MemoryParityError")
case GatewayPathUnavailable:
str = fmt.Sprintf("GatewayPathUnavailable")
case GatewayTargetDeviceFailedtoRespond:
str = fmt.Sprintf("GatewayTargetDeviceFailedtoRespond")
default:
str = fmt.Sprintf("unknown")
}
return str
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/flyiot/flylibs.git
git@gitee.com:flyiot/flylibs.git
flyiot
flylibs
flylibs
b9c81f1c9857

搜索帮助