modbus

package
v0.16.5 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: BSD-3-Clause, GPL-3.0 Imports: 14 Imported by: 0 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 (
	// Bit access - Single bits
	FuncReadCoils          = 0x01 // Read Coils (outputs)
	FuncReadDiscreteInputs = 0x02 // Read Discrete Inputs

	// Bit access - Multiple bits
	FuncWriteSingleCoil    = 0x05 // Write Single Coil
	FuncWriteMultipleCoils = 0x0F // Write Multiple Coils

	// 16-bit access - Single registers
	FuncReadHoldingRegisters = 0x03 // Read Holding Registers
	FuncReadInputRegisters   = 0x04 // Read Input Registers
	FuncWriteSingleRegister  = 0x06 // Write Single Register

	// 16-bit access - Multiple registers
	FuncWriteMultipleRegisters     = 0x10 // Write Multiple Registers
	FuncReadWriteMultipleRegisters = 0x17 // Read/Write Multiple Registers
	FuncMaskWriteRegister          = 0x16 // Mask Write Register
	FuncReadFIFOQueue              = 0x18 // Read FIFO Queue

	// File record access
	FuncReadFileRecord  = 0x14 // Read File Record
	FuncWriteFileRecord = 0x15 // Write File Record

	// Diagnostics
	FuncReadExceptionStatus   = 0x07 // Read Exception Status
	FuncDiagnostic            = 0x08 // Diagnostic
	FuncGetCommEventCounter   = 0x0B // Get Comm Event Counter
	FuncGetCommEventLog       = 0x0C // Get Comm Event Log
	FuncReportSlaveID         = 0x11 // Report Slave ID
	FuncEncapsulatedInterface = 0x2B // Encapsulated Interface Transport (includes Read Device Identification)

)

Modbus Function Codes (standard functions per Modbus Application Protocol Specification V1.1b3)

View Source
const (
	DiagReturnQueryData                = 0x00
	DiagRestartCommunications          = 0x01
	DiagReturnDiagnosticRegister       = 0x02
	DiagChangeASCIIInputDelimiter      = 0x03
	DiagForceListenOnlyMode            = 0x04
	DiagClearCountersAndDiagnosticReg  = 0x0A
	DiagReturnBusMessageCount          = 0x0B
	DiagReturnBusCommunicationError    = 0x0C
	DiagReturnBusExceptionErrorCount   = 0x0D
	DiagReturnSlaveMessageCount        = 0x0E
	DiagReturnSlaveNoResponseCount     = 0x0F
	DiagReturnSlaveNAKCount            = 0x10
	DiagReturnSlaveBusyCount           = 0x11
	DiagReturnBusCharacterOverrunCount = 0x12
	DiagClearOverrunCounter            = 0x14
)

Diagnostic sub-function codes

View Source
const (
	ExceptionIllegalFunction         = 0x01
	ExceptionIllegalDataAddress      = 0x02
	ExceptionIllegalDataValue        = 0x03
	ExceptionSlaveDeviceFailure      = 0x04
	ExceptionAcknowledge             = 0x05
	ExceptionSlaveDeviceBusy         = 0x06
	ExceptionNegativeAcknowledge     = 0x07
	ExceptionMemoryParityError       = 0x08
	ExceptionGatewayPathUnavailable  = 0x0A
	ExceptionGatewayTargetNoResponse = 0x0B
)

Exception codes

Variables

View Source
var Decoder = &decoder.StreamDecoder{
	Type:        types.Type_NC_Modbus,
	Name:        serviceModbus,
	Description: "Modbus is a serial communications protocol for ICS/SCADA PLCs and industrial devices",
	PostInit: func(d *decoder.StreamDecoder) error {
		var err error
		modbusLog, _, err = logging.InitZapLogger(
			decoderconfig.Instance.Out,
			"modbus",
			decoderconfig.Instance.Debug,
		)
		return err
	},

	Specificity: core.SpecificityValidated,

	CanDecode: func(client, server []byte) bool {

		return canDecodeModbus(client) || canDecodeModbus(server)
	},
	DeInit: func(sd *decoder.StreamDecoder) error {
		return modbusLog.Sync()
	},
	Factory: &modbusReader{},
	Typ:     core.TCP,
}

Decoder for protocol analysis and writing audit records to disk.

Functions

func GetExceptionCodeName

func GetExceptionCodeName(code uint8) string

GetExceptionCodeName returns the human-readable name for a Modbus exception code.

func GetFunctionCodeName

func GetFunctionCodeName(code uint8) string

GetFunctionCodeName returns the human-readable name for a Modbus function code.

func IsCriticalFunction

func IsCriticalFunction(code uint8) bool

IsCriticalFunction returns true if the function code is a write operation.

func IsDiagnosticFunction

func IsDiagnosticFunction(code uint8) bool

IsDiagnosticFunction returns true if the function code is a diagnostic operation.

func IsRTUConversation

func IsRTUConversation(c *core.ConversationInfo) bool

IsRTUConversation selects only explicitly configured destination endpoints. A capture without initialization may have its transport directions reversed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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