Initial commit
This commit is contained in:
39
node_modules/@serialport/bindings-cpp/dist/darwin.d.ts
generated
vendored
Normal file
39
node_modules/@serialport/bindings-cpp/dist/darwin.d.ts
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
/// <reference types="node" />
|
||||
import { BindingPortInterface } from '.';
|
||||
import { BindingInterface, OpenOptions, PortStatus, SetOptions, UpdateOptions } from '@serialport/bindings-interface';
|
||||
import { Poller } from './poller';
|
||||
export interface DarwinOpenOptions extends OpenOptions {
|
||||
/** Defaults to none */
|
||||
parity?: 'none' | 'even' | 'odd';
|
||||
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 1 */
|
||||
vmin?: number;
|
||||
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 0 */
|
||||
vtime?: number;
|
||||
}
|
||||
export type DarwinBindingInterface = BindingInterface<DarwinPortBinding, DarwinOpenOptions>;
|
||||
export declare const DarwinBinding: DarwinBindingInterface;
|
||||
/**
|
||||
* The Darwin binding layer for OSX
|
||||
*/
|
||||
export declare class DarwinPortBinding implements BindingPortInterface {
|
||||
readonly openOptions: Required<DarwinOpenOptions>;
|
||||
readonly poller: Poller;
|
||||
private writeOperation;
|
||||
fd: null | number;
|
||||
constructor(fd: number, options: Required<DarwinOpenOptions>);
|
||||
get isOpen(): boolean;
|
||||
close(): Promise<void>;
|
||||
read(buffer: Buffer, offset: number, length: number): Promise<{
|
||||
buffer: Buffer;
|
||||
bytesRead: number;
|
||||
}>;
|
||||
write(buffer: Buffer): Promise<void>;
|
||||
update(options: UpdateOptions): Promise<void>;
|
||||
set(options: SetOptions): Promise<void>;
|
||||
get(): Promise<PortStatus>;
|
||||
getBaudRate(): Promise<{
|
||||
baudRate: number;
|
||||
}>;
|
||||
flush(): Promise<void>;
|
||||
drain(): Promise<void>;
|
||||
}
|
||||
148
node_modules/@serialport/bindings-cpp/dist/darwin.js
generated
vendored
Normal file
148
node_modules/@serialport/bindings-cpp/dist/darwin.js
generated
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DarwinPortBinding = exports.DarwinBinding = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const load_bindings_1 = require("./load-bindings");
|
||||
const poller_1 = require("./poller");
|
||||
const unix_read_1 = require("./unix-read");
|
||||
const unix_write_1 = require("./unix-write");
|
||||
const debug = (0, debug_1.default)('serialport/bindings-cpp');
|
||||
exports.DarwinBinding = {
|
||||
list() {
|
||||
debug('list');
|
||||
return (0, load_bindings_1.asyncList)();
|
||||
},
|
||||
async open(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
if (!options.path) {
|
||||
throw new TypeError('"path" is not a valid port');
|
||||
}
|
||||
if (!options.baudRate) {
|
||||
throw new TypeError('"baudRate" is not a valid baudRate');
|
||||
}
|
||||
debug('open');
|
||||
const openOptions = Object.assign({ vmin: 1, vtime: 0, dataBits: 8, lock: true, stopBits: 1, parity: 'none', rtscts: false, xon: false, xoff: false, xany: false, hupcl: true }, options);
|
||||
const fd = await (0, load_bindings_1.asyncOpen)(openOptions.path, openOptions);
|
||||
return new DarwinPortBinding(fd, openOptions);
|
||||
},
|
||||
};
|
||||
/**
|
||||
* The Darwin binding layer for OSX
|
||||
*/
|
||||
class DarwinPortBinding {
|
||||
constructor(fd, options) {
|
||||
this.fd = fd;
|
||||
this.openOptions = options;
|
||||
this.poller = new poller_1.Poller(fd);
|
||||
this.writeOperation = null;
|
||||
}
|
||||
get isOpen() {
|
||||
return this.fd !== null;
|
||||
}
|
||||
async close() {
|
||||
debug('close');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
const fd = this.fd;
|
||||
this.poller.stop();
|
||||
this.poller.destroy();
|
||||
this.fd = null;
|
||||
await (0, load_bindings_1.asyncClose)(fd);
|
||||
}
|
||||
async read(buffer, offset, length) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
if (typeof offset !== 'number' || isNaN(offset)) {
|
||||
throw new TypeError(`"offset" is not an integer got "${isNaN(offset) ? 'NaN' : typeof offset}"`);
|
||||
}
|
||||
if (typeof length !== 'number' || isNaN(length)) {
|
||||
throw new TypeError(`"length" is not an integer got "${isNaN(length) ? 'NaN' : typeof length}"`);
|
||||
}
|
||||
debug('read');
|
||||
if (buffer.length < offset + length) {
|
||||
throw new Error('buffer is too small');
|
||||
}
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, unix_read_1.unixRead)({ binding: this, buffer, offset, length });
|
||||
}
|
||||
async write(buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
debug('write', buffer.length, 'bytes');
|
||||
if (!this.isOpen) {
|
||||
debug('write', 'error port is not open');
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
this.writeOperation = (async () => {
|
||||
if (buffer.length === 0) {
|
||||
return;
|
||||
}
|
||||
await (0, unix_write_1.unixWrite)({ binding: this, buffer });
|
||||
this.writeOperation = null;
|
||||
})();
|
||||
return this.writeOperation;
|
||||
}
|
||||
async update(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw TypeError('"options" is not an object');
|
||||
}
|
||||
if (typeof options.baudRate !== 'number') {
|
||||
throw new TypeError('"options.baudRate" is not a number');
|
||||
}
|
||||
debug('update');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncUpdate)(this.fd, options);
|
||||
}
|
||||
async set(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
debug('set', options);
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncSet)(this.fd, options);
|
||||
}
|
||||
async get() {
|
||||
debug('get');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, load_bindings_1.asyncGet)(this.fd);
|
||||
}
|
||||
async getBaudRate() {
|
||||
debug('getBaudRate');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
throw new Error('getBaudRate is not implemented on darwin');
|
||||
}
|
||||
async flush() {
|
||||
debug('flush');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncFlush)(this.fd);
|
||||
}
|
||||
async drain() {
|
||||
debug('drain');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await this.writeOperation;
|
||||
await (0, load_bindings_1.asyncDrain)(this.fd);
|
||||
}
|
||||
}
|
||||
exports.DarwinPortBinding = DarwinPortBinding;
|
||||
7
node_modules/@serialport/bindings-cpp/dist/errors.d.ts
generated
vendored
Normal file
7
node_modules/@serialport/bindings-cpp/dist/errors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { BindingsErrorInterface } from '@serialport/bindings-interface';
|
||||
export declare class BindingsError extends Error implements BindingsErrorInterface {
|
||||
canceled: boolean;
|
||||
constructor(message: string, { canceled }?: {
|
||||
canceled?: boolean | undefined;
|
||||
});
|
||||
}
|
||||
10
node_modules/@serialport/bindings-cpp/dist/errors.js
generated
vendored
Normal file
10
node_modules/@serialport/bindings-cpp/dist/errors.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.BindingsError = void 0;
|
||||
class BindingsError extends Error {
|
||||
constructor(message, { canceled = false } = {}) {
|
||||
super(message);
|
||||
this.canceled = canceled;
|
||||
}
|
||||
}
|
||||
exports.BindingsError = BindingsError;
|
||||
13
node_modules/@serialport/bindings-cpp/dist/index.d.ts
generated
vendored
Normal file
13
node_modules/@serialport/bindings-cpp/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { DarwinBindingInterface } from './darwin';
|
||||
import { LinuxBindingInterface } from './linux';
|
||||
import { WindowsBindingInterface } from './win32';
|
||||
export * from '@serialport/bindings-interface';
|
||||
export * from './darwin';
|
||||
export * from './linux';
|
||||
export * from './win32';
|
||||
export * from './errors';
|
||||
export type AutoDetectTypes = DarwinBindingInterface | WindowsBindingInterface | LinuxBindingInterface;
|
||||
/**
|
||||
* This is an auto detected binding for your current platform
|
||||
*/
|
||||
export declare function autoDetect(): AutoDetectTypes;
|
||||
48
node_modules/@serialport/bindings-cpp/dist/index.js
generated
vendored
Normal file
48
node_modules/@serialport/bindings-cpp/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.autoDetect = void 0;
|
||||
/* eslint-disable @typescript-eslint/no-var-requires */
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const darwin_1 = require("./darwin");
|
||||
const linux_1 = require("./linux");
|
||||
const win32_1 = require("./win32");
|
||||
const debug = (0, debug_1.default)('serialport/bindings-cpp');
|
||||
__exportStar(require("@serialport/bindings-interface"), exports);
|
||||
__exportStar(require("./darwin"), exports);
|
||||
__exportStar(require("./linux"), exports);
|
||||
__exportStar(require("./win32"), exports);
|
||||
__exportStar(require("./errors"), exports);
|
||||
/**
|
||||
* This is an auto detected binding for your current platform
|
||||
*/
|
||||
function autoDetect() {
|
||||
switch (process.platform) {
|
||||
case 'win32':
|
||||
debug('loading WindowsBinding');
|
||||
return win32_1.WindowsBinding;
|
||||
case 'darwin':
|
||||
debug('loading DarwinBinding');
|
||||
return darwin_1.DarwinBinding;
|
||||
default:
|
||||
debug('loading LinuxBinding');
|
||||
return linux_1.LinuxBinding;
|
||||
}
|
||||
}
|
||||
exports.autoDetect = autoDetect;
|
||||
4
node_modules/@serialport/bindings-cpp/dist/linux-list.d.ts
generated
vendored
Normal file
4
node_modules/@serialport/bindings-cpp/dist/linux-list.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
/// <reference types="node" />
|
||||
import { spawn } from 'child_process';
|
||||
import { PortInfo } from '@serialport/bindings-interface';
|
||||
export declare function linuxList(spawnCmd?: typeof spawn): Promise<PortInfo[]>;
|
||||
115
node_modules/@serialport/bindings-cpp/dist/linux-list.js
generated
vendored
Normal file
115
node_modules/@serialport/bindings-cpp/dist/linux-list.js
generated
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.linuxList = void 0;
|
||||
const child_process_1 = require("child_process");
|
||||
const parser_readline_1 = require("@serialport/parser-readline");
|
||||
// get only serial port names
|
||||
function checkPathOfDevice(path) {
|
||||
return /(tty(S|WCH|ACM|USB|AMA|MFD|O|XRUSB)|rfcomm)/.test(path) && path;
|
||||
}
|
||||
function propName(name) {
|
||||
return {
|
||||
DEVNAME: 'path',
|
||||
ID_VENDOR_ENC: 'manufacturer',
|
||||
ID_SERIAL_SHORT: 'serialNumber',
|
||||
ID_VENDOR_ID: 'vendorId',
|
||||
ID_MODEL_ID: 'productId',
|
||||
DEVLINKS: 'pnpId',
|
||||
/**
|
||||
* Workaround for systemd defect
|
||||
* see https://github.com/serialport/bindings-cpp/issues/115
|
||||
*/
|
||||
ID_USB_VENDOR_ENC: 'manufacturer',
|
||||
ID_USB_SERIAL_SHORT: 'serialNumber',
|
||||
ID_USB_VENDOR_ID: 'vendorId',
|
||||
ID_USB_MODEL_ID: 'productId',
|
||||
// End of workaround
|
||||
}[name.toUpperCase()];
|
||||
}
|
||||
function decodeHexEscape(str) {
|
||||
return str.replace(/\\x([a-fA-F0-9]{2})/g, (a, b) => {
|
||||
return String.fromCharCode(parseInt(b, 16));
|
||||
});
|
||||
}
|
||||
function propVal(name, val) {
|
||||
if (name === 'pnpId') {
|
||||
const match = val.match(/\/by-id\/([^\s]+)/);
|
||||
return (match === null || match === void 0 ? void 0 : match[1]) || undefined;
|
||||
}
|
||||
if (name === 'manufacturer') {
|
||||
return decodeHexEscape(val);
|
||||
}
|
||||
if (/^0x/.test(val)) {
|
||||
return val.substr(2);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
function linuxList(spawnCmd = child_process_1.spawn) {
|
||||
const ports = [];
|
||||
const udevadm = spawnCmd('udevadm', ['info', '-e']);
|
||||
const lines = udevadm.stdout.pipe(new parser_readline_1.ReadlineParser());
|
||||
let skipPort = false;
|
||||
let port = {
|
||||
path: '',
|
||||
manufacturer: undefined,
|
||||
serialNumber: undefined,
|
||||
pnpId: undefined,
|
||||
locationId: undefined,
|
||||
vendorId: undefined,
|
||||
productId: undefined,
|
||||
};
|
||||
lines.on('data', (line) => {
|
||||
const lineType = line.slice(0, 1);
|
||||
const data = line.slice(3);
|
||||
// new port entry
|
||||
if (lineType === 'P') {
|
||||
port = {
|
||||
path: '',
|
||||
manufacturer: undefined,
|
||||
serialNumber: undefined,
|
||||
pnpId: undefined,
|
||||
locationId: undefined,
|
||||
vendorId: undefined,
|
||||
productId: undefined,
|
||||
};
|
||||
skipPort = false;
|
||||
return;
|
||||
}
|
||||
if (skipPort) {
|
||||
return;
|
||||
}
|
||||
// Check dev name and save port if it matches flag to skip the rest of the data if not
|
||||
if (lineType === 'N') {
|
||||
if (checkPathOfDevice(data)) {
|
||||
ports.push(port);
|
||||
}
|
||||
else {
|
||||
skipPort = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// parse data about each port
|
||||
if (lineType === 'E') {
|
||||
const keyValue = data.match(/^(.+)=(.*)/);
|
||||
if (!keyValue) {
|
||||
return;
|
||||
}
|
||||
const key = propName(keyValue[1]);
|
||||
if (!key) {
|
||||
return;
|
||||
}
|
||||
port[key] = propVal(key, keyValue[2]);
|
||||
}
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
udevadm.on('close', (code) => {
|
||||
if (code) {
|
||||
reject(new Error(`Error listing ports udevadm exited with error code: ${code}`));
|
||||
}
|
||||
});
|
||||
udevadm.on('error', reject);
|
||||
lines.on('error', reject);
|
||||
lines.on('finish', () => resolve(ports));
|
||||
});
|
||||
}
|
||||
exports.linuxList = linuxList;
|
||||
46
node_modules/@serialport/bindings-cpp/dist/linux.d.ts
generated
vendored
Normal file
46
node_modules/@serialport/bindings-cpp/dist/linux.d.ts
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/// <reference types="node" />
|
||||
import { Poller } from './poller';
|
||||
import { BindingInterface, OpenOptions, PortStatus, SetOptions, UpdateOptions } from '@serialport/bindings-interface';
|
||||
import { BindingPortInterface } from '.';
|
||||
export interface LinuxOpenOptions extends OpenOptions {
|
||||
/** Defaults to none */
|
||||
parity?: 'none' | 'even' | 'odd';
|
||||
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 1 */
|
||||
vmin?: number;
|
||||
/** see [`man termios`](http://linux.die.net/man/3/termios) defaults to 0 */
|
||||
vtime?: number;
|
||||
}
|
||||
export interface LinuxPortStatus extends PortStatus {
|
||||
lowLatency: boolean;
|
||||
}
|
||||
export interface LinuxSetOptions extends SetOptions {
|
||||
/** Low latency mode */
|
||||
lowLatency?: boolean;
|
||||
}
|
||||
export type LinuxBindingInterface = BindingInterface<LinuxPortBinding, LinuxOpenOptions>;
|
||||
export declare const LinuxBinding: LinuxBindingInterface;
|
||||
/**
|
||||
* The linux binding layer
|
||||
*/
|
||||
export declare class LinuxPortBinding implements BindingPortInterface {
|
||||
readonly openOptions: Required<LinuxOpenOptions>;
|
||||
readonly poller: Poller;
|
||||
private writeOperation;
|
||||
fd: number | null;
|
||||
constructor(fd: number, openOptions: Required<LinuxOpenOptions>);
|
||||
get isOpen(): boolean;
|
||||
close(): Promise<void>;
|
||||
read(buffer: Buffer, offset: number, length: number): Promise<{
|
||||
buffer: Buffer;
|
||||
bytesRead: number;
|
||||
}>;
|
||||
write(buffer: Buffer): Promise<void>;
|
||||
update(options: UpdateOptions): Promise<void>;
|
||||
set(options: LinuxSetOptions): Promise<void>;
|
||||
get(): Promise<LinuxPortStatus>;
|
||||
getBaudRate(): Promise<{
|
||||
baudRate: number;
|
||||
}>;
|
||||
flush(): Promise<void>;
|
||||
drain(): Promise<void>;
|
||||
}
|
||||
150
node_modules/@serialport/bindings-cpp/dist/linux.js
generated
vendored
Normal file
150
node_modules/@serialport/bindings-cpp/dist/linux.js
generated
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.LinuxPortBinding = exports.LinuxBinding = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const linux_list_1 = require("./linux-list");
|
||||
const poller_1 = require("./poller");
|
||||
const unix_read_1 = require("./unix-read");
|
||||
const unix_write_1 = require("./unix-write");
|
||||
const load_bindings_1 = require("./load-bindings");
|
||||
const debug = (0, debug_1.default)('serialport/bindings-cpp');
|
||||
exports.LinuxBinding = {
|
||||
list() {
|
||||
debug('list');
|
||||
return (0, linux_list_1.linuxList)();
|
||||
},
|
||||
async open(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
if (!options.path) {
|
||||
throw new TypeError('"path" is not a valid port');
|
||||
}
|
||||
if (!options.baudRate) {
|
||||
throw new TypeError('"baudRate" is not a valid baudRate');
|
||||
}
|
||||
debug('open');
|
||||
const openOptions = Object.assign({ vmin: 1, vtime: 0, dataBits: 8, lock: true, stopBits: 1, parity: 'none', rtscts: false, xon: false, xoff: false, xany: false, hupcl: true }, options);
|
||||
const fd = await (0, load_bindings_1.asyncOpen)(openOptions.path, openOptions);
|
||||
this.fd = fd;
|
||||
return new LinuxPortBinding(fd, openOptions);
|
||||
},
|
||||
};
|
||||
/**
|
||||
* The linux binding layer
|
||||
*/
|
||||
class LinuxPortBinding {
|
||||
constructor(fd, openOptions) {
|
||||
this.fd = fd;
|
||||
this.openOptions = openOptions;
|
||||
this.poller = new poller_1.Poller(fd);
|
||||
this.writeOperation = null;
|
||||
}
|
||||
get isOpen() {
|
||||
return this.fd !== null;
|
||||
}
|
||||
async close() {
|
||||
debug('close');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
const fd = this.fd;
|
||||
this.poller.stop();
|
||||
this.poller.destroy();
|
||||
this.fd = null;
|
||||
await (0, load_bindings_1.asyncClose)(fd);
|
||||
}
|
||||
async read(buffer, offset, length) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
if (typeof offset !== 'number' || isNaN(offset)) {
|
||||
throw new TypeError(`"offset" is not an integer got "${isNaN(offset) ? 'NaN' : typeof offset}"`);
|
||||
}
|
||||
if (typeof length !== 'number' || isNaN(length)) {
|
||||
throw new TypeError(`"length" is not an integer got "${isNaN(length) ? 'NaN' : typeof length}"`);
|
||||
}
|
||||
debug('read');
|
||||
if (buffer.length < offset + length) {
|
||||
throw new Error('buffer is too small');
|
||||
}
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, unix_read_1.unixRead)({ binding: this, buffer, offset, length });
|
||||
}
|
||||
async write(buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
debug('write', buffer.length, 'bytes');
|
||||
if (!this.isOpen) {
|
||||
debug('write', 'error port is not open');
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
this.writeOperation = (async () => {
|
||||
if (buffer.length === 0) {
|
||||
return;
|
||||
}
|
||||
await (0, unix_write_1.unixWrite)({ binding: this, buffer });
|
||||
this.writeOperation = null;
|
||||
})();
|
||||
return this.writeOperation;
|
||||
}
|
||||
async update(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw TypeError('"options" is not an object');
|
||||
}
|
||||
if (typeof options.baudRate !== 'number') {
|
||||
throw new TypeError('"options.baudRate" is not a number');
|
||||
}
|
||||
debug('update');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncUpdate)(this.fd, options);
|
||||
}
|
||||
async set(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
debug('set');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncSet)(this.fd, options);
|
||||
}
|
||||
async get() {
|
||||
debug('get');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, load_bindings_1.asyncGet)(this.fd);
|
||||
}
|
||||
async getBaudRate() {
|
||||
debug('getBaudRate');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, load_bindings_1.asyncGetBaudRate)(this.fd);
|
||||
}
|
||||
async flush() {
|
||||
debug('flush');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncFlush)(this.fd);
|
||||
}
|
||||
async drain() {
|
||||
debug('drain');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await this.writeOperation;
|
||||
await (0, load_bindings_1.asyncDrain)(this.fd);
|
||||
}
|
||||
}
|
||||
exports.LinuxPortBinding = LinuxPortBinding;
|
||||
11
node_modules/@serialport/bindings-cpp/dist/load-bindings.d.ts
generated
vendored
Normal file
11
node_modules/@serialport/bindings-cpp/dist/load-bindings.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export declare const asyncClose: Function;
|
||||
export declare const asyncDrain: Function;
|
||||
export declare const asyncFlush: Function;
|
||||
export declare const asyncGet: Function;
|
||||
export declare const asyncGetBaudRate: Function;
|
||||
export declare const asyncList: Function;
|
||||
export declare const asyncOpen: Function;
|
||||
export declare const asyncSet: Function;
|
||||
export declare const asyncUpdate: Function;
|
||||
export declare const asyncRead: Function;
|
||||
export declare const asyncWrite: Function;
|
||||
22
node_modules/@serialport/bindings-cpp/dist/load-bindings.js
generated
vendored
Normal file
22
node_modules/@serialport/bindings-cpp/dist/load-bindings.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.asyncWrite = exports.asyncRead = exports.asyncUpdate = exports.asyncSet = exports.asyncOpen = exports.asyncList = exports.asyncGetBaudRate = exports.asyncGet = exports.asyncFlush = exports.asyncDrain = exports.asyncClose = void 0;
|
||||
const node_gyp_build_1 = __importDefault(require("node-gyp-build"));
|
||||
const util_1 = require("util");
|
||||
const path_1 = require("path");
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const binding = (0, node_gyp_build_1.default)((0, path_1.join)(__dirname, '../'));
|
||||
exports.asyncClose = binding.close ? (0, util_1.promisify)(binding.close) : async () => { throw new Error('"binding.close" Method not implemented'); };
|
||||
exports.asyncDrain = binding.drain ? (0, util_1.promisify)(binding.drain) : async () => { throw new Error('"binding.drain" Method not implemented'); };
|
||||
exports.asyncFlush = binding.flush ? (0, util_1.promisify)(binding.flush) : async () => { throw new Error('"binding.flush" Method not implemented'); };
|
||||
exports.asyncGet = binding.get ? (0, util_1.promisify)(binding.get) : async () => { throw new Error('"binding.get" Method not implemented'); };
|
||||
exports.asyncGetBaudRate = binding.getBaudRate ? (0, util_1.promisify)(binding.getBaudRate) : async () => { throw new Error('"binding.getBaudRate" Method not implemented'); };
|
||||
exports.asyncList = binding.list ? (0, util_1.promisify)(binding.list) : async () => { throw new Error('"binding.list" Method not implemented'); };
|
||||
exports.asyncOpen = binding.open ? (0, util_1.promisify)(binding.open) : async () => { throw new Error('"binding.open" Method not implemented'); };
|
||||
exports.asyncSet = binding.set ? (0, util_1.promisify)(binding.set) : async () => { throw new Error('"binding.set" Method not implemented'); };
|
||||
exports.asyncUpdate = binding.update ? (0, util_1.promisify)(binding.update) : async () => { throw new Error('"binding.update" Method not implemented'); };
|
||||
exports.asyncRead = binding.read ? (0, util_1.promisify)(binding.read) : async () => { throw new Error('"binding.read" Method not implemented'); };
|
||||
exports.asyncWrite = binding.write ? (0, util_1.promisify)(binding.write) : async () => { throw new Error('"binding.write" Method not implemented'); };
|
||||
40
node_modules/@serialport/bindings-cpp/dist/poller.d.ts
generated
vendored
Normal file
40
node_modules/@serialport/bindings-cpp/dist/poller.d.ts
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/// <reference types="node" />
|
||||
import { EventEmitter } from 'events';
|
||||
interface PollerClass {
|
||||
new (fd: number, cb: (err: Error, flag: number) => void): PollerInstance;
|
||||
}
|
||||
interface PollerInstance {
|
||||
poll(flag: number): void;
|
||||
stop(): void;
|
||||
destroy(): void;
|
||||
}
|
||||
export declare const EVENTS: {
|
||||
UV_READABLE: number;
|
||||
UV_WRITABLE: number;
|
||||
UV_DISCONNECT: number;
|
||||
};
|
||||
/**
|
||||
* Polls unix systems for readable or writable states of a file or serialport
|
||||
*/
|
||||
export declare class Poller extends EventEmitter {
|
||||
poller: PollerInstance;
|
||||
constructor(fd: number, FDPoller?: PollerClass);
|
||||
/**
|
||||
* Wait for the next event to occur
|
||||
* @param {string} event ('readable'|'writable'|'disconnect')
|
||||
* @returns {Poller} returns itself
|
||||
*/
|
||||
once(event: 'readable' | 'writable' | 'disconnect', callback: (err: null | Error) => void): this;
|
||||
/**
|
||||
* Ask the bindings to listen for an event, it is recommend to use `.once()` for easy use
|
||||
* @param {EVENTS} eventFlag polls for an event or group of events based upon a flag.
|
||||
*/
|
||||
poll(eventFlag?: number): void;
|
||||
/**
|
||||
* Stop listening for events and cancel all outstanding listening with an error
|
||||
*/
|
||||
stop(): void;
|
||||
destroy(): void;
|
||||
emitCanceled(): void;
|
||||
}
|
||||
export {};
|
||||
104
node_modules/@serialport/bindings-cpp/dist/poller.js
generated
vendored
Normal file
104
node_modules/@serialport/bindings-cpp/dist/poller.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Poller = exports.EVENTS = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const events_1 = require("events");
|
||||
const path_1 = require("path");
|
||||
const node_gyp_build_1 = __importDefault(require("node-gyp-build"));
|
||||
const errors_1 = require("./errors");
|
||||
const { Poller: PollerBindings } = (0, node_gyp_build_1.default)((0, path_1.join)(__dirname, '../'));
|
||||
const logger = (0, debug_1.default)('serialport/bindings-cpp/poller');
|
||||
exports.EVENTS = {
|
||||
UV_READABLE: 0b0001,
|
||||
UV_WRITABLE: 0b0010,
|
||||
UV_DISCONNECT: 0b0100,
|
||||
};
|
||||
function handleEvent(error, eventFlag) {
|
||||
if (error) {
|
||||
logger('error', error);
|
||||
this.emit('readable', error);
|
||||
this.emit('writable', error);
|
||||
this.emit('disconnect', error);
|
||||
return;
|
||||
}
|
||||
if (eventFlag & exports.EVENTS.UV_READABLE) {
|
||||
logger('received "readable"');
|
||||
this.emit('readable', null);
|
||||
}
|
||||
if (eventFlag & exports.EVENTS.UV_WRITABLE) {
|
||||
logger('received "writable"');
|
||||
this.emit('writable', null);
|
||||
}
|
||||
if (eventFlag & exports.EVENTS.UV_DISCONNECT) {
|
||||
logger('received "disconnect"');
|
||||
this.emit('disconnect', null);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Polls unix systems for readable or writable states of a file or serialport
|
||||
*/
|
||||
class Poller extends events_1.EventEmitter {
|
||||
constructor(fd, FDPoller = PollerBindings) {
|
||||
logger('Creating poller');
|
||||
super();
|
||||
this.poller = new FDPoller(fd, handleEvent.bind(this));
|
||||
}
|
||||
/**
|
||||
* Wait for the next event to occur
|
||||
* @param {string} event ('readable'|'writable'|'disconnect')
|
||||
* @returns {Poller} returns itself
|
||||
*/
|
||||
once(event, callback) {
|
||||
switch (event) {
|
||||
case 'readable':
|
||||
this.poll(exports.EVENTS.UV_READABLE);
|
||||
break;
|
||||
case 'writable':
|
||||
this.poll(exports.EVENTS.UV_WRITABLE);
|
||||
break;
|
||||
case 'disconnect':
|
||||
this.poll(exports.EVENTS.UV_DISCONNECT);
|
||||
break;
|
||||
}
|
||||
return super.once(event, callback);
|
||||
}
|
||||
/**
|
||||
* Ask the bindings to listen for an event, it is recommend to use `.once()` for easy use
|
||||
* @param {EVENTS} eventFlag polls for an event or group of events based upon a flag.
|
||||
*/
|
||||
poll(eventFlag = 0) {
|
||||
if (eventFlag & exports.EVENTS.UV_READABLE) {
|
||||
logger('Polling for "readable"');
|
||||
}
|
||||
if (eventFlag & exports.EVENTS.UV_WRITABLE) {
|
||||
logger('Polling for "writable"');
|
||||
}
|
||||
if (eventFlag & exports.EVENTS.UV_DISCONNECT) {
|
||||
logger('Polling for "disconnect"');
|
||||
}
|
||||
this.poller.poll(eventFlag);
|
||||
}
|
||||
/**
|
||||
* Stop listening for events and cancel all outstanding listening with an error
|
||||
*/
|
||||
stop() {
|
||||
logger('Stopping poller');
|
||||
this.poller.stop();
|
||||
this.emitCanceled();
|
||||
}
|
||||
destroy() {
|
||||
logger('Destroying poller');
|
||||
this.poller.destroy();
|
||||
this.emitCanceled();
|
||||
}
|
||||
emitCanceled() {
|
||||
const err = new errors_1.BindingsError('Canceled', { canceled: true });
|
||||
this.emit('readable', err);
|
||||
this.emit('writable', err);
|
||||
this.emit('disconnect', err);
|
||||
}
|
||||
}
|
||||
exports.Poller = Poller;
|
||||
18
node_modules/@serialport/bindings-cpp/dist/unix-read.d.ts
generated
vendored
Normal file
18
node_modules/@serialport/bindings-cpp/dist/unix-read.d.ts
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { read as fsRead } from 'fs';
|
||||
import { LinuxPortBinding } from './linux';
|
||||
import { DarwinPortBinding } from './darwin';
|
||||
declare const readAsync: typeof fsRead.__promisify__;
|
||||
interface UnixReadOptions {
|
||||
binding: LinuxPortBinding | DarwinPortBinding;
|
||||
buffer: Buffer;
|
||||
offset: number;
|
||||
length: number;
|
||||
fsReadAsync?: typeof readAsync;
|
||||
}
|
||||
export declare const unixRead: ({ binding, buffer, offset, length, fsReadAsync, }: UnixReadOptions) => Promise<{
|
||||
buffer: Buffer;
|
||||
bytesRead: number;
|
||||
}>;
|
||||
export {};
|
||||
55
node_modules/@serialport/bindings-cpp/dist/unix-read.js
generated
vendored
Normal file
55
node_modules/@serialport/bindings-cpp/dist/unix-read.js
generated
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unixRead = void 0;
|
||||
const util_1 = require("util");
|
||||
const fs_1 = require("fs");
|
||||
const errors_1 = require("./errors");
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const logger = (0, debug_1.default)('serialport/bindings-cpp/unixRead');
|
||||
const readAsync = (0, util_1.promisify)(fs_1.read);
|
||||
const readable = (binding) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!binding.poller) {
|
||||
throw new Error('No poller on bindings');
|
||||
}
|
||||
binding.poller.once('readable', err => (err ? reject(err) : resolve()));
|
||||
});
|
||||
};
|
||||
const unixRead = async ({ binding, buffer, offset, length, fsReadAsync = readAsync, }) => {
|
||||
logger('Starting read');
|
||||
if (!binding.isOpen || !binding.fd) {
|
||||
throw new errors_1.BindingsError('Port is not open', { canceled: true });
|
||||
}
|
||||
try {
|
||||
const { bytesRead } = await fsReadAsync(binding.fd, buffer, offset, length, null);
|
||||
if (bytesRead === 0) {
|
||||
return (0, exports.unixRead)({ binding, buffer, offset, length, fsReadAsync });
|
||||
}
|
||||
logger('Finished read', bytesRead, 'bytes');
|
||||
return { bytesRead, buffer };
|
||||
}
|
||||
catch (err) {
|
||||
logger('read error', err);
|
||||
if (err.code === 'EAGAIN' || err.code === 'EWOULDBLOCK' || err.code === 'EINTR') {
|
||||
if (!binding.isOpen) {
|
||||
throw new errors_1.BindingsError('Port is not open', { canceled: true });
|
||||
}
|
||||
logger('waiting for readable because of code:', err.code);
|
||||
await readable(binding);
|
||||
return (0, exports.unixRead)({ binding, buffer, offset, length, fsReadAsync });
|
||||
}
|
||||
const disconnectError = err.code === 'EBADF' || // Bad file number means we got closed
|
||||
err.code === 'ENXIO' || // No such device or address probably usb disconnect
|
||||
err.code === 'UNKNOWN' ||
|
||||
err.errno === -1; // generic error
|
||||
if (disconnectError) {
|
||||
err.disconnect = true;
|
||||
logger('disconnecting', err);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
exports.unixRead = unixRead;
|
||||
14
node_modules/@serialport/bindings-cpp/dist/unix-write.d.ts
generated
vendored
Normal file
14
node_modules/@serialport/bindings-cpp/dist/unix-write.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
/// <reference types="node" />
|
||||
/// <reference types="node" />
|
||||
import { write } from 'fs';
|
||||
import { LinuxPortBinding } from './linux';
|
||||
import { DarwinPortBinding } from './darwin';
|
||||
declare const writeAsync: typeof write.__promisify__;
|
||||
interface UnixWriteOptions {
|
||||
binding: LinuxPortBinding | DarwinPortBinding;
|
||||
buffer: Buffer;
|
||||
offset?: number;
|
||||
fsWriteAsync?: typeof writeAsync;
|
||||
}
|
||||
export declare const unixWrite: ({ binding, buffer, offset, fsWriteAsync }: UnixWriteOptions) => Promise<void>;
|
||||
export {};
|
||||
56
node_modules/@serialport/bindings-cpp/dist/unix-write.js
generated
vendored
Normal file
56
node_modules/@serialport/bindings-cpp/dist/unix-write.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.unixWrite = void 0;
|
||||
const fs_1 = require("fs");
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const util_1 = require("util");
|
||||
const logger = (0, debug_1.default)('serialport/bindings-cpp/unixWrite');
|
||||
const writeAsync = (0, util_1.promisify)(fs_1.write);
|
||||
const writable = (binding) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
binding.poller.once('writable', err => (err ? reject(err) : resolve()));
|
||||
});
|
||||
};
|
||||
const unixWrite = async ({ binding, buffer, offset = 0, fsWriteAsync = writeAsync }) => {
|
||||
const bytesToWrite = buffer.length - offset;
|
||||
logger('Starting write', buffer.length, 'bytes offset', offset, 'bytesToWrite', bytesToWrite);
|
||||
if (!binding.isOpen || !binding.fd) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
try {
|
||||
const { bytesWritten } = await fsWriteAsync(binding.fd, buffer, offset, bytesToWrite);
|
||||
logger('write returned: wrote', bytesWritten, 'bytes');
|
||||
if (bytesWritten + offset < buffer.length) {
|
||||
if (!binding.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, exports.unixWrite)({ binding, buffer, offset: bytesWritten + offset, fsWriteAsync });
|
||||
}
|
||||
logger('Finished writing', bytesWritten + offset, 'bytes');
|
||||
}
|
||||
catch (err) {
|
||||
logger('write errored', err);
|
||||
if (err.code === 'EAGAIN' || err.code === 'EWOULDBLOCK' || err.code === 'EINTR') {
|
||||
if (!binding.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
logger('waiting for writable because of code:', err.code);
|
||||
await writable(binding);
|
||||
return (0, exports.unixWrite)({ binding, buffer, offset, fsWriteAsync });
|
||||
}
|
||||
const disconnectError = err.code === 'EBADF' || // Bad file number means we got closed
|
||||
err.code === 'ENXIO' || // No such device or address probably usb disconnect
|
||||
err.code === 'UNKNOWN' ||
|
||||
err.errno === -1; // generic error
|
||||
if (disconnectError) {
|
||||
err.disconnect = true;
|
||||
logger('disconnecting', err);
|
||||
}
|
||||
logger('error', err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
exports.unixWrite = unixWrite;
|
||||
1
node_modules/@serialport/bindings-cpp/dist/win32-sn-parser.d.ts
generated
vendored
Normal file
1
node_modules/@serialport/bindings-cpp/dist/win32-sn-parser.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare const serialNumParser: (pnpId?: string) => string | null;
|
||||
17
node_modules/@serialport/bindings-cpp/dist/win32-sn-parser.js
generated
vendored
Normal file
17
node_modules/@serialport/bindings-cpp/dist/win32-sn-parser.js
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.serialNumParser = void 0;
|
||||
const PARSERS = [/USB\\(?:.+)\\(.+)/, /FTDIBUS\\(?:.+)\+(.+?)A?\\.+/];
|
||||
const serialNumParser = (pnpId) => {
|
||||
if (!pnpId) {
|
||||
return null;
|
||||
}
|
||||
for (const parser of PARSERS) {
|
||||
const sn = pnpId.match(parser);
|
||||
if (sn) {
|
||||
return sn[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
exports.serialNumParser = serialNumParser;
|
||||
35
node_modules/@serialport/bindings-cpp/dist/win32.d.ts
generated
vendored
Normal file
35
node_modules/@serialport/bindings-cpp/dist/win32.d.ts
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
/// <reference types="node" />
|
||||
import { BindingPortInterface } from '.';
|
||||
import { BindingInterface, OpenOptions, PortStatus, SetOptions, UpdateOptions } from '@serialport/bindings-interface';
|
||||
export interface WindowsOpenOptions extends OpenOptions {
|
||||
/** Device parity defaults to none */
|
||||
parity?: 'none' | 'even' | 'odd' | 'mark' | 'space';
|
||||
/** RTS mode defaults to handshake */
|
||||
rtsMode?: 'handshake' | 'enable' | 'toggle';
|
||||
}
|
||||
export type WindowsBindingInterface = BindingInterface<WindowsPortBinding, WindowsOpenOptions>;
|
||||
export declare const WindowsBinding: WindowsBindingInterface;
|
||||
/**
|
||||
* The Windows binding layer
|
||||
*/
|
||||
export declare class WindowsPortBinding implements BindingPortInterface {
|
||||
fd: null | number;
|
||||
writeOperation: Promise<void> | null;
|
||||
openOptions: Required<OpenOptions>;
|
||||
constructor(fd: number, options: Required<OpenOptions>);
|
||||
get isOpen(): boolean;
|
||||
close(): Promise<void>;
|
||||
read(buffer: Buffer, offset: number, length: number): Promise<{
|
||||
buffer: Buffer;
|
||||
bytesRead: number;
|
||||
}>;
|
||||
write(buffer: Buffer): Promise<void>;
|
||||
update(options: UpdateOptions): Promise<void>;
|
||||
set(options: SetOptions): Promise<void>;
|
||||
get(): Promise<PortStatus>;
|
||||
getBaudRate(): Promise<{
|
||||
baudRate: number;
|
||||
}>;
|
||||
flush(): Promise<void>;
|
||||
drain(): Promise<void>;
|
||||
}
|
||||
162
node_modules/@serialport/bindings-cpp/dist/win32.js
generated
vendored
Normal file
162
node_modules/@serialport/bindings-cpp/dist/win32.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.WindowsPortBinding = exports.WindowsBinding = void 0;
|
||||
const debug_1 = __importDefault(require("debug"));
|
||||
const _1 = require(".");
|
||||
const load_bindings_1 = require("./load-bindings");
|
||||
const win32_sn_parser_1 = require("./win32-sn-parser");
|
||||
const debug = (0, debug_1.default)('serialport/bindings-cpp');
|
||||
exports.WindowsBinding = {
|
||||
async list() {
|
||||
const ports = await (0, load_bindings_1.asyncList)();
|
||||
// Grab the serial number from the pnp id
|
||||
return ports.map(port => {
|
||||
if (port.pnpId && !port.serialNumber) {
|
||||
const serialNumber = (0, win32_sn_parser_1.serialNumParser)(port.pnpId);
|
||||
if (serialNumber) {
|
||||
return Object.assign(Object.assign({}, port), { serialNumber });
|
||||
}
|
||||
}
|
||||
return port;
|
||||
});
|
||||
},
|
||||
async open(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
if (!options.path) {
|
||||
throw new TypeError('"path" is not a valid port');
|
||||
}
|
||||
if (!options.baudRate) {
|
||||
throw new TypeError('"baudRate" is not a valid baudRate');
|
||||
}
|
||||
debug('open');
|
||||
const openOptions = Object.assign({ dataBits: 8, lock: true, stopBits: 1, parity: 'none', rtscts: false, rtsMode: 'handshake', xon: false, xoff: false, xany: false, hupcl: true }, options);
|
||||
const fd = await (0, load_bindings_1.asyncOpen)(openOptions.path, openOptions);
|
||||
return new WindowsPortBinding(fd, openOptions);
|
||||
},
|
||||
};
|
||||
/**
|
||||
* The Windows binding layer
|
||||
*/
|
||||
class WindowsPortBinding {
|
||||
constructor(fd, options) {
|
||||
this.fd = fd;
|
||||
this.openOptions = options;
|
||||
this.writeOperation = null;
|
||||
}
|
||||
get isOpen() {
|
||||
return this.fd !== null;
|
||||
}
|
||||
async close() {
|
||||
debug('close');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
const fd = this.fd;
|
||||
this.fd = null;
|
||||
await (0, load_bindings_1.asyncClose)(fd);
|
||||
}
|
||||
async read(buffer, offset, length) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
if (typeof offset !== 'number' || isNaN(offset)) {
|
||||
throw new TypeError(`"offset" is not an integer got "${isNaN(offset) ? 'NaN' : typeof offset}"`);
|
||||
}
|
||||
if (typeof length !== 'number' || isNaN(length)) {
|
||||
throw new TypeError(`"length" is not an integer got "${isNaN(length) ? 'NaN' : typeof length}"`);
|
||||
}
|
||||
debug('read');
|
||||
if (buffer.length < offset + length) {
|
||||
throw new Error('buffer is too small');
|
||||
}
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
try {
|
||||
const bytesRead = await (0, load_bindings_1.asyncRead)(this.fd, buffer, offset, length);
|
||||
return { bytesRead, buffer };
|
||||
}
|
||||
catch (err) {
|
||||
if (!this.isOpen) {
|
||||
throw new _1.BindingsError(err.message, { canceled: true });
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
async write(buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
debug('write', buffer.length, 'bytes');
|
||||
if (!this.isOpen) {
|
||||
debug('write', 'error port is not open');
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
this.writeOperation = (async () => {
|
||||
if (buffer.length === 0) {
|
||||
return;
|
||||
}
|
||||
await (0, load_bindings_1.asyncWrite)(this.fd, buffer);
|
||||
this.writeOperation = null;
|
||||
})();
|
||||
return this.writeOperation;
|
||||
}
|
||||
async update(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw TypeError('"options" is not an object');
|
||||
}
|
||||
if (typeof options.baudRate !== 'number') {
|
||||
throw new TypeError('"options.baudRate" is not a number');
|
||||
}
|
||||
debug('update');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncUpdate)(this.fd, options);
|
||||
}
|
||||
async set(options) {
|
||||
if (!options || typeof options !== 'object' || Array.isArray(options)) {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
debug('set', options);
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncSet)(this.fd, options);
|
||||
}
|
||||
async get() {
|
||||
debug('get');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, load_bindings_1.asyncGet)(this.fd);
|
||||
}
|
||||
async getBaudRate() {
|
||||
debug('getBaudRate');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
return (0, load_bindings_1.asyncGetBaudRate)(this.fd);
|
||||
}
|
||||
async flush() {
|
||||
debug('flush');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await (0, load_bindings_1.asyncFlush)(this.fd);
|
||||
}
|
||||
async drain() {
|
||||
debug('drain');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await this.writeOperation;
|
||||
await (0, load_bindings_1.asyncDrain)(this.fd);
|
||||
}
|
||||
}
|
||||
exports.WindowsPortBinding = WindowsPortBinding;
|
||||
Reference in New Issue
Block a user