protocol

package
v0.1.93 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MODBUS_HEADER_LENGTH = 7

	// MODBUS_Maximum_Number_Of_Registers is maximum number of registers that can be read in one request, a modbus message is limit to 256 bytes
	// TODO: this should be checked when register groups are created
	MODBUS_MAXIMUM_NUMBER_OF_REGISTERS = 125
	MODBUS_MAXIMUM_NUMBER_OF_COILS     = 2000
)
View Source
const (
	// 01 (0x01) Read Coils
	READ_COILS = 0x01
	// 02 (0x02) Read Discrete Inputs
	READ_DISCRETE_INPUTS = 0x02
	// 03 (0x03) Read Holding Registers
	READ_HOLDING_REGISTERS = 0x03
	// 04 (0x04) Read Input Registers
	READ_INPUT_REGISTERS = 0x04
	// 05 (0x05) Write Single Coil
	WRITE_SINGLE_COIL = 0x05
	// 06 (0x06) Write Single Register
	WRITE_SINGLE_REGISTER = 0x06
	// 08 (0x08) Diagnostics (Serial Line only)
	DIAGNOSTICS = 0x08
	// 11 (0x0B) Get Comm Event Counter (Serial Line only)
	GET_COMM_EVENT_COUNTER = 0x0B
	// 15 (0x0F) Write Multiple Coils
	WRITE_MULTIPLE_COILS = 0x0F
	// 16 (0x10) Write Multiple Registers
	WRITE_MULTIPLE_REGISTERS = 0x10
	// 17 (0x11) Report Server ID (Serial Line only)
	REPORT_SERVER_ID = 0x11
	// 22 (0x16) Mask Write Register
	MASK_WRITE_REGISTERS = 0x16
	// 23 (0x17) Read/Write Multiple Registers
	READ_WRITE_MULTIPLE_REGISTERS = 0x17
	// 43 / 14 (0x2B / 0x0E) Read Device Identification
	READ_DEVICE_IDENTIFICATION_A = 0x0E
	READ_DEVICE_IDENTIFICATION_B = 0x43
)

Variables

This section is empty.

Functions

func BytesToCoils

func BytesToCoils(bytes []byte) ([]bool, error)

func BytesToRegisters

func BytesToRegisters(bytes []byte) ([]uint16, error)

func CoilsToBytes

func CoilsToBytes(values []bool) []byte

func CoilsToRegisters

func CoilsToRegisters(coils []bool) []uint16

func InjectModbusHeader

func InjectModbusHeader(header *ModbusHeader, bytes []byte) []byte

func RegistersToBytes

func RegistersToBytes(values []uint16) []byte

func RegistersToCoils

func RegistersToCoils(registers []uint16) []bool

Types

type ModbusClient

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

func NewModbusClient

func NewModbusClient(realClient *modbus.ModbusClient, header *ModbusHeader) *ModbusClient

func (*ModbusClient) Poll

func (m *ModbusClient) Poll(stream chan<- []byte, pollingInterval time.Duration) error

func (*ModbusClient) Read

func (m *ModbusClient) Read(bytes []byte) (n int, err error)

func (*ModbusClient) Write

func (m *ModbusClient) Write(bytes []byte) (n int, err error)

type ModbusHeader

type ModbusHeader struct {
	Slave                    uint8  `mapstructure:"slave"`
	FunctionCode             uint16 `mapstructure:"functionCode"`
	Address                  uint16 `mapstructure:"address"`
	NumberOfCoilsOrRegisters uint16 `mapstructure:"numberOfCoilsOrRegisters"`
}

func ExtractModbusHeader

func ExtractModbusHeader(bytes []byte) (*ModbusHeader, []byte, error)

Jump to

Keyboard shortcuts

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