dlt645

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AddressBroadCast = 0
	AddressMin       = 1
)

proto address limit

View Source
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

View Source
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

View Source
const (
	ExceptionCodeIllegalFunction                    = 1
	ExceptionCodeIllegalDataAddress                 = 2
	ExceptionCodeIllegalDataValue                   = 3
	ExceptionCodeServerDeviceFailure                = 4
	ExceptionCodeAcknowledge                        = 5
	ExceptionCodeServerDeviceBusy                   = 6
	ExceptionCodeNegativeAcknowledge                = 7
	ExceptionCodeMemoryParityError                  = 8
	ExceptionCodeGatewayPathUnavailable             = 10
	ExceptionCodeGatewayTargetDeviceFailedToRespond = 11
)

Exception Code

View Source
const (
	// SerialDefaultTimeout Serial Default timeout
	SerialDefaultTimeout = 1 * time.Second
	// SerialDefaultAutoReconnect Serial Default auto reconnect count
	SerialDefaultAutoReconnect = 0
)

Variables

View Source
var AddressMax byte = addressMax

AddressMax proto address max limit you can change with SetSpecialAddressMax, when your device have address upon addressMax

View Source
var ErrClosedConnection = errors.New("use of closed connection")

ErrClosedConnection 连接已关闭

View Source
var ErrConnectionFailed = errors.New("create connection failed")

Functions

func CheckCode

func CheckCode(data string) string

计算出校验码

func DecConvertToX

func DecConvertToX(n, num int) (string, error)

func HexStringToBytes

func HexStringToBytes(data string) []byte

把字符串转换成字节数组

Types

type Client

type Client interface {
	ClientProvider

	// 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

	// 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 dltcon 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 float64, err error)
}

ClientProvider is the interface implements underlying methods.

type Dlt645ClientProvider

type Dlt645ClientProvider struct {
	// contains filtered or unexported fields
}

RTUClientProvider implements ClientProvider interface.

func NewClientProvider

func NewClientProvider() *Dlt645ClientProvider

NewRTUClientProvider allocates and initializes a RTUClientProvider. it will use default /dev/ttyS0 19200 8 1 N and timeout 1000

func (*Dlt645ClientProvider) Close

func (sf *Dlt645ClientProvider) Close() error

Close close current connection.

func (*Dlt645ClientProvider) Connect

func (sf *Dlt645ClientProvider) Connect() error

Connect try to connect the remote server

func (Dlt645ClientProvider) Debug

func (sf Dlt645ClientProvider) Debug(format string, v ...interface{})

Debug Log DEBUG level message.

func (Dlt645ClientProvider) Error

func (sf Dlt645ClientProvider) Error(format string, v ...interface{})

Error Log ERROR level message.

func (*Dlt645ClientProvider) IsConnected

func (sf *Dlt645ClientProvider) IsConnected() bool

IsConnected returns a bool signifying whether the client is connected or not.

func (*Dlt645ClientProvider) LogMode

func (sf *Dlt645ClientProvider) LogMode(enable bool)

LogMode set enable or disable log output when you has set logger

func (*Dlt645ClientProvider) Send

func (sf *Dlt645ClientProvider) Send(slaveID byte, request ProtocolDataUnit) (ProtocolDataUnit, error)

Send request to the remote server,it implements on SendRawFrame

func (*Dlt645ClientProvider) SendPdu

func (sf *Dlt645ClientProvider) SendPdu(slaveID byte, pduRequest []byte) ([]byte, error)

SendPdu send pdu request to the remote server

func (*Dlt645ClientProvider) SendRawFrame

func (dlt *Dlt645ClientProvider) SendRawFrame(request string) (response float64, err error)

SendRawFrame send Adu frame SendRawFrame发送Adu帧。

func (*Dlt645ClientProvider) SetAutoReconnect

func (sf *Dlt645ClientProvider) SetAutoReconnect(cnt byte)

SetAutoReconnect set auto reconnect count if cnt == 0, disable auto reconnect if cnt > 0 ,enable auto reconnect,but max 6

func (*Dlt645ClientProvider) SetLogProvider

func (sf *Dlt645ClientProvider) SetLogProvider(p LogProvider)

SetLogProvider overwrite log provider

type Dlt645ConfigClient

type Dlt645ConfigClient struct {
	MeterNumber string
	DataMarker  string
}

func (*Dlt645ConfigClient) SendMessageToSerial

func (dltconfig *Dlt645ConfigClient) SendMessageToSerial(dlt Client) (response float64, err error)

type ExceptionError

type ExceptionError struct {
	ExceptionCode byte
}

ExceptionError implements error interface.

func (*ExceptionError) Error

func (e *ExceptionError) Error() 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

type ProtocolDataUnit struct {
	FuncCode byte
	Data     []byte
}

ProtocolDataUnit (PDU) is independent of underlying communication layers.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL