mbserver

package
v0.5.51 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Read    = uint8(0x03)
	Write   = uint8(0x10)
	Control = uint8(0x05)
)

Variables

View Source
var BigEndian bigEndian

BigEndian is the big-endian implementation of ByteOrder.

View Source
var LittleEndian littleEndian

LittleEndian is the little-endian implementation of ByteOrder.

Functions

func CRCModbus added in v0.5.43

func CRCModbus(data []byte) (crc uint16)

func GetRegister added in v0.5.42

func GetRegister(frame Framer) uint16

获取读取响应的寄存器地址

func SetDataWithRegisterAndNumber

func SetDataWithRegisterAndNumber(frame Framer, register uint16, number uint16)

用于读寄存器 SetDataWithRegisterAndNumber sets the RTUFrame Data byte field to hold a register and number of registers

func SetDataWithRegisterAndNumberAndBytes

func SetDataWithRegisterAndNumberAndBytes(frame Framer, register uint16, number uint16, bytes []byte)

仅用于写寄存器 SetDataWithRegisterAndNumberAndBytes sets the TCPFrame Data byte field to hold a register and number of registers and coil bytes

func SetDataWithRegisterAndNumberAndValues

func SetDataWithRegisterAndNumberAndValues(frame Framer, register uint16, number uint16, values []uint16)

仅用于写寄存器,并且要求寄存器值类型为uint16 SetDataWithRegisterAndNumberAndValues sets the TCPFrame Data byte field to hold a register and number of registers and values

func SetDateForControl added in v0.5.40

func SetDateForControl(frame Framer, register uint16, value uint16)

仅用于遥控操作寄存器

Types

type Exception

type Exception uint8

Exception codes.

var (
	// Success operation successful.
	Success Exception
	// IllegalFunction function code received in the query is not recognized or allowed by slave.
	IllegalFunction Exception = 1
	// IllegalDataAddress data address of some or all the required entities are not allowed or do not exist in slave.
	IllegalDataAddress Exception = 2
	// IllegalDataValue value is not accepted by slave.
	IllegalDataValue Exception = 3
	// SlaveDeviceFailure Unrecoverable error occurred while slave was attempting to perform requested action.
	SlaveDeviceFailure Exception = 4
	// AcknowledgeSlave has accepted request and is processing it, but a long duration of time is required. This response is returned to prevent a timeout error from occurring in the master. Master can next issue a Poll Program Complete message to determine whether processing is completed.
	AcknowledgeSlave Exception = 5
	// SlaveDeviceBusy is engaged in processing a long-duration command. Master should retry later.
	SlaveDeviceBusy Exception = 6
	// NegativeAcknowledge Slave cannot perform the programming functions. Master should request diagnostic or error information from slave.
	NegativeAcknowledge Exception = 7
	// MemoryParityError Slave detected a parity error in memory. Master can retry the request, but service may be required on the slave device.
	MemoryParityError Exception = 8
	// GatewayPathUnavailable Specialized for Modbus gateways. Indicates a misconfigured gateway.
	GatewayPathUnavailable Exception = 10
	// GatewayTargetDeviceFailedtoRespond Specialized for Modbus gateways. Sent when slave fails to respond.
	GatewayTargetDeviceFailedtoRespond Exception = 11
)

func GetException

func GetException(frame Framer) (exception Exception)

GetException retunrns the Modbus exception or Success (indicating not exception).

func (Exception) Error

func (e Exception) Error() string

func (Exception) String

func (e Exception) String() string

type Framer

type Framer interface {
	Bytes() []byte
	Copy() Framer
	GetData() []byte
	GetFunction() uint8
	SetException(exception *Exception)
	SetData(data []byte)
}

Framer is the interface that wraps Modbus frames.

type RTUFrame

type RTUFrame struct {
	Address  uint8
	Function uint8
	Data     []byte
	CRC      uint16
}

RTUFrame is the Modbus TCP frame.

func NewRTUFrame

func NewRTUFrame(packet []byte) (*RTUFrame, error)

NewRTUFrame converts a packet to a Modbus RTU frame.

func (*RTUFrame) Bytes

func (frame *RTUFrame) Bytes() []byte

Bytes returns the Modbus byte stream based on the RTUFrame fields

func (*RTUFrame) Copy

func (frame *RTUFrame) Copy() Framer

Copy the RTUFrame.

func (*RTUFrame) GetData

func (frame *RTUFrame) GetData() []byte

GetData returns the RTUFrame Data byte field.

func (*RTUFrame) GetFunction

func (frame *RTUFrame) GetFunction() uint8

GetFunction returns the Modbus function code.

func (*RTUFrame) SetData

func (frame *RTUFrame) SetData(data []byte)

SetData sets the RTUFrame Data byte field and updates the frame length accordingly.

func (*RTUFrame) SetException

func (frame *RTUFrame) SetException(exception *Exception)

SetException sets the Modbus exception code in the frame.

Jump to

Keyboard shortcuts

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