Dia antes primera install
This commit is contained in:
6
node_modules/@serialport/binding-mock/.releaserc
generated
vendored
Normal file
6
node_modules/@serialport/binding-mock/.releaserc
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"branches": [
|
||||
"main",
|
||||
"next"
|
||||
]
|
||||
}
|
||||
21
node_modules/@serialport/binding-mock/LICENSE
generated
vendored
Normal file
21
node_modules/@serialport/binding-mock/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021 Francis Gulotta
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
9
node_modules/@serialport/binding-mock/README.md
generated
vendored
Normal file
9
node_modules/@serialport/binding-mock/README.md
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
# @serialport/binding-mock
|
||||
|
||||
```ts
|
||||
import { MockBinding } from '@serialport/binding-mock'
|
||||
const MockBinding = new MockBinding()
|
||||
|
||||
MockBinding.createPort('/dev/fakePort', { echo: true })
|
||||
await MockBinding.write(Buffer.from('data')))
|
||||
```
|
||||
271
node_modules/@serialport/binding-mock/dist/index-esm.mjs
generated
vendored
Normal file
271
node_modules/@serialport/binding-mock/dist/index-esm.mjs
generated
vendored
Normal file
@@ -0,0 +1,271 @@
|
||||
import debugFactory from 'debug';
|
||||
|
||||
const debug = debugFactory('serialport/binding-mock');
|
||||
let ports = {};
|
||||
let serialNumber = 0;
|
||||
function resolveNextTick() {
|
||||
return new Promise(resolve => process.nextTick(() => resolve()));
|
||||
}
|
||||
class CanceledError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.canceled = true;
|
||||
}
|
||||
}
|
||||
const MockBinding = {
|
||||
reset() {
|
||||
ports = {};
|
||||
serialNumber = 0;
|
||||
},
|
||||
// Create a mock port
|
||||
createPort(path, options = {}) {
|
||||
serialNumber++;
|
||||
const optWithDefaults = Object.assign({ echo: false, record: false, manufacturer: 'The J5 Robotics Company', vendorId: undefined, productId: undefined, maxReadSize: 1024 }, options);
|
||||
ports[path] = {
|
||||
data: Buffer.alloc(0),
|
||||
echo: optWithDefaults.echo,
|
||||
record: optWithDefaults.record,
|
||||
readyData: optWithDefaults.readyData,
|
||||
maxReadSize: optWithDefaults.maxReadSize,
|
||||
info: {
|
||||
path,
|
||||
manufacturer: optWithDefaults.manufacturer,
|
||||
serialNumber: `${serialNumber}`,
|
||||
pnpId: undefined,
|
||||
locationId: undefined,
|
||||
vendorId: optWithDefaults.vendorId,
|
||||
productId: optWithDefaults.productId,
|
||||
},
|
||||
};
|
||||
debug(serialNumber, 'created port', JSON.stringify({ path, opt: options }));
|
||||
},
|
||||
async list() {
|
||||
debug(null, 'list');
|
||||
return Object.values(ports).map(port => port.info);
|
||||
},
|
||||
async open(options) {
|
||||
var _a;
|
||||
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');
|
||||
}
|
||||
const openOptions = Object.assign({ dataBits: 8, lock: true, stopBits: 1, parity: 'none', rtscts: false, xon: false, xoff: false, xany: false, hupcl: true }, options);
|
||||
const { path } = openOptions;
|
||||
debug(null, `open: opening path ${path}`);
|
||||
const port = ports[path];
|
||||
await resolveNextTick();
|
||||
if (!port) {
|
||||
throw new Error(`Port does not exist - please call MockBinding.createPort('${path}') first`);
|
||||
}
|
||||
const serialNumber = port.info.serialNumber;
|
||||
if ((_a = port.openOpt) === null || _a === void 0 ? void 0 : _a.lock) {
|
||||
debug(serialNumber, 'open: Port is locked cannot open');
|
||||
throw new Error('Port is locked cannot open');
|
||||
}
|
||||
debug(serialNumber, `open: opened path ${path}`);
|
||||
port.openOpt = Object.assign({}, openOptions);
|
||||
return new MockPortBinding(port, openOptions);
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Mock bindings for pretend serialport access
|
||||
*/
|
||||
class MockPortBinding {
|
||||
constructor(port, openOptions) {
|
||||
this.port = port;
|
||||
this.openOptions = openOptions;
|
||||
this.pendingRead = null;
|
||||
this.isOpen = true;
|
||||
this.lastWrite = null;
|
||||
this.recording = Buffer.alloc(0);
|
||||
this.writeOperation = null; // in flight promise or null
|
||||
this.serialNumber = port.info.serialNumber;
|
||||
if (port.readyData) {
|
||||
const data = port.readyData;
|
||||
process.nextTick(() => {
|
||||
if (this.isOpen) {
|
||||
debug(this.serialNumber, 'emitting ready data');
|
||||
this.emitData(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// Emit data on a mock port
|
||||
emitData(data) {
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port must be open to pretend to receive data');
|
||||
}
|
||||
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
||||
debug(this.serialNumber, 'emitting data - pending read:', Boolean(this.pendingRead));
|
||||
this.port.data = Buffer.concat([this.port.data, bufferData]);
|
||||
if (this.pendingRead) {
|
||||
process.nextTick(this.pendingRead);
|
||||
this.pendingRead = null;
|
||||
}
|
||||
}
|
||||
async close() {
|
||||
debug(this.serialNumber, 'close');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
const port = this.port;
|
||||
if (!port) {
|
||||
throw new Error('already closed');
|
||||
}
|
||||
port.openOpt = undefined;
|
||||
// reset data on close
|
||||
port.data = Buffer.alloc(0);
|
||||
debug(this.serialNumber, 'port is closed');
|
||||
this.serialNumber = undefined;
|
||||
this.isOpen = false;
|
||||
if (this.pendingRead) {
|
||||
this.pendingRead(new CanceledError('port is closed'));
|
||||
}
|
||||
}
|
||||
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}"`);
|
||||
}
|
||||
if (buffer.length < offset + length) {
|
||||
throw new Error('buffer is too small');
|
||||
}
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
debug(this.serialNumber, 'read', length, 'bytes');
|
||||
await resolveNextTick();
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new CanceledError('Read canceled');
|
||||
}
|
||||
if (this.port.data.length <= 0) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.pendingRead = err => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
this.read(buffer, offset, length).then(resolve, reject);
|
||||
};
|
||||
});
|
||||
}
|
||||
const lengthToRead = this.port.maxReadSize > length ? length : this.port.maxReadSize;
|
||||
const data = this.port.data.slice(0, lengthToRead);
|
||||
const bytesRead = data.copy(buffer, offset);
|
||||
this.port.data = this.port.data.slice(lengthToRead);
|
||||
debug(this.serialNumber, 'read', bytesRead, 'bytes');
|
||||
return { bytesRead, buffer };
|
||||
}
|
||||
async write(buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
if (!this.isOpen || !this.port) {
|
||||
debug('write', 'error port is not open');
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
debug(this.serialNumber, 'write', buffer.length, 'bytes');
|
||||
if (this.writeOperation) {
|
||||
throw new Error('Overlapping writes are not supported and should be queued by the serialport object');
|
||||
}
|
||||
this.writeOperation = (async () => {
|
||||
await resolveNextTick();
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Write canceled');
|
||||
}
|
||||
const data = (this.lastWrite = Buffer.from(buffer)); // copy
|
||||
if (this.port.record) {
|
||||
this.recording = Buffer.concat([this.recording, data]);
|
||||
}
|
||||
if (this.port.echo) {
|
||||
process.nextTick(() => {
|
||||
if (this.isOpen) {
|
||||
this.emitData(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.writeOperation = null;
|
||||
debug(this.serialNumber, 'writing finished');
|
||||
})();
|
||||
return this.writeOperation;
|
||||
}
|
||||
async update(options) {
|
||||
if (typeof options !== 'object') {
|
||||
throw TypeError('"options" is not an object');
|
||||
}
|
||||
if (typeof options.baudRate !== 'number') {
|
||||
throw new TypeError('"options.baudRate" is not a number');
|
||||
}
|
||||
debug(this.serialNumber, 'update');
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
if (this.port.openOpt) {
|
||||
this.port.openOpt.baudRate = options.baudRate;
|
||||
}
|
||||
}
|
||||
async set(options) {
|
||||
if (typeof options !== 'object') {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
debug(this.serialNumber, 'set');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
}
|
||||
async get() {
|
||||
debug(this.serialNumber, 'get');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
return {
|
||||
cts: true,
|
||||
dsr: false,
|
||||
dcd: false,
|
||||
};
|
||||
}
|
||||
async getBaudRate() {
|
||||
var _a;
|
||||
debug(this.serialNumber, 'getBaudRate');
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
if (!((_a = this.port.openOpt) === null || _a === void 0 ? void 0 : _a.baudRate)) {
|
||||
throw new Error('Internal Error');
|
||||
}
|
||||
return {
|
||||
baudRate: this.port.openOpt.baudRate,
|
||||
};
|
||||
}
|
||||
async flush() {
|
||||
debug(this.serialNumber, 'flush');
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
this.port.data = Buffer.alloc(0);
|
||||
}
|
||||
async drain() {
|
||||
debug(this.serialNumber, 'drain');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await this.writeOperation;
|
||||
await resolveNextTick();
|
||||
}
|
||||
}
|
||||
|
||||
export { CanceledError, MockBinding, MockPortBinding };
|
||||
73
node_modules/@serialport/binding-mock/dist/index.d.ts
generated
vendored
Normal file
73
node_modules/@serialport/binding-mock/dist/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/// <reference types="node" />
|
||||
|
||||
import { BindingInterface } from '@serialport/bindings-interface';
|
||||
import { BindingPortInterface } from '@serialport/bindings-interface';
|
||||
import { OpenOptions } from '@serialport/bindings-interface';
|
||||
import { PortInfo } from '@serialport/bindings-interface';
|
||||
import { PortStatus } from '@serialport/bindings-interface';
|
||||
import { SetOptions } from '@serialport/bindings-interface';
|
||||
import { UpdateOptions } from '@serialport/bindings-interface';
|
||||
|
||||
export declare class CanceledError extends Error {
|
||||
canceled: true;
|
||||
constructor(message: string);
|
||||
}
|
||||
|
||||
export declare interface CreatePortOptions {
|
||||
echo?: boolean;
|
||||
record?: boolean;
|
||||
readyData?: Buffer;
|
||||
maxReadSize?: number;
|
||||
manufacturer?: string;
|
||||
vendorId?: string;
|
||||
productId?: string;
|
||||
}
|
||||
|
||||
export declare const MockBinding: MockBindingInterface;
|
||||
|
||||
export declare interface MockBindingInterface extends BindingInterface<MockPortBinding> {
|
||||
reset(): void;
|
||||
createPort(path: string, opt?: CreatePortOptions): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mock bindings for pretend serialport access
|
||||
*/
|
||||
export declare class MockPortBinding implements BindingPortInterface {
|
||||
readonly openOptions: Required<OpenOptions>;
|
||||
readonly port: MockPortInternal;
|
||||
private pendingRead;
|
||||
lastWrite: null | Buffer;
|
||||
recording: Buffer;
|
||||
writeOperation: null | Promise<void>;
|
||||
isOpen: boolean;
|
||||
serialNumber?: string;
|
||||
constructor(port: MockPortInternal, openOptions: Required<OpenOptions>);
|
||||
emitData(data: Buffer | string): void;
|
||||
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>;
|
||||
}
|
||||
|
||||
export declare interface MockPortInternal {
|
||||
data: Buffer;
|
||||
echo: boolean;
|
||||
record: boolean;
|
||||
info: PortInfo;
|
||||
maxReadSize: number;
|
||||
readyData?: Buffer;
|
||||
openOpt?: OpenOptions;
|
||||
}
|
||||
|
||||
export { }
|
||||
281
node_modules/@serialport/binding-mock/dist/index.js
generated
vendored
Normal file
281
node_modules/@serialport/binding-mock/dist/index.js
generated
vendored
Normal file
@@ -0,0 +1,281 @@
|
||||
'use strict';
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
var debugFactory = require('debug');
|
||||
|
||||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
||||
|
||||
var debugFactory__default = /*#__PURE__*/_interopDefaultLegacy(debugFactory);
|
||||
|
||||
const debug = debugFactory__default["default"]('serialport/binding-mock');
|
||||
let ports = {};
|
||||
let serialNumber = 0;
|
||||
function resolveNextTick() {
|
||||
return new Promise(resolve => process.nextTick(() => resolve()));
|
||||
}
|
||||
class CanceledError extends Error {
|
||||
constructor(message) {
|
||||
super(message);
|
||||
this.canceled = true;
|
||||
}
|
||||
}
|
||||
const MockBinding = {
|
||||
reset() {
|
||||
ports = {};
|
||||
serialNumber = 0;
|
||||
},
|
||||
// Create a mock port
|
||||
createPort(path, options = {}) {
|
||||
serialNumber++;
|
||||
const optWithDefaults = Object.assign({ echo: false, record: false, manufacturer: 'The J5 Robotics Company', vendorId: undefined, productId: undefined, maxReadSize: 1024 }, options);
|
||||
ports[path] = {
|
||||
data: Buffer.alloc(0),
|
||||
echo: optWithDefaults.echo,
|
||||
record: optWithDefaults.record,
|
||||
readyData: optWithDefaults.readyData,
|
||||
maxReadSize: optWithDefaults.maxReadSize,
|
||||
info: {
|
||||
path,
|
||||
manufacturer: optWithDefaults.manufacturer,
|
||||
serialNumber: `${serialNumber}`,
|
||||
pnpId: undefined,
|
||||
locationId: undefined,
|
||||
vendorId: optWithDefaults.vendorId,
|
||||
productId: optWithDefaults.productId,
|
||||
},
|
||||
};
|
||||
debug(serialNumber, 'created port', JSON.stringify({ path, opt: options }));
|
||||
},
|
||||
async list() {
|
||||
debug(null, 'list');
|
||||
return Object.values(ports).map(port => port.info);
|
||||
},
|
||||
async open(options) {
|
||||
var _a;
|
||||
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');
|
||||
}
|
||||
const openOptions = Object.assign({ dataBits: 8, lock: true, stopBits: 1, parity: 'none', rtscts: false, xon: false, xoff: false, xany: false, hupcl: true }, options);
|
||||
const { path } = openOptions;
|
||||
debug(null, `open: opening path ${path}`);
|
||||
const port = ports[path];
|
||||
await resolveNextTick();
|
||||
if (!port) {
|
||||
throw new Error(`Port does not exist - please call MockBinding.createPort('${path}') first`);
|
||||
}
|
||||
const serialNumber = port.info.serialNumber;
|
||||
if ((_a = port.openOpt) === null || _a === void 0 ? void 0 : _a.lock) {
|
||||
debug(serialNumber, 'open: Port is locked cannot open');
|
||||
throw new Error('Port is locked cannot open');
|
||||
}
|
||||
debug(serialNumber, `open: opened path ${path}`);
|
||||
port.openOpt = Object.assign({}, openOptions);
|
||||
return new MockPortBinding(port, openOptions);
|
||||
},
|
||||
};
|
||||
/**
|
||||
* Mock bindings for pretend serialport access
|
||||
*/
|
||||
class MockPortBinding {
|
||||
constructor(port, openOptions) {
|
||||
this.port = port;
|
||||
this.openOptions = openOptions;
|
||||
this.pendingRead = null;
|
||||
this.isOpen = true;
|
||||
this.lastWrite = null;
|
||||
this.recording = Buffer.alloc(0);
|
||||
this.writeOperation = null; // in flight promise or null
|
||||
this.serialNumber = port.info.serialNumber;
|
||||
if (port.readyData) {
|
||||
const data = port.readyData;
|
||||
process.nextTick(() => {
|
||||
if (this.isOpen) {
|
||||
debug(this.serialNumber, 'emitting ready data');
|
||||
this.emitData(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
// Emit data on a mock port
|
||||
emitData(data) {
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port must be open to pretend to receive data');
|
||||
}
|
||||
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
||||
debug(this.serialNumber, 'emitting data - pending read:', Boolean(this.pendingRead));
|
||||
this.port.data = Buffer.concat([this.port.data, bufferData]);
|
||||
if (this.pendingRead) {
|
||||
process.nextTick(this.pendingRead);
|
||||
this.pendingRead = null;
|
||||
}
|
||||
}
|
||||
async close() {
|
||||
debug(this.serialNumber, 'close');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
const port = this.port;
|
||||
if (!port) {
|
||||
throw new Error('already closed');
|
||||
}
|
||||
port.openOpt = undefined;
|
||||
// reset data on close
|
||||
port.data = Buffer.alloc(0);
|
||||
debug(this.serialNumber, 'port is closed');
|
||||
this.serialNumber = undefined;
|
||||
this.isOpen = false;
|
||||
if (this.pendingRead) {
|
||||
this.pendingRead(new CanceledError('port is closed'));
|
||||
}
|
||||
}
|
||||
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}"`);
|
||||
}
|
||||
if (buffer.length < offset + length) {
|
||||
throw new Error('buffer is too small');
|
||||
}
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
debug(this.serialNumber, 'read', length, 'bytes');
|
||||
await resolveNextTick();
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new CanceledError('Read canceled');
|
||||
}
|
||||
if (this.port.data.length <= 0) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.pendingRead = err => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
this.read(buffer, offset, length).then(resolve, reject);
|
||||
};
|
||||
});
|
||||
}
|
||||
const lengthToRead = this.port.maxReadSize > length ? length : this.port.maxReadSize;
|
||||
const data = this.port.data.slice(0, lengthToRead);
|
||||
const bytesRead = data.copy(buffer, offset);
|
||||
this.port.data = this.port.data.slice(lengthToRead);
|
||||
debug(this.serialNumber, 'read', bytesRead, 'bytes');
|
||||
return { bytesRead, buffer };
|
||||
}
|
||||
async write(buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) {
|
||||
throw new TypeError('"buffer" is not a Buffer');
|
||||
}
|
||||
if (!this.isOpen || !this.port) {
|
||||
debug('write', 'error port is not open');
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
debug(this.serialNumber, 'write', buffer.length, 'bytes');
|
||||
if (this.writeOperation) {
|
||||
throw new Error('Overlapping writes are not supported and should be queued by the serialport object');
|
||||
}
|
||||
this.writeOperation = (async () => {
|
||||
await resolveNextTick();
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Write canceled');
|
||||
}
|
||||
const data = (this.lastWrite = Buffer.from(buffer)); // copy
|
||||
if (this.port.record) {
|
||||
this.recording = Buffer.concat([this.recording, data]);
|
||||
}
|
||||
if (this.port.echo) {
|
||||
process.nextTick(() => {
|
||||
if (this.isOpen) {
|
||||
this.emitData(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.writeOperation = null;
|
||||
debug(this.serialNumber, 'writing finished');
|
||||
})();
|
||||
return this.writeOperation;
|
||||
}
|
||||
async update(options) {
|
||||
if (typeof options !== 'object') {
|
||||
throw TypeError('"options" is not an object');
|
||||
}
|
||||
if (typeof options.baudRate !== 'number') {
|
||||
throw new TypeError('"options.baudRate" is not a number');
|
||||
}
|
||||
debug(this.serialNumber, 'update');
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
if (this.port.openOpt) {
|
||||
this.port.openOpt.baudRate = options.baudRate;
|
||||
}
|
||||
}
|
||||
async set(options) {
|
||||
if (typeof options !== 'object') {
|
||||
throw new TypeError('"options" is not an object');
|
||||
}
|
||||
debug(this.serialNumber, 'set');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
}
|
||||
async get() {
|
||||
debug(this.serialNumber, 'get');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
return {
|
||||
cts: true,
|
||||
dsr: false,
|
||||
dcd: false,
|
||||
};
|
||||
}
|
||||
async getBaudRate() {
|
||||
var _a;
|
||||
debug(this.serialNumber, 'getBaudRate');
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
if (!((_a = this.port.openOpt) === null || _a === void 0 ? void 0 : _a.baudRate)) {
|
||||
throw new Error('Internal Error');
|
||||
}
|
||||
return {
|
||||
baudRate: this.port.openOpt.baudRate,
|
||||
};
|
||||
}
|
||||
async flush() {
|
||||
debug(this.serialNumber, 'flush');
|
||||
if (!this.isOpen || !this.port) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await resolveNextTick();
|
||||
this.port.data = Buffer.alloc(0);
|
||||
}
|
||||
async drain() {
|
||||
debug(this.serialNumber, 'drain');
|
||||
if (!this.isOpen) {
|
||||
throw new Error('Port is not open');
|
||||
}
|
||||
await this.writeOperation;
|
||||
await resolveNextTick();
|
||||
}
|
||||
}
|
||||
|
||||
exports.CanceledError = CanceledError;
|
||||
exports.MockBinding = MockBinding;
|
||||
exports.MockPortBinding = MockPortBinding;
|
||||
58
node_modules/@serialport/binding-mock/package.json
generated
vendored
Normal file
58
node_modules/@serialport/binding-mock/package.json
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
{
|
||||
"name": "@serialport/binding-mock",
|
||||
"version": "10.2.2",
|
||||
"description": "The mock serialport bindings",
|
||||
"types": "./dist/index.d.ts",
|
||||
"main": "./dist/index.js",
|
||||
"exports": {
|
||||
"require": "./dist/index.js",
|
||||
"default": "./dist/index-esm.mjs"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12.0.0"
|
||||
},
|
||||
"repository": "git@github.com:serialport/binding-mock.git",
|
||||
"homepage": "https://github.com/serialport/binding-mock",
|
||||
"scripts": {
|
||||
"test": "mocha",
|
||||
"lint": "tsc && eslint lib/**/*.ts",
|
||||
"format": "eslint lib/**/*.ts --fix",
|
||||
"clean": "rm -rf dist-ts dist",
|
||||
"build": "npm run clean && tsc -p tsconfig-build.json && rollup -c && node -r esbuild-register bundle-types",
|
||||
"prepublishOnly": "npm run build",
|
||||
"semantic-release": "semantic-release"
|
||||
},
|
||||
"keywords": [
|
||||
"serialport-binding",
|
||||
"debug"
|
||||
],
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@microsoft/api-extractor": "7.19.4",
|
||||
"@types/chai": "4.3.0",
|
||||
"@types/mocha": "9.1.0",
|
||||
"@types/node": "17.0.15",
|
||||
"@typescript-eslint/eslint-plugin": "5.10.2",
|
||||
"@typescript-eslint/parser": "5.10.2",
|
||||
"chai": "4.3.6",
|
||||
"esbuild": "0.14.18",
|
||||
"esbuild-register": "3.3.2",
|
||||
"eslint": "8.8.0",
|
||||
"mocha": "9.2.0",
|
||||
"rollup": "2.67.0",
|
||||
"rollup-plugin-node-resolve": "5.2.0",
|
||||
"semantic-release": "19.0.2",
|
||||
"typescript": "4.5.5"
|
||||
},
|
||||
"mocha": {
|
||||
"bail": true,
|
||||
"require": [
|
||||
"esbuild-register"
|
||||
],
|
||||
"spec": "lib/**/*-test.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@serialport/bindings-interface": "^1.2.1",
|
||||
"debug": "^4.3.3"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user