testutil

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StartASCIISimulator

func StartASCIISimulator(t *testing.T, opts ...ASCIISimulatorOption) (cleanup func(), devicePath string)

StartASCIISimulator creates and starts an ASCII Modbus simulator for testing. It returns a cleanup function that should be deferred, and the device path that clients should use to connect.

func StartRTUSimulator

func StartRTUSimulator(t *testing.T, opts ...RTUSimulatorOption) (cleanup func(), devicePath string)

StartRTUSimulator creates and starts an RTU Modbus simulator for testing. It returns a cleanup function that should be deferred, and the device path that clients should use to connect.

Example usage:

cleanup, devicePath := testutil.StartRTUSimulator(t,
    testutil.WithSlaveID(17),
    testutil.WithBaudRate(19200))
defer cleanup()

client := modbus.NewRTUClientHandler(devicePath)
// ... use client ...

func StartTCPSimulator

func StartTCPSimulator(t *testing.T, opts ...TCPSimulatorOption) (cleanup func(), address string)

StartTCPSimulator creates and starts a TCP Modbus simulator for testing. It returns a cleanup function that should be deferred, and the address that clients should use to connect.

Types

type ASCIISimulatorOption

type ASCIISimulatorOption func(*asciiSimulatorConfig)

ASCIISimulatorOption configures an ASCII simulator.

func WithASCIIBaudRate

func WithASCIIBaudRate(rate int) ASCIISimulatorOption

WithASCIIBaudRate sets the baud rate for the ASCII simulator.

func WithASCIIDataStoreConfig

func WithASCIIDataStoreConfig(config *simulator.DataStoreConfig) ASCIISimulatorOption

WithASCIIDataStoreConfig sets initial data values for the ASCII simulator.

func WithASCIISlaveID

func WithASCIISlaveID(id byte) ASCIISimulatorOption

WithASCIISlaveID sets the slave ID for the ASCII simulator.

type RTUSimulatorOption

type RTUSimulatorOption func(*rtuSimulatorConfig)

RTUSimulatorOption configures an RTU simulator.

func WithBaudRate

func WithBaudRate(rate int) RTUSimulatorOption

WithBaudRate sets the baud rate for the simulator.

func WithDataStoreConfig

func WithDataStoreConfig(config *simulator.DataStoreConfig) RTUSimulatorOption

WithDataStoreConfig sets initial data values for the simulator.

func WithSlaveID

func WithSlaveID(id byte) RTUSimulatorOption

WithSlaveID sets the slave ID for the simulator.

type TCPSimulatorOption

type TCPSimulatorOption func(*tcpSimulatorConfig)

TCPSimulatorOption configures a TCP simulator.

func WithTCPAddress

func WithTCPAddress(address string) TCPSimulatorOption

WithTCPAddress sets the TCP address for the simulator.

func WithTCPDataStoreConfig

func WithTCPDataStoreConfig(config *simulator.DataStoreConfig) TCPSimulatorOption

WithTCPDataStoreConfig sets initial data values for the TCP simulator.

Jump to

Keyboard shortcuts

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