mbserver

package
v0.5.42 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToFloat32

func BytesToFloat32(bytes []byte) float32

BytesToFloat32 converts a big endian array of bytes to an array of float32

func BytesToUint16

func BytesToUint16(bytes []byte) []uint16

BytesToUint16 converts a big endian array of bytes to an array of unit16s

func BytesToUint32

func BytesToUint32(bytes []byte) []uint32

BytesToUint32 converts a big endian array of bytes to an array of unit32s

func CrcModbus

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

func DecodeFloat32s

func DecodeFloat32s(bytes *[]byte, num uint) (vals []float32, err error)

func DecodeUint16s

func DecodeUint16s(bytes *[]byte, num uint) (vals []uint16, err error)

func DecodeUint32s

func DecodeUint32s(bytes *[]byte, num uint) (vals []uint32, err error)

func EncodeFloat32

func EncodeFloat32(bytes *[]byte, value float32)

func EncodeUint16

func EncodeUint16(bytes *[]byte, value uint16)

func EncodeUint32

func EncodeUint32(bytes *[]byte, value uint32)

func Float32ToBytes

func Float32ToBytes(value float32) []byte

Float32ToBytes converts an array of float32 to a big endian array of bytes

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)

仅用于遥控操作寄存器

func Uint16ToBytes

func Uint16ToBytes(values []uint16) []byte

Uint16ToBytes converts an array of uint16s to a big endian array of bytes

func Uint32ToBytes

func Uint32ToBytes(values []uint32) []byte

Uint32ToBytes converts an array of uint32s to a big endian array of bytes

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
	Bytes2() []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 NewRTUFrame2 added in v0.5.29

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

NewRTUFrame converts a packet to a Modbus RTU frame. CRC校验使用大端模式

func (*RTUFrame) Bytes

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

Bytes returns the Modbus byte stream based on the RTUFrame fields

func (*RTUFrame) Bytes2 added in v0.5.28

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

Bytes returns the Modbus byte stream based on the RTUFrame fields CRC校验使用大端模式

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