dlt645

package module
v0.0.0-...-2e49d34 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

dlt645-go

使用go实现的多功能电能表通信协议

支持的指令

  • Read Data
  • Write Data
  • Read Communication Address
  • Write Communication Address
  • Broadcast Timing
  • Freeze Command
  • Change Communication Rate
  • Change Password
  • Clear Maximum Demand
  • Clear Ammeter
  • Clear Event

版本支持

  • DL/T 645 2007

用法

Basic usage:

// default configuration is 19200, 8, 1, even
handler := dlt.NewClient2007Handler(rtuDevice)
err := handler.Connect()
defer handler.Close()
client := dlt.NewClient(handler)
results, err := client.ReadData(00000000, 0, 0, 0, 0, 0, 0)

Advanced usage:

handler := dlt.NewClient2007Handler(rtuDevice)
handler.BaudRate = 4800
handler.DataBits = 8
handler.Parity = "N"
handler.StopBits = 1
handler.RS485.Enabled = true
handler.SlaveAddr = 304257140001
err := handler.Connect()
defer handler.Close()

client := dlt.NewClient(handler)
results, err := client.ReadData(00000000, 0, 0, 0, 0, 0, 0)

References

Documentation

Overview

Package dlt645 provides a client for dlt645

Index

Constants

View Source
const (
	ReadDataDomainMaxSize  = 200
	WriteDataDomainMaxSize = 50
)
View Source
const (
	CommunicationRate19200 = 0x40 // binary 0100 0000
	CommunicationRate9600  = 0x20 // binary 0010 0000
	CommunicationRate4800  = 0x10 // binary 0001 0000
	CommunicationRate2400  = 0x08 // binary 0000 1000
	CommunicationRate1200  = 0x04 // binary 0000 0100
	CommunicationRate600   = 0x02 // binary 0000 0010
)
View Source
const (
	// len limit 5-Bit
	FunctionCodeReadData                  = 0x11 // binary 0001 0001
	FunctionCodeReadFollowUpData          = 0x12 // binary 0001 0010
	FunctionCodeWriteData                 = 0x14 // binary 0001 0100
	FunctionCodeReadCommunicationAddress  = 0x13 // binary 0001 0011
	FunctionCodeWriteCommunicationAddress = 0x15 // binary 0001 0101
	FunctionCodeBroadcastTiming           = 0x8  // binary 0000 1000
	FunctionCodeFreezeCommand             = 0x16 // binary 0001 0110
	FunctionCodeChangeCommunicationRate   = 0x17 // binary 0001 0111
	FunctionCodeChangePassword            = 0x18 // binary 0001 1000
	FunctionCodeClearMaximumDemand        = 0x19 // binary 0001 1001
	FunctionCodeClearAmmeter              = 0x1A // binary 0001 1010
	FunctionCodeClearEvent                = 0x1B // binary 0001 1011
)
View Source
const (
	ExceptionCodeRatesExceedsLimit              = 0x40 // binary 0100 0000 费率数超过限制
	ExceptionCodeDayPeriodsExceedsThreshold     = 0x20 // binary 0010 0000 日时段数超
	ExceptionCodeTimeZonesYearExceedsThreshold  = 0x10 // binary 0001 0000 年时区数超
	ExceptionCodeCommunicationRateCannotChanged = 0x08 // binary 0000 1000 通讯速率不能更改
	ExceptionCodeIllegalPassword                = 0x04 // binary 0000 0100 密码错误或者没有权限
	ExceptionCodeRequestWithoutData             = 0x02 // binary 0000 0010 请求无数据
	ExceptionCodeOtherError                     = 0x01 // binary 0000 0001 其他错误
)
View Source
const (
	FrameHead = 0x68
	FrameTail = 0x16
)
View Source
const (
	BroadcastAddressDomain = 0x999999999999
)

Variables

This section is empty.

Functions

func Reverse

func Reverse(s interface{})

Reverse reverses the elements of s in place.

Types

type Client

