UNPKG

@thi.ng/axidraw

Version:

Minimal AxiDraw plotter/drawing machine controller for Node.js

37 lines (36 loc) 707 B
import { illegalState } from "@thi.ng/errors/illegal-state"; import { SerialPort } from "serialport"; const SERIAL_PORT = { list: () => SerialPort.list(), ctor: (path, baudRate) => new SerialPort({ path, baudRate }) }; const MOCK_SERIAL = { list: async (path) => [{ path }], ctor: () => new MockSerial() }; class MockSerial { sent = []; isClosed = false; /** * Clears internal log of "sent" message. */ clear() { this.sent = []; } close() { this.isClosed = true; } /** * Appends * @param msg */ write(msg) { this.isClosed && illegalState("connection already closed"); this.sent.push(msg); } } export { MOCK_SERIAL, MockSerial, SERIAL_PORT };