command

package
v0.0.0-...-00fb2c7 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package command provides communication patterns for Goodwe inverters using the Modbus protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Send

func Send(cmd Command, conn Conn) ([]byte, error)

Send writes the command to the provided Writer, and reads and validates the response.

Types

type AA55Command

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

func NewAA55

func NewAA55(payload, responseType string) (*AA55Command, error)

func (AA55Command) String

func (cmd AA55Command) String() string

func (AA55Command) ValidateResponse

func (cmd AA55Command) ValidateResponse(p []byte) ([]byte, error)

type Command

type Command interface {
	String() string
	ValidateResponse([]byte) ([]byte, error)
}

type Conn

type Conn interface {
	io.ReadWriter
	SetDeadline(time.Time) error
}

type FailureCode

type FailureCode byte
const (
	FailureCodeIllegalFunction FailureCode = iota + 1
	FailureCodeIllegalDataAddress
	FailureCodeIllegalDataValue
	FailureCodeSlaveDeviceFailure
	FailureCodeAcknowledge
	FailureCodeSlaveDeviceBusy
	FailureCodeNegativeAcknowledgement
	FailureCodeMemoryParityError
	FailureCodeGatewayPathUnavailable
	FailureCodeGatewayTargetDeviceFailedToRespond
)

func (FailureCode) String

func (i FailureCode) String() string

type ModbusCommand

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

func NewModbus

func NewModbus(commandType ModbusCommandType, offset uint16, value uint16) *ModbusCommand

func (ModbusCommand) String

func (cmd ModbusCommand) String() string

func (ModbusCommand) ValidateResponse

func (cmd ModbusCommand) ValidateResponse(p []byte) ([]byte, error)

ValidateResponse validates the entire response and if valid returns the response body.

type ModbusCommandType

type ModbusCommandType byte
const (
	ModbusCommandTypeRead ModbusCommandType = 0x03
	// TODO: implement write commands.
	ModbusCommandTypeWrite      ModbusCommandType = 0x06
	ModbusCommandTypeWriteMulti ModbusCommandType = 0x10
)

Jump to

Keyboard shortcuts

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