type Client interface {
	// read data
	ReadData(dataMarker uint32, blockQuantity uint8, year, month, day, hour, minute uint8) (results []byte, err error)
	// write data
	WriteData(dataMarker uint32, passwordPermission uint8, password uint32, operatorCode uint32, data []byte) (results []byte, err error)
	// read communication address
	ReadCommunicationAddress() (results []byte, err error)
	// write communication address
	WriteCommunicationAddress(commAddr uint64) (results []byte, err error)
	// broadcast timing
	BroadcastTiming(year, month, day, hour, minute, second uint8) (err error)
	// freeze command
	FreezeCommand(month, day, hour, minute uint8) (results []byte, err error)
	// change communication speed
	ChangeCommunicationRate(Word uint8) (results []byte, err error)
	// change password
	ChangePassword(dataMarker uint32, oldPasswordPermission uint8, oldPassword uint32, newPasswordPermission uint8, newPassword uint32) (results []byte, err error)
	// Clear the maximum demand
	ClearMaximumDemand(passwordPermission uint8, password uint32, operatorCode uint32) (results []byte, err error)
	// Clear the ammeter
	ClearAmmeter(passwordPermission uint8, password uint32, operatorCode uint32) (results []byte, err error)
	// Clear the event
	ClearEvent(dataMarker uint32, passwordPermission uint8, password uint32, operatorCode uint32) (results []byte, err error)
}

func Client2007

func Client2007(address string) Client

func NewClient

func NewClient(handler ClientHandler) Client

type Client2007Handler

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

func NewClient2007Handler

func NewClient2007Handler(address string) *Client2007Handler

func (*Client2007Handler) Decode

func (dlt *Client2007Handler) Decode(raw []byte) (payload *FramePayLoad, err error)

Decode a DTL645-2007 frame:

StartSymbol : 1 byte Address : 6 byte StartSymbol2 : 1 byte ControlCode : 1 byte DataLen : 1 byte Data : n byte CheckSUm : 1 byte EndSymbol : 1 byte

func (*Client2007Handler) Encode

func (dtl *Client2007Handler) Encode(frame *FramePayLoad) (raw []byte, err error)

Encode encodes a DTL645-2007 frame:

StartSymbol : 1 byte Address : 6 byte StartSymbol2 : 1 byte ControlCode : 1 byte DataLen : 1 byte Data : n byte CheckSUm : 1 byte EndSymbol : 1 byte

func (*Client2007Handler) ProcessPacket

func (dlt *Client2007Handler) ProcessPacket(data []byte) (result []byte, err error)

func (*Client2007Handler) Send

func (dlt *Client2007Handler) Send(request []byte) (response []byte, err error)

func (*Client2007Handler) SendNotResponse

func (dlt *Client2007Handler) SendNotResponse(request []byte) (err error)

func (*Client2007Handler) Verify

func (dlt *Client2007Handler) Verify(request []byte, response []byte) (err error)

verify verifies response length and slave id.

StartSymbol : 1 byte Address : 6 byte StartSymbol2 : 1 byte ControlCode : 1 byte DataLen : 1 byte Data : n byte CheckSUm : 1 byte EndSymbol : 1 byte

type ClientHandler

type ClientHandler interface {
	Packager
	Transporter
}

type DltError

type DltError struct {
	FunctionCode  byte
	ExceptionCode byte
}

DLTError implements error interface

func (*DltError) Error

func (e *DltError) Error() string

Error converts known dlt645 exception code to error message

type FramePayLoad

type FramePayLoad struct {
	HasFollowUpData bool
	FunctionCode    byte
	Data            []byte
}

controlCode 8 bit : 0 master send 1 slave send 7 biy : 0 slave ok 1 slave err 6 bit : 0 have not follow-up data 1 have follow-up data 1-5 bit : function code

type Packager

type Packager interface {
	Encode(frame *FramePayLoad) (adu []byte, err error)
	Decode(adu []byte) (frame *FramePayLoad, err error)
	Verify(aduRequest []byte, aduResponse []byte) (err error)
}

Packager specifies the communication layer.

type Transporter

type Transporter interface {
	Send(request []byte) (response []byte, err error)
	SendNotResponse(request []byte) (err error)
}

Transporter specifies the transport layer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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