Documentation
¶
Index ¶
- Constants
- Variables
- func CheckCode(data string) string
- func ConvertBinaryTo16Base(controlDomain string) string
- func DecConvertToX(n, num int) (string, error)
- func HexStringToBytes(data string) []byte
- func StringToIntArray(input string) []int
- type Client
- type ClientProvider
- type ExceptionError
- type Iec103ClientProvider
- func (sf *Iec103ClientProvider) Close() error
- func (sf *Iec103ClientProvider) Connect() error
- func (sf Iec103ClientProvider) Debug(format string, v ...interface{})
- func (sf Iec103ClientProvider) Error(format string, v ...interface{})
- func (sf *Iec103ClientProvider) IsConnected() bool
- func (sf *Iec103ClientProvider) LogMode(enable bool)
- func (sf *Iec103ClientProvider) Send(slaveID byte, request ProtocolDataUnit) (ProtocolDataUnit, error)
- func (sf *Iec103ClientProvider) SendPdu(slaveID byte, pduRequest []byte) ([]byte, error)
- func (iec *Iec103ClientProvider) SendRawFrame(request string) (response string, err error)
- func (sf *Iec103ClientProvider) SetAutoReconnect(cnt byte)
- func (sf *Iec103ClientProvider) SetLogProvider(p LogProvider)
- type Iec103ConfigClient
- type LogProvider
- type ProtocolDataUnit
Constants ¶
const ( AddressBroadCast = 0 AddressMin = 1 )
proto address limit
const ( // Bits ReadBitsQuantityMin = 1 // 0x0001 ReadBitsQuantityMax = 2000 // 0x07d0 WriteBitsQuantityMin = 1 // 1 WriteBitsQuantityMax = 1968 // 0x07b0 // 16 Bits ReadRegQuantityMin = 1 // 1 ReadRegQuantityMax = 125 // 0x007d WriteRegQuantityMin = 1 // 1 WriteRegQuantityMax = 123 // 0x007b ReadWriteOnReadRegQuantityMin = 1 // 1 ReadWriteOnReadRegQuantityMax = 125 // 0x007d ReadWriteOnWriteRegQuantityMin = 1 // 1 ReadWriteOnWriteRegQuantityMax = 121 // 0x0079 )
proto register limit
const ( // Bit access FuncCodeReadDiscreteInputs = 2 FuncCodeReadCoils = 1 FuncCodeWriteSingleCoil = 5 FuncCodeWriteMultipleCoils = 15 // 16-bit access FuncCodeReadInputRegisters = 4 FuncCodeReadHoldingRegisters = 3 FuncCodeWriteSingleRegister = 6 FuncCodeWriteMultipleRegisters = 16 FuncCodeReadWriteMultipleRegisters = 23 FuncCodeMaskWriteRegister = 22 FuncCodeReadFIFOQueue = 24 FuncCodeOtherReportSlaveID = 17 )
Function Code
const ( ExceptionCodeIllegalFunction = 1 ExceptionCodeIllegalDataAddress = 2 ExceptionCodeIllegalDataValue = 3 ExceptionCodeServerDeviceFailure = 4 ExceptionCodeAcknowledge = 5 ExceptionCodeServerDeviceBusy = 6 ExceptionCodeNegativeAcknowledge = 7 ExceptionCodeMemoryParityError = 8 ExceptionCodeGatewayTargetDeviceFailedToRespond = 11 )
Exception Code
const ( //start character StartCharacter10 = "10" //end character Endcharacter = "16" StartCharacter68 = "68" )
const ( // SerialDefaultTimeout Serial Default timeout SerialDefaultTimeout = 1 * time.Second // SerialDefaultAutoReconnect Serial Default auto reconnect count SerialDefaultAutoReconnect = 0 )
Variables ¶
var AddressMax byte = addressMax
AddressMax proto address max limit you can change with SetSpecialAddressMax, when your device have address upon addressMax
var ErrClosedConnection = errors.New("use of closed connection")
ErrClosedConnection 连接已关闭
Functions ¶
func ConvertBinaryTo16Base ¶
func DecConvertToX ¶
func StringToIntArray ¶
Types ¶
type Client ¶
type Client interface { ClientProvider // Bits // ReadCoils reads from 1 to 2000 contiguous status of coils in a // remote device and returns coil status. ReadCoils(slaveID byte, address, quantity uint16) (results []byte, err error) // ReadDiscreteInputs reads from 1 to 2000 contiguous status of // discrete inputs in a remote device and returns input status. ReadDiscreteInputs(slaveID byte, address, quantity uint16) (results []byte, err error) // WriteSingleCoil write a single output to either ON or OFF in a // remote device and returns success or failed. WriteSingleCoil(slaveID byte, address uint16, isOn bool) error // WriteMultipleCoils forces each coil in a sequence of coils to either // ON or OFF in a remote device and returns success or failed. WriteMultipleCoils(slaveID byte, address, quantity uint16, value []byte) error // 16-bits // ReadInputRegisters reads from 1 to 125 contiguous input registers in // a remote device and returns input registers. ReadInputRegistersBytes(slaveID byte, address, quantity uint16) (results []byte, err error) // ReadInputRegisters reads from 1 to 125 contiguous input registers in // a remote device and returns input registers. ReadInputRegisters(slaveID byte, address, quantity uint16) (results []uint16, err error) // ReadHoldingRegistersBytes reads the contents of a contiguous block of // holding registers in a remote device and returns register value. ReadHoldingRegistersBytes(slaveID byte, address, quantity uint16) (results []byte, err error) // ReadHoldingRegisters reads the contents of a contiguous block of // holding registers in a remote device and returns register value. ReadHoldingRegisters(slaveID byte, address, quantity uint16) (results []uint16, err error) // WriteSingleRegister writes a single holding register in a remote // device and returns success or failed. WriteSingleRegister(slaveID byte, address, value uint16) error // WriteMultipleRegisters writes a block of contiguous registers // (1 to 123 registers) in a remote device and returns success or failed. WriteMultipleRegisters(slaveID byte, address, quantity uint16, value []byte) error // ReadWriteMultipleRegisters performs a combination of one read // operation and one write operation. It returns read registers value. ReadWriteMultipleRegistersBytes(slaveID byte, readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) (results []byte, err error) // ReadWriteMultipleRegisters performs a combination of one read // operation and one write operation. It returns read registers value. ReadWriteMultipleRegisters(slaveID byte, readAddress, readQuantity, writeAddress, writeQuantity uint16, value []byte) (results []uint16, err error) // MaskWriteRegister modify the contents of a specified holding // register using a combination of an AND mask, an OR mask, and the // register's current contents. The function returns success or failed. MaskWriteRegister(slaveID byte, address, andMask, orMask uint16) error //ReadFIFOQueue reads the contents of a First-In-First-Out (FIFO) queue // of register in a remote device and returns FIFO value register. ReadFIFOQueue(slaveID byte, address uint16) (results []byte, err error) }
Client interface
func NewClient ¶
func NewClient(p ClientProvider) Client
NewClient creates a new ieccon client with given backend handler.
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 // SetAutoReconnect set auto reconnect count // if cnt == 0, disable auto reconnect // if cnt > 0 ,enable auto reconnect,but max 6 SetAutoReconnect(cnt byte) // LogMode set enable or diable log output when you has set logger LogMode(enable bool) // SetLogProvider set logger provider SetLogProvider(p LogProvider) // Close disconnect the remote server Close() error // Send request to the remote server,it implements on SendRawFrame Send(slaveID byte, request ProtocolDataUnit) (ProtocolDataUnit, error) // SendPdu send pdu request to the remote server SendPdu(slaveID byte, pduRequest []byte) (pduResponse []byte, err error) // SendRawFrame send raw frame to the remote server SendRawFrame(request string) (response string, err error) }
ClientProvider is the interface implements underlying methods.
type ExceptionError ¶
type ExceptionError struct {
ExceptionCode byte
}
ExceptionError implements error interface.
func (*ExceptionError) Error ¶
func (e *ExceptionError) Error() string
type Iec103ClientProvider ¶
type Iec103ClientProvider struct {
// contains filtered or unexported fields
}
RTUClientProvider implements ClientProvider interface.
func NewClientProvider ¶
func NewClientProvider() *Iec103ClientProvider
NewRTUClientProvider allocates and initializes a RTUClientProvider. it will use default /dev/ttyS0 19200 8 1 N and timeout 1000
func (*Iec103ClientProvider) Close ¶
func (sf *Iec103ClientProvider) Close() error
Close close current connection.
func (*Iec103ClientProvider) Connect ¶
func (sf *Iec103ClientProvider) Connect() error
Connect try to connect the remote server
func (Iec103ClientProvider) Debug ¶
func (sf Iec103ClientProvider) Debug(format string, v ...interface{})
Debug Log DEBUG level message.
func (Iec103ClientProvider) Error ¶
func (sf Iec103ClientProvider) Error(format string, v ...interface{})
Error Log ERROR level message.
func (*Iec103ClientProvider) IsConnected ¶
func (sf *Iec103ClientProvider) IsConnected() bool
IsConnected returns a bool signifying whether the client is connected or not.
func (*Iec103ClientProvider) LogMode ¶
func (sf *Iec103ClientProvider) LogMode(enable bool)
LogMode set enable or disable log output when you has set logger
func (*Iec103ClientProvider) Send ¶
func (sf *Iec103ClientProvider) Send(slaveID byte, request ProtocolDataUnit) (ProtocolDataUnit, error)
Send request to the remote server,it implements on SendRawFrame
func (*Iec103ClientProvider) SendPdu ¶
func (sf *Iec103ClientProvider) SendPdu(slaveID byte, pduRequest []byte) ([]byte, error)
SendPdu send pdu request to the remote server
func (*Iec103ClientProvider) SendRawFrame ¶
func (iec *Iec103ClientProvider) SendRawFrame(request string) (response string, err error)
SendRawFrame send Adu frame SendRawFrame发送Adu帧。
func (*Iec103ClientProvider) SetAutoReconnect ¶
func (sf *Iec103ClientProvider) SetAutoReconnect(cnt byte)
SetAutoReconnect set auto reconnect count if cnt == 0, disable auto reconnect if cnt > 0 ,enable auto reconnect,but max 6
func (*Iec103ClientProvider) SetLogProvider ¶
func (sf *Iec103ClientProvider) SetLogProvider(p LogProvider)
SetLogProvider overwrite log provider
type Iec103ConfigClient ¶
type Iec103ConfigClient struct { LinkAddress string /* FCB(Frame Count Degree):FCB = 0 or 1 ——Each time the master sends a new round of "send/confirm" or "request/response" transmission service to the slave station,the FCB is inverted.The master station saves a copy of FCB for each slave station,if no response is received over time,the master station will retransmit,the FCB of the retransmitted message remains unchanged,and the number of retransmissions does not exceed 3 times at most.If the expected response is not received after 3 retransmissions, the current round of transmissions service will be terminated */ FCB int /* FCV(Frame count valid bit) FCB = 0 indicates that the change of FCB is invalid, and FCB = 1 indicates that the change of FCB is invalid Send/no answer service,broadcast message does not consider message loss and repeated transmissions no need to change the FCB state, these frames FCV always 0 */ FCV int //Type identification TYP string //Reason for transmission COT string //Function type FUN string //Message number INF string //General classification identification number GIN string }
func (*Iec103ConfigClient) Initialize ¶
func (iec103 *Iec103ConfigClient) Initialize(iec Client) string
func (*Iec103ConfigClient) MasterStationReadsAnalogQuantity ¶
func (iec103 *Iec103ConfigClient) MasterStationReadsAnalogQuantity(iec Client, groupNum []int) []float32
func (*Iec103ConfigClient) SummonSecondaryData ¶
func (iec103 *Iec103ConfigClient) SummonSecondaryData(iec Client) string
type LogProvider ¶
type LogProvider interface { Error(format string, v ...interface{}) Debug(format string, v ...interface{}) }
LogProvider RFC5424 log message levels only Debug and Error
type ProtocolDataUnit ¶
ProtocolDataUnit (PDU) is independent of underlying communication layers.