Versions in this module Expand all Collapse all v0 v0.1.0 Feb 15, 2018 Changes in this version + const MaxPDUSize + const MaxRTUSize + var DebugOut io.Writer + var ErrFcNotSupported = errors.New("this FunctionCode is not supported") + var ErrServerTimeOut = errors.New("server timed out") + var ErrorCrc = fmt.Errorf("RTU data crc not valid") + var OverSizeMaxRTU = MaxRTUSize + var OverSizeSupport = false + func BoolsToData(values []bool, fc FunctionCode) ([]byte, error) + func BytesDelay(baudRate int64, n int) time.Duration + func DataToBools(data []byte, count uint16, fc FunctionCode) ([]bool, error) + func DataToRegisters(data []byte) ([]uint16, error) + func DoTransactions(c RTUTransactionStarter, slaveID byte, reqs []PDU) (int, error) + func GetPDUSizeFromHeader(header []byte, isClient bool) int + func GetRTUSizeFromHeader(header []byte, isClient bool) int + func MatchPDU(ask PDU, ans PDU) bool + func MinDelay(baudRate int64) time.Duration + func NewRTUPacketReader(r SerialContext, isClient bool) io.Reader + func RegistersToData(values []uint16) ([]byte, error) + func Uint64ToSlaveID(n uint64) (byte, error) + type ExceptionCode byte + const EcAcknowledge + const EcGatewayPathUnavailable + const EcGatewayTargetDeviceFailedToRespond + const EcIllegalDataAddress + const EcIllegalDataValue + const EcIllegalFunction + const EcInternal + const EcMemoryParityError + const EcOK + const EcServerDeviceBusy + const EcServerDeviceFailure + func ToExceptionCode(err error) ExceptionCode + func (e ExceptionCode) Error() string + type FunctionCode byte + const FcReadCoils + const FcReadDiscreteInputs + const FcReadHoldingRegisters + const FcReadInputRegisters + const FcWriteMultipleCoils + const FcWriteMultipleRegisters + const FcWriteSingleCoil + const FcWriteSingleRegister + func (f FunctionCode) IsBool() bool + func (f FunctionCode) IsReadToServer() bool + func (f FunctionCode) IsSingle() bool + func (f FunctionCode) IsUint16() bool + func (f FunctionCode) IsWriteToServer() bool + func (f FunctionCode) MakeRequestHeader(address, quantity uint16) (PDU, error) + func (f FunctionCode) MaxPerPacket() uint16 + func (f FunctionCode) MaxPerPacketSized(size int) uint16 + func (f FunctionCode) MaxRange() uint16 + func (f FunctionCode) SeparateError() (bool, FunctionCode) + func (f FunctionCode) Valid() bool + func (f FunctionCode) WithError() FunctionCode + type PDU []byte + func ExceptionReplyPacket(req PDU, e ExceptionCode) PDU + func MakePDURequestHeaders(fc FunctionCode, address, quantity uint16, appendTO []PDU) ([]PDU, error) + func MakePDURequestHeadersSized(fc FunctionCode, address, quantity uint16, maxPerPacket uint16, appendTO []PDU) ([]PDU, error) + func (p PDU) GetAddress() uint16 + func (p PDU) GetFunctionCode() FunctionCode + func (p PDU) GetReplyValues() ([]byte, error) + func (p PDU) GetRequestCount() uint16 + func (p PDU) GetRequestValues() ([]byte, error) + func (p PDU) MakeReadReply(data []byte) PDU + func (p PDU) MakeWriteReply() PDU + func (p PDU) MakeWriteRequest(data []byte) PDU + func (p PDU) ValidateRequest() error + type ProtocalHandler interface + OnError func(req PDU, errRep PDU) + OnRead func(req PDU) (data []byte, err error) + OnWrite func(req PDU, data []byte) error + type RTU []byte + func MakeRTU(slaveID byte, p PDU) RTU + func (r RTU) GetPDU() (PDU, error) + func (r RTU) IsMulticast() bool + type RTUClient struct + SlaveID byte + func NewRTUCLient(com SerialContext, slaveID byte) *RTUClient + func (c *RTUClient) DoTransaction(req PDU) error + func (c *RTUClient) GetTransactionTimeOut(reqLen, ansLen int) time.Duration + func (c *RTUClient) Serve(handler ProtocalHandler) error + func (c *RTUClient) SetServerProcessingTime(t time.Duration) + func (c *RTUClient) StartTransactionToServer(slaveID byte, req PDU, errChan chan error) + type RTUServer struct + SlaveID byte + func NewRTUServer(com SerialContext, slaveID byte) *RTUServer + func (s *RTUServer) Serve(handler ProtocalHandler) error + type RTUTransactionStarter interface + StartTransactionToServer func(slaveID byte, req PDU, errChan chan error) + type SerialContext interface + BytesDelay func(n int) time.Duration + MinDelay func() time.Duration + Stats func() *Stats + func NewSerialContext(conn io.ReadWriteCloser, baudRate int64) SerialContext + type Server interface + Serve func(handler ProtocalHandler) error + type SimpleHandler struct + OnErrorImp func(req PDU, errRep PDU) + ReadCoils func(address, quantity uint16) ([]bool, error) + ReadDiscreteInputs func(address, quantity uint16) ([]bool, error) + ReadHoldingRegisters func(address, quantity uint16) ([]uint16, error) + ReadInputRegisters func(address, quantity uint16) ([]uint16, error) + WriteCoils func(address uint16, values []bool) error + WriteDiscreteInputs func(address uint16, values []bool) error + WriteHoldingRegisters func(address uint16, values []uint16) error + WriteInputRegisters func(address uint16, values []uint16) error + func (h *SimpleHandler) OnError(req PDU, errRep PDU) + func (h *SimpleHandler) OnRead(req PDU) ([]byte, error) + func (h *SimpleHandler) OnWrite(req PDU, data []byte) error + type Stats struct + CrcErrors int64 + FormateWarnings int64 + IdDrops int64 + LongReadWarnings int64 + OtherDrops int64 + OtherErrors int64 + ReadPackets int64 + RemoteErrors int64