You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool-biz/nmodbus/protocol/errors.go

66 lines
2.0 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package protocol
import "fmt"
type MError uint8
var (
// Success 成功
Success MError = 0
// IllegalFunction 接收到的功能码不可识别或服务端(从机)未实现其功能
IllegalFunction MError = 1
// IllegalDataAddress 数据地址不可接收
IllegalDataAddress MError = 2
// IllegalDataValue 数据不被识别
IllegalDataValue MError = 3
// SlaveDeviceFailure 不可恢复的错误
SlaveDeviceFailure MError = 4
// AcknowledgeSlave 已接受并正在处理的耗时请求防止发生超时错误主站可以发送一个poll(pgc)来确定消息是否处理完成
AcknowledgeSlave MError = 5
// SlaveDeviceBusy 从站正在处理耗时指令,从站忙
SlaveDeviceBusy MError = 6
// NegativeAcknowledge 从站无法处理此请求
NegativeAcknowledge MError = 7
// MemoryParityError 从站检测到奇偶校验错误,但仍然需要提供服务,故此返回此错误
MemoryParityError MError = 8
// GatewayPathUnavailable Modbus网关配置错误
GatewayPathUnavailable MError = 10
// GatewayTargetDeviceFailedToRespond Modbus网关从机无法响应
GatewayTargetDeviceFailedToRespond MError = 11
)
func (e MError) Error() string {
return fmt.Sprintf("%d", e)
}
func (e MError) 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
}