feat: 动态载入node-serialport和node-usb避免nwjs下server异常

This commit is contained in:
王立帮
2025-05-22 22:14:02 +08:00
parent 8de021439e
commit 958413b03a
15 changed files with 251 additions and 40 deletions

View File

@@ -1,12 +1,17 @@
import { exec } from 'node:child_process';
import {
SerialPort,
ReadlineParser,
ByteLengthParser
} from 'serialport';
import _ from 'lodash';
import EventsBase from './events-base.js';
import { CURRENT_PLANTFORM } from './config.js';
import { CURRENT_PLANTFORM, SERVER_MODE } from './config.js';
let SerialPort, ReadlineParser, ByteLengthParser;
if (SERVER_MODE === 'all') {
const serial = await import('serialport');
SerialPort = serial.SerialPort;
ReadlineParser = serial.ReadlineParser;
ByteLengthParser = serial.ByteLengthParser;
}
export default class Serial extends EventsBase {