message

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EOL is a CRLF.
	EOL = "\r\n"
	// A Prompt is emitted on each line of output.
	Prompt = '>'
)

Variables

View Source
var (
	CommandMachineSN         = Int64(100)
	CommandControlVersion    = Int64(101)
	CommandMachineModel      = Int64(102)
	CommandMode              = Int64(104)
	CommandToolChanges       = Int64(200)
	CommandToolNumber        = Int64(201)
	CommandPowerOnTime       = Int64(300)
	CommandMotionTime        = Int64(301)
	CommandLastCycleTime     = Int64(303)
	CommandPreviousCycleTime = Int64(304)
	CommandPartsCounter1     = Int64(402)
	CommandPartsCounter2     = Int64(403)
	CommandThreeInOne        = Int64(500)
	CommandMacroVariable     = Int64(600)
)

These basic commands are defined in Haas Mill Operator's Manual.

Functions

func ScanPrompt added in v0.2.1

func ScanPrompt(data []byte, atEOF bool) (int, []byte, error)

ScanPrompt is a bufio.ScanFunc that reads each line of text and strips any Prompt prefix characters.

func WritePrompt added in v0.2.1

func WritePrompt(w WriteFlusher) error

WritePrompt writes a prompt to the output and then flushes it.

func WriteResponse added in v0.2.1

func WriteResponse(w WriteFlusher, format string, args ...any) error

WriteResponse writes a complete response message line to the output, followed by a new prompt, and flushes.

Types

type Message

type Message interface {
	fmt.Stringer
	slog.LogValuer

	Buffer() ([]byte, bool)
	Command() (Number, bool)
	Value() (Number, bool)
	Variable() (Number, bool)

	// IsSafe returns true if the message is unlikely to cause damage to the MDC
	// receiver.
	IsSafe() bool

	// IsWrite returns true if the message writes to a remote variable.
	IsWrite() bool

	// WriteTo implements [io.WriterTo].
	WriteTo(out io.Writer) (int64, error)
	// contains filtered or unexported methods
}

A Message is a Machine Data Collection message.

func Basic

func Basic(n Number) Message

A Basic query message with no parameters.

func Parse

func Parse(bytes []byte) (Message, error)

Parse the input as a Message.

func Query

func Query(n Number) Message

Query a macro variable number.

func Response

func Response(data []byte) Message

A Response to an MDC command.

func Write

func Write(target, value Number) Message

Write to a macro variable.

type Number

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

A Number represents a fixed-point decimal value.

func Int64

func Int64(i int64) Number

Int64 returns the integer as a parsed Number.

func NewNumber

func NewNumber(whole, frac int64) Number

NewNumber constructs a number with a whole and fractional part.

func ParseNumber

func ParseNumber(buf []byte) (Number, error)

ParseNumber validates the input is numeric.

func (Number) Format

func (n Number) Format(state fmt.State, verb rune)

Format implements io.Formatter.

func (Number) Frac

func (n Number) Frac() int64

Frac returns the fractional portion of the Number.

func (Number) LogValue

func (n Number) LogValue() slog.Value

LogValue implements slog.LogValuer.

func (Number) String

func (n Number) String() string

String is for debugging use only.

func (Number) Whole

func (n Number) Whole() int64

Whole returns the whole portion of the Number.

type WriteFlusher added in v0.2.1

type WriteFlusher interface {
	io.Writer
	Flush() error
}

WriteFlusher is implemented by bufio.Writer, for example.

Jump to

Keyboard shortcuts

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