mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 23:07:06 +00:00
Merge pull request #30120 from ondrowan/upgrade-serialport-version
Upgrade serialport version to 7.0
This commit is contained in:
Vendored
+13
-3
@@ -1,4 +1,4 @@
|
||||
// Type definitions for serialport 6.0
|
||||
// Type definitions for serialport 7.0
|
||||
// Project: https://github.com/EmergingTechnologyAdvisors/node-serialport
|
||||
// Definitions by: Jeremy Foster <https://github.com/codefoster>
|
||||
// Andrew Pearson <https://github.com/apearson>
|
||||
@@ -40,7 +40,7 @@ declare class SerialPort extends Stream.Duplex {
|
||||
|
||||
static Binding: SerialPort.BaseBinding;
|
||||
|
||||
static list(): Promise<any>;
|
||||
static list(callback?: SerialPort.ListCallback): Promise<SerialPort.PortInfo[]>;
|
||||
}
|
||||
|
||||
declare namespace SerialPort {
|
||||
@@ -77,6 +77,16 @@ declare namespace SerialPort {
|
||||
dsr?: boolean;
|
||||
dtr?: boolean;
|
||||
rts?: boolean;
|
||||
}
|
||||
|
||||
interface PortInfo {
|
||||
comName: string;
|
||||
manufacturer?: string;
|
||||
serialNumber?: string;
|
||||
pnpId?: string;
|
||||
locationId?: string;
|
||||
productId?: string;
|
||||
vendorId?: string;
|
||||
}
|
||||
|
||||
namespace parsers {
|
||||
@@ -119,7 +129,7 @@ declare namespace SerialPort {
|
||||
get(): Promise<any>;
|
||||
flush(): Promise<any>;
|
||||
drain(): Promise<any>;
|
||||
static list(): Promise<any>;
|
||||
static list(): Promise<PortInfo[]>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -126,3 +126,14 @@ function test_properties() {
|
||||
const isOpen: boolean = port.isOpen;
|
||||
const path: string = port.path;
|
||||
}
|
||||
|
||||
function test_list_ports_promise() {
|
||||
const ports = SerialPort
|
||||
.list()
|
||||
.then((ports: any) => {})
|
||||
.catch((err: Error) => {});
|
||||
}
|
||||
|
||||
function test_list_ports_callback() {
|
||||
const ports = SerialPort.list((error: Error, port: any[]) => {});
|
||||
}
|
||||
|
||||
Vendored
+126
@@ -0,0 +1,126 @@
|
||||
// Type definitions for serialport 6.0
|
||||
// Project: https://github.com/EmergingTechnologyAdvisors/node-serialport
|
||||
// Definitions by: Jeremy Foster <https://github.com/codefoster>
|
||||
// Andrew Pearson <https://github.com/apearson>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/// <reference types="node" />
|
||||
|
||||
import * as Stream from 'stream';
|
||||
|
||||
declare class SerialPort extends Stream.Duplex {
|
||||
constructor(path: string, callback?: SerialPort.ErrorCallback);
|
||||
constructor(path: string, options?: SerialPort.OpenOptions, callback?: SerialPort.ErrorCallback);
|
||||
|
||||
readonly baudRate: number;
|
||||
readonly binding: SerialPort.BaseBinding;
|
||||
readonly isOpen: boolean;
|
||||
readonly path: string;
|
||||
|
||||
open(callback?: SerialPort.ErrorCallback): void;
|
||||
update(options: SerialPort.UpdateOptions, callback?: SerialPort.ErrorCallback): void;
|
||||
|
||||
write(data: string| number[] | Buffer, callback?: (error: any, bytesWritten: number) => void): boolean;
|
||||
write(buffer: string| number[] | Buffer, encoding?: 'ascii'|'utf8'|'utf16le'|'ucs2'|'base64'|'binary'|'hex', callback?: (error: any, bytesWritten: number) => void): boolean;
|
||||
|
||||
read(size?: number): string | Buffer | null;
|
||||
|
||||
close(callback?: (error: Error) => void): void;
|
||||
|
||||
set(options: SerialPort.SetOptions, callback?: SerialPort.ErrorCallback): void;
|
||||
get(callback?: SerialPort.ModemBitsCallback): void;
|
||||
|
||||
flush(callback?: SerialPort.ErrorCallback): void;
|
||||
drain(callback?: SerialPort.ErrorCallback): void;
|
||||
|
||||
pause(): this;
|
||||
resume(): this;
|
||||
|
||||
on(event: string, callback: (data?: any) => void): this;
|
||||
|
||||
static Binding: SerialPort.BaseBinding;
|
||||
|
||||
static list(): Promise<any>;
|
||||
}
|
||||
|
||||
declare namespace SerialPort {
|
||||
// Callbacks Type Defs
|
||||
type ErrorCallback = (error: Error) => void;
|
||||
type ModemBitsCallback = (error: Error, status: {cts: boolean, dsr: boolean, dcd: boolean }) => void;
|
||||
type ListCallback = (error: Error, port: any[]) => void;
|
||||
|
||||
// Options Type Defs
|
||||
interface OpenOptions {
|
||||
autoOpen?: boolean;
|
||||
baudRate?: 115200|57600|38400|19200|9600|4800|2400|1800|1200|600|300|200|150|134|110|75|50|number;
|
||||
dataBits?: 8|7|6|5;
|
||||
highWaterMark?: number;
|
||||
lock?: boolean;
|
||||
stopBits?: 1|2;
|
||||
parity?: 'none'|'even'|'mark'|'odd'|'space';
|
||||
rtscts?: boolean;
|
||||
xon?: boolean;
|
||||
xoff?: boolean;
|
||||
xany?: boolean;
|
||||
binding?: BaseBinding;
|
||||
bindingOptions?: {
|
||||
vmin?: number;
|
||||
vtime?: number;
|
||||
};
|
||||
}
|
||||
interface UpdateOptions {
|
||||
baudRate?: 115200|57600|38400|19200|9600|4800|2400|1800|1200|600|300|200|150|134|110|75|50|number;
|
||||
}
|
||||
interface SetOptions {
|
||||
brk?: boolean;
|
||||
cts?: boolean;
|
||||
dsr?: boolean;
|
||||
dtr?: boolean;
|
||||
rts?: boolean;
|
||||
}
|
||||
|
||||
namespace parsers {
|
||||
class ByteLength extends Stream.Transform {
|
||||
constructor(options: {length: number});
|
||||
}
|
||||
class CCTalk extends Stream.Transform {
|
||||
constructor();
|
||||
}
|
||||
class Delimiter extends Stream.Transform {
|
||||
constructor(options: {delimiter: string | Buffer | number[], includeDelimiter?: boolean});
|
||||
}
|
||||
class Readline extends Delimiter {
|
||||
constructor(options: {delimiter: string | Buffer | number[], encoding?: 'ascii'|'utf8'|'utf16le'|'ucs2'|'base64'|'binary'|'hex'});
|
||||
}
|
||||
class Ready extends Stream.Transform {
|
||||
constructor(options: {data: string | Buffer | number[]});
|
||||
}
|
||||
class Regex extends Stream.Transform {
|
||||
constructor(options: {regex: RegExp});
|
||||
}
|
||||
}
|
||||
|
||||
// Binding Type Defs
|
||||
type win32Binding = BaseBinding;
|
||||
type darwinBinding = BaseBinding;
|
||||
type linuxBinding = BaseBinding;
|
||||
|
||||
// Binding Type Def
|
||||
class BaseBinding {
|
||||
constructor(options: any);
|
||||
|
||||
open(path: string, options: OpenOptions): Promise<any>;
|
||||
close(): Promise<any>;
|
||||
|
||||
read(data: Buffer, offset: number, length: number): Promise<any>;
|
||||
write(data: Buffer): Promise<any>;
|
||||
update(options?: UpdateOptions): Promise<any>;
|
||||
set(options?: SetOptions): Promise<any>;
|
||||
get(): Promise<any>;
|
||||
flush(): Promise<any>;
|
||||
drain(): Promise<any>;
|
||||
static list(): Promise<any>;
|
||||
}
|
||||
}
|
||||
|
||||
export = SerialPort;
|
||||
@@ -0,0 +1,128 @@
|
||||
// Tests taken from documentation samples.
|
||||
|
||||
import SerialPort = require('serialport');
|
||||
|
||||
function test_basic_connect() {
|
||||
const port = new SerialPort('');
|
||||
}
|
||||
|
||||
function test_connect_config() {
|
||||
const port1 = new SerialPort('', {
|
||||
}, (error: Error) => {});
|
||||
|
||||
const port4 = new SerialPort('', {
|
||||
autoOpen: false,
|
||||
lock: false,
|
||||
baudRate: 115200,
|
||||
dataBits: 5,
|
||||
stopBits: 2,
|
||||
parity: 'odd',
|
||||
rtscts: true,
|
||||
xon: true,
|
||||
xoff: true,
|
||||
highWaterMark: 1024,
|
||||
bindingOptions: {
|
||||
vmin: 1,
|
||||
vtime: 1
|
||||
}
|
||||
}, (error: Error) => {});
|
||||
}
|
||||
|
||||
function test_open() {
|
||||
const port = new SerialPort('');
|
||||
port.open(() => {});
|
||||
}
|
||||
|
||||
function test_update() {
|
||||
const port = new SerialPort('');
|
||||
port.update({baudRate: 57600});
|
||||
}
|
||||
|
||||
function test_write() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
port.write('test', (error: Error) => {});
|
||||
port.write('test', 'utf8', (error: Error) => {});
|
||||
}
|
||||
|
||||
function test_read() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
const data = port.read(8);
|
||||
}
|
||||
|
||||
function test_close() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
port.close((error: Error) => {});
|
||||
}
|
||||
|
||||
function test_set() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
port.set({}, (error: Error) => {});
|
||||
}
|
||||
|
||||
function test_get() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
port.get((error, status) => {});
|
||||
}
|
||||
|
||||
function test_flush() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
port.flush((error: Error) => {});
|
||||
}
|
||||
|
||||
function test_drain() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
port.drain((error: Error) => {});
|
||||
}
|
||||
|
||||
function test_pause_resume() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
const pauseItem: SerialPort = port.pause();
|
||||
const resumeItem: SerialPort = port.resume();
|
||||
}
|
||||
|
||||
function test_on_events() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
const onItem: SerialPort = port.on('event', (data: any) => {});
|
||||
}
|
||||
|
||||
function test_binding() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
const bindingItem: SerialPort.BaseBinding = SerialPort.Binding;
|
||||
}
|
||||
|
||||
function test_parsers() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
const ByteLengthParser = new SerialPort.parsers.ByteLength({length: 8});
|
||||
const CCTalkParser = new SerialPort.parsers.CCTalk();
|
||||
const DelimiterParser = new SerialPort.parsers.Delimiter({ delimiter: Buffer.from('EOL') });
|
||||
const ReadlineParser = new SerialPort.parsers.Readline({ delimiter: '\r\n' });
|
||||
const ReadyParser = new SerialPort.parsers.Ready({ data: 'READY' });
|
||||
const RegexParser = new SerialPort.parsers.Regex({regex: /.*/});
|
||||
|
||||
port.pipe(ByteLengthParser);
|
||||
port.pipe(CCTalkParser);
|
||||
port.pipe(DelimiterParser);
|
||||
port.pipe(ReadlineParser);
|
||||
port.pipe(ReadyParser);
|
||||
port.pipe(RegexParser);
|
||||
}
|
||||
|
||||
function test_properties() {
|
||||
const port = new SerialPort('');
|
||||
|
||||
const baudRate: number = port.baudRate;
|
||||
const binding: SerialPort.BaseBinding = port.binding;
|
||||
const isOpen: boolean = port.isOpen;
|
||||
const path: string = port.path;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../../",
|
||||
"typeRoots": [
|
||||
"../../"
|
||||
],
|
||||
"paths": {
|
||||
"serialport": [
|
||||
"serialport/v6"
|
||||
]
|
||||
},
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"serialport-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user