modbus

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2025 License: MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	FuncCodeReadCoils              = 1
	FuncCodeReadDiscreteInputs     = 2
	FuncCodeReadHoldingRegisters   = 3
	FuncCodeReadInputRegisters     = 4
	FuncCodeWriteSingleCoil        = 5
	FuncCodeWriteSingleRegister    = 6
	FuncCodeWriteMultipleCoils     = 15
	FuncCodeWriteMultipleRegisters = 16
)
View Source
const (
	AddressBroadCast = 0
	AddressMin       = 1
	AddressMax       = 247

	// Bits
	WriteRegQuantityMin = 1   // 1
	WriteRegQuantityMax = 123 // 0x007b
)

proto address limit.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {

	//发送前延迟 默认 100ms
	DelayRtsBeforeSend time.Duration

	BaudRate int

	// 默认延时倍数
	DefaultDelayReadTimes int64
	// 读操作每一个地址的延时倍数
	DelayReadTimes map[uint]int64
	// contains filtered or unexported fields
}

func NewClient

func NewClient(c *serial.Config) (*Client, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) EnableLog

func (c *Client) EnableLog()

开启log

func (*Client) GetDelayTimes added in v0.0.9

func (c *Client) GetDelayTimes(address uint) int64

func (*Client) Printf added in v0.0.6

func (c *Client) Printf(format string, v ...interface{})

日志打印

func (*Client) ReadCoils

func (c *Client) ReadCoils(slaveID byte, address, quantity uint16) (results []byte, err error)

ReadCoils读取远程设备中线圈的1到2000个连续状态,并返回线圈状态。

func (*Client) ReadDiscreteInputs

func (c *Client) ReadDiscreteInputs(slaveID byte, address, quantity uint16) (results []byte, err error)

ReadDiscreteInputs 读取从1到2000连续状态的远程设备中的离散输入,并返回输入状态.

func (*Client) ReadHoldingRegisters

func (c *Client) ReadHoldingRegisters(slaveID byte, address, quantity uint16) (results []uint16, err error)

ReadHoldingRegisters 读取远程设备中连续的保持寄存器块的内容,并返回寄存器值。

func (*Client) ReadInputRegisters added in v0.1.2

func (c *Client) ReadInputRegisters(slaveID byte, address, quantity uint16) (results []uint16, err error)

Request:

Function code         : 1 byte (0x04)
Starting address      : 2 bytes
Quantity of registers : 2 bytes

Response:

Function code         : 1 byte (0x04)
Byte count            : 1 byte
Input registers       : N bytes

func (*Client) Reconnect

func (c *Client) Reconnect() error

重新连接

func (*Client) Send

func (c *Client) Send(data []byte) ([]byte, error)

发送

func (*Client) WriteMultipleRegistersBytes added in v0.0.7

func (c *Client) WriteMultipleRegistersBytes(slaveID byte, address, quantity uint16, value []byte) error

Request:

Slave Id              : 1 byte
Function code         : 1 byte (0x10)
Starting address      : 2 bytes
Quantity of outputs   : 2 bytes
Byte count            : 1 byte
Registers value       : N* bytes

Response:

Function code         : 1 byte (0x10)
Starting address      : 2 bytes
Quantity of registers : 2 bytes

func (*Client) WriteSingleCoil

func (c *Client) WriteSingleCoil(slaveID byte, address uint16, isOn bool) error

WriteSingleCoil 在远程设备中将单个输出写入ON或OFF,并返回成功或失败。

func (*Client) WriteSingleRegister

func (c *Client) WriteSingleRegister(slaveID byte, address, value uint16) error

WriteSingleRegister 在远程设备中写入单个保留寄存器,并返回成功或失败。

type ProtocolDataUnit added in v0.0.7

type ProtocolDataUnit struct {
	FuncCode byte
	Data     []byte
}

ProtocolDataUnit (PDU) is independent of underlying communication layers.

Jump to

Keyboard shortcuts

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