Add more definitions based on documentation.

This commit is contained in:
jgillick
2016-06-26 23:53:58 -07:00
parent 2743ece76d
commit 19ccfe97a5
2 changed files with 44 additions and 9 deletions

View File

@@ -8,8 +8,31 @@
import * as serialport from 'serialport';
this.port = new serialport.SerialPort("", {
baudrate: 0,
disconnectedCallback: function () { },
parser: serialport.parsers.readline("\n")
});
function test_basic_connect() {
let port = new serialport.SerialPort("");
}
function test_connect_config() {
let port = new serialport.SerialPort("", {
baudrate: 0,
disconnectedCallback: function () { },
parser: serialport.parsers.readline("\n")
});
}
function test_write() {
let port = new serialport.SerialPort("");
port.write('main screen turn on', (err, bytesWritten) => {
});
}
function test_events() {
let port = new serialport.SerialPort("");
port.on('open', function () { });
}
function test_list_ports() {
serialport.list( (err:string, ports:serialport.portConfig[]) => {
});
}

View File

@@ -1,19 +1,20 @@
// Type definitions for serialport
// Project: https://github.com/EmergingTechnologyAdvisors/node-serialport
// Definitions by: Jeremy Foster <https://github.com/codefoster>
// Definitions by: Jeremy Foster <https://github.com/codefoster>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'serialport' {
module parsers {
function readline(delimiter: string):void;
function raw(emitter:any, buffer:string):void
}
export class SerialPort {
constructor(path: string, options?: Object, openImmediately?: boolean, callback?: () => {})
constructor(path: string, options?: Object, openImmediately?: boolean, callback?: (err:string) => void)
isOpen: boolean;
on(event: string, callback?: (data?:any) => void):void;
open(callback?: () => void):void;
write(buffer: any, callback?: () => void):void
write(buffer: any, callback?: (err:string, bytesWritten:number) => void):void
pause():void;
resume():void;
disconnected(err: Error):void;
@@ -22,7 +23,18 @@ declare module 'serialport' {
set(options: setOptions, callback: () => void):void;
drain(callback?: () => void):void;
update(options: updateOptions, callback?: () => void):void;
list(callback?: () => void):void;
}
export function list(callback: (err: string, ports:portConfig[]) => void): void;
interface portConfig {
comName: string,
manufacturer: string,
serialNumber: string,
pnpId: string,
locationId: string,
vendorId: string,
productId: string
}
interface setOptions {