Documentation
¶
Index ¶
- Constants
- func Bcd2Number(bcd []byte) string
- func DecodeException(buffer *bytes.Buffer) error
- func DecoderData(buffer *bytes.Buffer, size int) (*bytes.Buffer, error)
- func GetHex(protocol *Protocol) (string, error)
- func Hex2Byte(str string) []byte
- func Int2bytes(data int32, ver ProtoVersion) []byte
- func IsStateUin8(des uint8, i int) bool
- func Number2bcd(number string) []byte
- func WriteWithOffSet(buffer *bytes.Buffer, data byte) error
- type Address
- type Client
- type ClientProvider
- type ClientProviderOption
- func WithEnableLogger() ClientProviderOption
- func WithLogProvider(provider LogProvider) ClientProviderOption
- func WithLogSaver(l LogSaver) ClientProviderOption
- func WithPrefixHandler(prefixHandler PrefixHandler) ClientProviderOption
- func WithSerialConfig(config serial.Config) ClientProviderOption
- func WithTCPTimeout(t time.Duration) ClientProviderOption
- type Control
- func (c *Control) Encode(buffer *bytes.Buffer) error
- func (c *Control) IsState(ver ProtoVersion, state ControlKind) bool
- func (c *Control) IsStates(ver ProtoVersion, state ...ControlKind) bool
- func (c *Control) Reset()
- func (c *Control) SetState(ver ProtoVersion, state ControlKind)
- func (c *Control) SetStates(ver ProtoVersion, state ...ControlKind)
- type ControlKind
- type ControlType
- type DateTime
- type Decoder
- type DefaultPrefix
- type Exception
- type InformationElement
- type LogProvider
- type LogSaver
- type NullData
- type Option
- type Order
- type PrefixHandler
- type ProtoVersion
- type Protocol
- func Decode(ver ProtoVersion, buffer *bytes.Buffer) (*Protocol, error)
- func NewProtocol(address Address, data InformationElement, control *Control) *Protocol
- func ReadRequest(ver ProtoVersion, address Address, itemCode int32) *Protocol
- func ReadRequestWithBlock(ver ProtoVersion, address Address, data ReadRequestData) *Protocol
- func ReadResponse(ver ProtoVersion, address Address, itemCode int32, control *Control, ...) *Protocol
- type RTUClientProvider
- func (sf *RTUClientProvider) Close() (err error)
- func (sf *RTUClientProvider) Connect() (err error)
- func (sf RTUClientProvider) Debugf(format string, v ...interface{})
- func (sf RTUClientProvider) Errorf(format string, v ...interface{})
- func (sf *RTUClientProvider) IsConnected() (b bool)
- func (sf *RTUClientProvider) LogMode(enable bool)
- func (sf *RTUClientProvider) ReadRawFrame() (aduResponse []byte, err error)
- func (sf *RTUClientProvider) Send(p *Protocol) (err error)
- func (sf *RTUClientProvider) SendAndRead(p *Protocol) (aduResponse []byte, err error)
- func (sf *RTUClientProvider) SendRawFrame(station string, aduRequest []byte) (err error)
- func (sf *RTUClientProvider) SendRawFrameAndRead(station string, aduRequest []byte) (aduResponse []byte, err error)
- type ReadData
- func (d ReadData) Encode(buffer *bytes.Buffer) error
- func (d *ReadData) GetDataType() []byte
- func (d *ReadData) GetDataTypeStr() string
- func (d *ReadData) GetFloat64Value() float64
- func (d *ReadData) GetFloat64ValueUnsigned() float64
- func (d *ReadData) GetFloat64ValueWithTime() *ReadDataWithTime
- func (d ReadData) GetLen() byte
- func (d ReadData) GetValue() string
- type ReadDataWithTime
- type ReadRequestData
- type Value
- type WriteData
- type YearDateTimeS
- type ZapLogger
Constants ¶
const ( DirTx = iota + 1 DirRx )
const ( LittleEndian Order = false BigEndian Order = true Start = 0x68 End = 0x16 HeadLen = 1 + 6 + 1 BroadcastAddress = "999999999999" )
const SerialDefaultTimeout = 2 * time.Second
SerialDefaultTimeout Serial Default timeout
Variables ¶
This section is empty.
Functions ¶
func Bcd2Number ¶
func DecodeException ¶
func Int2bytes ¶
func Int2bytes(data int32, ver ProtoVersion) []byte
func IsStateUin8 ¶
func Number2bcd ¶
Types ¶
type Address ¶
type Address struct {
// contains filtered or unexported fields
}
Address 表计地址
func (Address) GetStrAddress ¶
type Client ¶
type Client interface {
ClientProvider
//Read 发送读请求
Read(ver ProtoVersion, address Address, itemCode int32) (*ReadData, bool, error)
//ReadWithBlock 读请求使能块
ReadWithBlock(ver ProtoVersion, address Address, data ReadRequestData) (*Protocol, error)
//Broadcast 开始广播
Broadcast(ver ProtoVersion, p InformationElement, control Control) error
}
func NewClient ¶
func NewClient(p ClientProvider, opts ...Option) Client
type ClientProvider ¶
type ClientProvider interface {
// Connect try to connect the remote server
Connect() error
// IsConnected returns a bool signifying whether
// the client is connected or not.
IsConnected() bool
LogMode(enable bool)
// Close disconnect the remote server
Close() error
SendAndRead(*Protocol) (aduResponse []byte, err error)
SendRawFrameAndRead(station string, aduRequest []byte) (aduResponse []byte, err error)
SendRawFrame(station string, aduRequest []byte) (err error)
ReadRawFrame() (aduResponse []byte, err error)
Send(*Protocol) (err error)
// contains filtered or unexported methods
}
type ClientProviderOption ¶
type ClientProviderOption func(ClientProvider)
ClientProviderOption client provider option for user.
func WithEnableLogger ¶
func WithEnableLogger() ClientProviderOption
WithEnableLogger enable log output when you has set logger.
func WithLogProvider ¶
func WithLogProvider(provider LogProvider) ClientProviderOption
WithLogProvider set logger provider.
func WithLogSaver ¶
func WithLogSaver(l LogSaver) ClientProviderOption
func WithPrefixHandler ¶
func WithPrefixHandler(prefixHandler PrefixHandler) ClientProviderOption
func WithSerialConfig ¶
func WithSerialConfig(config serial.Config) ClientProviderOption
WithSerialConfig set serial config, only valid on serial.
func WithTCPTimeout ¶
func WithTCPTimeout(t time.Duration) ClientProviderOption
WithTCPTimeout set tcp Connect & Read timeout, only valid on TCP.
type Control ¶
type Control struct {
Data ControlType
}
func NewControl ¶
func NewControl() *Control
func NewControlValue ¶
func NewControlValue(data ControlType) *Control
func (*Control) IsState ¶
func (c *Control) IsState(ver ProtoVersion, state ControlKind) bool
func (*Control) IsStates ¶
func (c *Control) IsStates(ver ProtoVersion, state ...ControlKind) bool
IsStates 判断控制域
func (*Control) SetState ¶
func (c *Control) SetState(ver ProtoVersion, state ControlKind)
func (*Control) SetStates ¶
func (c *Control) SetStates(ver ProtoVersion, state ...ControlKind)
SetStates 批量设置状态
type ControlKind ¶
type ControlKind int
const ( IsSlave ControlKind = iota + 1 SlaveErr HasNext //Retain 保留 Retain //Broadcast 广播校时 Broadcast // ReadNext 读后续10001 ReadNext //ReadAddress 读通讯地址 ReadAddress //Write 写数据 Write //WriteAddress 读通讯地址 WriteAddress //ToChangeCommunicationRate 更改通讯速率 ToChangeCommunicationRate Freeze //PassWord 修改密码 PassWord ResetMaxDemand //ResetEM 电表清零 ResetEM ResetEvent //Read 读 Read )
type ControlType ¶
type ControlType byte
type DefaultPrefix ¶
type DefaultPrefix struct {
}
func (DefaultPrefix) DecodePrefix ¶
func (DefaultPrefix) EncodePrefix ¶
func (d DefaultPrefix) EncodePrefix(buffer *bytes.Buffer) error
type InformationElement ¶
func DecodeNullData ¶
func DecodeNullData(*bytes.Buffer) InformationElement
func DecodeRead ¶
func DecodeRead(buffer *bytes.Buffer, size int, ver ProtoVersion) InformationElement
func Handler ¶
func Handler(control *Control, buffer *bytes.Buffer, size byte, ver ProtoVersion) (InformationElement, error)
type LogProvider ¶
type LogProvider interface {
Errorf(format string, v ...interface{})
Debugf(format string, v ...interface{})
}
LogProvider log message levels only Debug and Error
type PrefixHandler ¶
type Protocol ¶
type Protocol struct {
Version ProtoVersion
//Start 645协议起始符号
Start byte
//设备地址 6个字节的BCD
Address Address
//Start 645协议起始符号 标志报文头结束
Start2 byte
//Control 控制域
Control *Control
//Control 数据长度
DataLength byte
//Control 数据抽象
Data InformationElement
//CS 校验和
CS byte
//End 0x16
End byte
}
Protocol 协议
func NewProtocol ¶
func NewProtocol(address Address, data InformationElement, control *Control) *Protocol
func ReadRequest ¶
func ReadRequest(ver ProtoVersion, address Address, itemCode int32) *Protocol
ReadRequest 读数据
func ReadRequestWithBlock ¶
func ReadRequestWithBlock(ver ProtoVersion, address Address, data ReadRequestData) *Protocol
ReadRequestWithBlock 读数据
func ReadResponse ¶
func ReadResponse(ver ProtoVersion, address Address, itemCode int32, control *Control, rawValue string) *Protocol
ReadResponse 创建读响应
type RTUClientProvider ¶
type RTUClientProvider struct {
PrefixHandler
// contains filtered or unexported fields
}
func NewRTUClientProvider ¶
func NewRTUClientProvider(opts ...ClientProviderOption) *RTUClientProvider
NewRTUClientProvider allocates and initializes a RTUClientProvider. it will use default /dev/ttyS0 19200 8 1 N and timeout 1000
func (*RTUClientProvider) Close ¶
func (sf *RTUClientProvider) Close() (err error)
Close current connection.
func (*RTUClientProvider) Connect ¶
func (sf *RTUClientProvider) Connect() (err error)
Connect try to connect the remote server
func (RTUClientProvider) Debugf ¶
func (sf RTUClientProvider) Debugf(format string, v ...interface{})
Debug Log DEBUG level message.
func (RTUClientProvider) Errorf ¶
func (sf RTUClientProvider) Errorf(format string, v ...interface{})
Error Log ERROR level message.
func (*RTUClientProvider) IsConnected ¶
func (sf *RTUClientProvider) IsConnected() (b bool)
IsConnected returns a bool signifying whether the client is connected or not.
func (*RTUClientProvider) LogMode ¶
func (sf *RTUClientProvider) LogMode(enable bool)
LogMode set enable or disable log output when you has set logger.
func (*RTUClientProvider) ReadRawFrame ¶
func (sf *RTUClientProvider) ReadRawFrame() (aduResponse []byte, err error)
ReadRawFrame 读取返回数据
func (*RTUClientProvider) Send ¶
func (sf *RTUClientProvider) Send(p *Protocol) (err error)
func (*RTUClientProvider) SendAndRead ¶
func (sf *RTUClientProvider) SendAndRead(p *Protocol) (aduResponse []byte, err error)
SendAndRead 发送数据并读取返回值
func (*RTUClientProvider) SendRawFrame ¶
func (sf *RTUClientProvider) SendRawFrame(station string, aduRequest []byte) (err error)
func (*RTUClientProvider) SendRawFrameAndRead ¶
func (sf *RTUClientProvider) SendRawFrameAndRead(station string, aduRequest []byte) (aduResponse []byte, err error)
type ReadData ¶
type ReadData struct {
Negative bool
// contains filtered or unexported fields
}
ReadData 数据域
func NewReadData ¶
func NewReadData(dataType int32, value string, ver ProtoVersion) ReadData
func (*ReadData) GetDataType ¶
func (*ReadData) GetDataTypeStr ¶
func (*ReadData) GetFloat64Value ¶
func (*ReadData) GetFloat64ValueUnsigned ¶
func (*ReadData) GetFloat64ValueWithTime ¶
func (d *ReadData) GetFloat64ValueWithTime() *ReadDataWithTime
type ReadDataWithTime ¶
type ReadDataWithTime struct {
ReadData
// contains filtered or unexported fields
}
type ReadRequestData ¶
type ReadRequestData struct {
// contains filtered or unexported fields
}
func (ReadRequestData) GetLen ¶
func (r ReadRequestData) GetLen() byte
type YearDateTimeS ¶
type YearDateTimeS struct {
// contains filtered or unexported fields
}
func NewTimeS ¶
func NewTimeS() *YearDateTimeS
func (YearDateTimeS) GetLen ¶
func (t YearDateTimeS) GetLen() byte