Laseryx includes a powerful Virtual Machine (Virtual GRBL Driver) that simulates a physical laser cutter in software. This allows developers to test G-code generation, streaming logic, and machine control workflows without connecting to hardware.
- G-code Simulation: Parses and executes
G0,G1,M3,M5,$H, and other standard commands. - State Tracking: Maintains real-time
MPos(Machine Position) andWPos(Work Position). - Alarm Simulation: Correctly enters
ALARMstate on errors or aborts. - Headless Mode: Can be run entirely in Node.js for integration testing (see
src/io/virtualMachine.test.ts).
You can enable the Virtual Machine in the PWA Development build in two ways:
-
URL Parameter: Append
?virtual=trueto the URL.http://localhost:5173/?virtual=true -
Machine Panel: In the "Machine" tab, look for the "Use Virtual Machine" checkbox at the top (only visible in
DEVmode).
Once enabled:
- Click Connect. The status should turn green (
IDLE). - Use the Jog Controls to move the virtual laser. You will see coordinates update.
- Run a Job: Generate G-code in the Design tab and click "Start Job". The virtual machine will stream the job, simulating movement delay.
You can instantiate the VirtualGrblDriver directly in tests:
import { createVirtualGrblDriver } from './grblDriver';
const driver = createVirtualGrblDriver({ responseDelayMs: 0 }); // 0ms for instant tests
await driver.connect();
await driver.sendLine('G0 X10 Y10');
const status = await driver.getStatus();
// status.mpos.x === 10The VirtualGrblDriver implements the GrblDriver interface but replaces the Web Serial I/O with an innovative state machine.
streamJob: Processes G-code lines sequentially, simulating protocolokacknowledgments.sendLine: Parses G-code immediately and updates the internalstateobject.getStatus: Returns a snapshot of the current simulatedMPos,WPos, andFeed/Speed.