|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| ModbusModule | RunSequenceWait (sequence, user_message, device) |
| Run a Modbus PLC sequence and wait for it to complete. | |
| ModbusModule | SetSeqData (Device, Index, Val) |
| Send a data value to a PLC sequence data register on a Modbus device. | |
| ModbusModule | GetSeqData (Index) |
| Get sequence data from a Modbus PLC device by index. | |
| ModbusModule | SeqCall (Device, PrintToStatus,...) |
| Call and wait for PLC sequences to start on a Modbus device. | |
| ModbusModule | SeqCallWrapper (Device, seq_numbers) |
| Protected wrapper for starting PLC sequences with error recovery. | |
| ModbusModule | IsSeqRunning (Device, seq_number) |
| Check if a specific PLC sequence is currently running. | |
| ModbusModule | SeqWait (Device, PrintToStatus,...) |
| Wait for specified PLC sequences to complete on a device. | |
| ModbusModule | SeqWaitWrapper (Device, seq_numbers) |
| Protected wrapper for the internal sequence wait implementation. | |
| ModbusModule | SeqAllWait (Device, PrintToStatus) |
| Wait for all 64 PLC sequences on a device to complete. | |
| ModbusModule | GetBit (Device, BitWanted, Reg) |
| Get the boolean state of a specific bit in a Modbus register. | |
| ModbusModule | SetBit (Device, BitWanted, Reg) |
| Set a specific bit in a Modbus register for a device. | |
| ModbusModule | ClearBit (Device, BitWanted, Reg) |
| Clear a specific bit in a Modbus register for a device. | |
| ModbusModule | ByteSwap (Val) |
| Swap the high and low bytes of a 16-bit integer value. | |
| ModbusModule | ClearModbus (Device) |
| Clear all Modbus ContSeqCall registers for a device. | |
| ModbusModule | GetSeqDescription (PLCDevice, Seq) |
| Get the description string for a specific PLC sequence. | |
| ModbusModule | GetSeqTimeoutStatus (PLCDevice, Seq) |
| Get the timeout status of a specific PLC sequence. | |
| ModbusModule | GetAllSeqTimeoutStatus (PLCDevice) |
| Get the timeout status of all 64 PLC sequences for a device. | |
| ModbusModule | StartFunction (device, func) |
| Start a Modbus function on a device and wait for acknowledgement. | |
| ModbusModule | StopFunction (device, func) |
| Stop a running Modbus function on a device. | |
| ModbusModule ByteSwap | ( | Val | ) |
Swap the high and low bytes of a 16-bit integer value.
[[---------—BYTE SWAP-----------------—
Extracts the low byte (bits 0-7) and high byte (bits 8-15) of the input value, then recombines them with their positions swapped. Used for correcting byte-order differences between Mach4 and Modbus devices that use different byte ordering conventions.
| Val | (number) The 16-bit integer value to byte-swap. Must be in range -65535 to 65535 |
| ModbusModule ClearBit | ( | Device | , |
| BitWanted | , | ||
| Reg | ) |
Clear a specific bit in a Modbus register for a device.
[[---------—CLEAR BITS-----------------—
Reads the current value of the register word containing the target bit, optionally byte-swaps it if the device is configured for byte swapping, clears the specified bit using bitwise AND with the complement mask, reverses the byte swap if applied, then writes the result back to the register.
| Device | (number) The Modbus device index (0-7) |
| BitWanted | (number) The bit number to clear (0-1024) |
| Reg | (string) The base register name (e.g., "ContSeqCall", "PLCSeqFB") |
| ModbusModule ClearModbus | ( | Device | ) |
Clear all Modbus ContSeqCall registers for a device.
[[---------—CLEAR MODBUS-----------------—
Resets the ContSeqCall registers (indices 0-3) to 0 for the specified Modbus device. This is typically called before reporting a sequence error to ensure no stale call bits remain active in the PLC communication registers.
| Device | (number) The Modbus device index to clear (0-7) |
| ModbusModule GetAllSeqTimeoutStatus | ( | PLCDevice | ) |
Get the timeout status of all 64 PLC sequences for a device.
Iterates through all 64 possible sequence numbers (0-63) and checks each one for a timeout condition using ModbusModule.GetSeqTimeoutStatus(). Returns a table summarizing which sequences have timed out, a combined timeout message, and an overall timeout flag.
| PLCDevice | (number|nil) The PLC device index (0-7). If nil, defaults to 0 |
| ModbusModule GetBit | ( | Device | , |
| BitWanted | , | ||
| Reg | ) |
Get the boolean state of a specific bit in a Modbus register.
[[---------—GET BIT-----------------—
Reads the register word that contains the target bit for the given device, optionally byte-swaps the value if the device is configured for byte swapping, then extracts and returns the boolean state of the specified bit using bitwise operations. The word index is calculated as floor(BitWanted / 16) and the bit position within the word is BitWanted mod 16.
| Device | (number) The Modbus device index (0-7) |
| BitWanted | (number) The bit number to read (0-1024) |
| Reg | (string) The base register name (e.g., "ContSeqCall", "PLCSeqFB") |
| ModbusModule GetSeqData | ( | Index | ) |
Get sequence data from a Modbus PLC device by index.
Retrieves data from the PLC sequence data register at the specified index. This function is currently commented out in the codebase and represents legacy functionality for bidirectional sequence data exchange with the PLC.
| Index | (number) The data index to retrieve from the PLC sequence data registers (0-15) |
| ModbusModule GetSeqDescription | ( | PLCDevice | , |
| Seq | ) |
Get the description string for a specific PLC sequence.
Reads the timeout message/description for the given sequence from the Mach4 profile under the MachMotionModbusDevicePLCConfiguration section. This description is used in alarm messages to identify which sequence timed out or failed.
| PLCDevice | (number|nil) The PLC device index (0-7). If nil, defaults to 0 |
| Seq | (number) The sequence number to retrieve the description for (0-63) |
| ModbusModule GetSeqTimeoutStatus | ( | PLCDevice | , |
| Seq | ) |
Get the timeout status of a specific PLC sequence.
Checks the PLCSeqTimeOut bit for the specified sequence number on the given PLC device. Returns true if the sequence has timed out, false if it completed normally.
| PLCDevice | (number|nil) The PLC device index (0-7). If nil, defaults to 0 |
| Seq | (number) The sequence number to check (0-63) |
| ModbusModule IsSeqRunning | ( | Device | , |
| seq_number | ) |
Check if a specific PLC sequence is currently running.
Reads the PLCSeqFB bit for the given sequence number on the specified device and returns true if the feedback bit is set, indicating the sequence is active.
| Device | (number) The Modbus device index (0-7) |
| seq_number | (number) The sequence number to check (0-63) |
| ModbusModule RunSequenceWait | ( | sequence | , |
| user_message | , | ||
| device | ) |
Run a Modbus PLC sequence and wait for it to complete.
Calls mb.SeqCallWrapper() to start the specified sequence on the given device, then waits for completion. In a screen chunk context, displays a please-wait dialog that polls mb.IsSeqRunning() until the sequence finishes. In an M-code chunk context, calls mb.SeqWaitWrapper() to block until completion. If device is not provided, defaults to device 0.
| sequence | (number) The sequence number to run |
| user_message | (string|nil) Message to display in the please-wait dialog. If nil, defaults to "PLC Sequence Running..." |
| device | (number|nil) The Modbus device index. If nil, defaults to 0 |
Behavior differs based on execution context:
| ModbusModule SeqAllWait | ( | Device | , |
| PrintToStatus | ) |
Wait for all 64 PLC sequences on a device to complete.
[[---------—SEQUENCE ALL WAIT-----------------—
Builds a stack of all sequence numbers (0-63) and polls each one's PLCSeqFB bit until all sequences report as not running. If the machine is stopped or disabled during the wait, the function checks for timeout conditions and returns an appropriate error message. Optionally logs progress to the operator log when sequences are still pending.
| Device | (number) The Modbus device index (0-7) |
| PrintToStatus | (boolean) If true, logs waiting and completion messages to the operator log |
| ModbusModule SeqCall | ( | Device | , |
| PrintToStatus | , | ||
| ... ) |
Call and wait for PLC sequences to start on a Modbus device.
[[---------—SEQUENCE CALL-----------------—
Validates the device number, PLC enabled status, and machine enabled state before proceeding. Builds an argument stack from variadic inputs (accepts individual numbers or tables), verifies that no requested sequences are already running or have their call bits active, then sets the ContSeqCall bits for all requested sequences. Polls until all sequences acknowledge via their PLCSeqFB bits or a 500ms timeout occurs. Checks machine stop status and PLC timeout status throughout. Optionally logs progress to the operator log.
| Device | (number) The Modbus device index (0-7) |
| PrintToStatus | (boolean) If true, logs waiting and completion messages to the operator log |
| ... | (number|table) Sequence numbers to call, as individual numbers or tables of numbers |
| ModbusModule SeqCallWrapper | ( | Device | , |
| seq_numbers | ) |
Protected wrapper for starting PLC sequences with error recovery.
Verifies machine stop status before proceeding, then calls mb._SeqCallWrapper() inside a w.pcall() protected call. If the call fails, clears all Modbus call bits via ModbusModule.ClearModbus(), re-checks the stop status, and raises an appropriate alarm. Table-type errors are raised as alarm messages; string errors are logged via w.FunctionError().
| Device | (number) The Modbus device index (0-7) |
| seq_numbers | (number|table) A single sequence number or table of sequence numbers to call |
| ModbusModule SeqWait | ( | Device | , |
| PrintToStatus | , | ||
| ... ) |
Wait for specified PLC sequences to complete on a device.
[[---------—SEQUENCE WAIT-----------------—
Builds a stack from the variadic sequence number arguments (accepts individual numbers or tables of numbers) and polls each sequence's PLCSeqFB bit until all report as not running. Validates device number and PLC enabled status before waiting. Checks machine stop status and PLC timeout status during the wait loop. On completion, verifies no sequences are in a timed-out state before returning success.
| Device | (number) The Modbus device index (0-7) |
| PrintToStatus | (boolean) If true, logs waiting and completion messages to the operator log |
| ... | (number|table) Sequence numbers to wait for, as individual numbers or tables of numbers |
| ModbusModule SeqWaitWrapper | ( | Device | , |
| seq_numbers | ) |
Protected wrapper for the internal sequence wait implementation.
Calls mb._SeqWaitWrapper() inside a w.pcall() protected call. If the call fails, checks the machine stop status - if stopped, returns the error directly; otherwise raises an alarm message for table-type errors or logs via w.FunctionError() for string errors.
| Device | (number) The Modbus device index (0-7) |
| seq_numbers | (number|table) A single sequence number or table of sequence numbers to wait for. A value less than 1 triggers "wait all" mode. |
| ModbusModule SetBit | ( | Device | , |
| BitWanted | , | ||
| Reg | ) |
Set a specific bit in a Modbus register for a device.
[[---------—SET BITS-----------------—
Reads the current value of the register word containing the target bit, optionally byte-swaps it if the device is configured for byte swapping, sets the specified bit using bitwise OR, reverses the byte swap if applied, then writes the result back to the register.
| Device | (number) The Modbus device index (0-7) |
| BitWanted | (number) The bit number to set (0-1024) |
| Reg | (string) The base register name (e.g., "ContSeqCall", "PLCSeqFB") |
| ModbusModule SetSeqData | ( | Device | , |
| Index | , | ||
| Val | ) |
Send a data value to a PLC sequence data register on a Modbus device.
[[---------—SEND DATA-----------------—
Validates all inputs, checks that the PLC device is enabled, then writes the specified value to the ContSeqData register at the given index for the named device. The active handshaking protocol (setting/clearing ContSeqBitData and waiting for PLCSeqBitData) is currently patched out - the function writes the value directly to the register without the full handshake sequence.
| Device | (number) The Modbus device index (0-7) |
| Index | (number) The data register index to write to (0-14) |
| Val | (number) The value to write to the register (-32767 to 32767) |
| ModbusModule StartFunction | ( | device | , |
| func | ) |
Start a Modbus function on a device and wait for acknowledgement.
Sends a start command to the Modbus control register for the specified device and function, then polls the function's return code register until it reaches 0 (indicating the function started successfully) or a 1000ms timeout expires. If the function does not start within the timeout, an error is raised via w.Error().
| device | (string) The device name to send the start command to |
| func | (string) The function name to start on the device |
References func().
| ModbusModule StopFunction | ( | device | , |
| func | ) |
Stop a running Modbus function on a device.
Sends a stop command to the Modbus control register for the specified device and function. This is a fire-and-forget operation with no confirmation that the function actually stopped.
| device | (string) The device name to send the stop command to |
| func | (string) The function name to stop on the device |
References func().