forked from yaacov/node-modbus-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
117 lines (98 loc) · 4.25 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
declare namespace ModbusRTU {
interface IModbusRTU {
new(port?: any): IModbusRTU;
open(callback: Function): void;
close(callback: Function): void;
writeFC1(address: number, dataAddress: number, length: number, next: NodeStyleCallback<ReadCoilResult>): void;
writeFC2(address: number, dataAddress: number, length: number, next: NodeStyleCallback<ReadCoilResult>): void;
writeFC3(address: number, dataAddress: number, length: number, next: NodeStyleCallback<ReadRegisterResult>): void;
writeFC4(address: number, dataAddress: number, length: number, next: NodeStyleCallback<ReadRegisterResult>): void;
writeFC5(address: number, dataAddress: number, state: boolean, next: NodeStyleCallback<WriteCoilResult>): void;
writeFC6(address: number, dataAddress: number, value: number, next: NodeStyleCallback<WriteRegisterResult>): void;
writeFC15(address: number, dataAddress: number, states: Array<boolean>, next: NodeStyleCallback<WriteMultipleResult>): void;
writeFC16(address: number, dataAddress: number, values: Array<number>, next: NodeStyleCallback<WriteMultipleResult>): void;
// Connection shorthand API
connectRTU(path: string, options: SerialPortOptions, next: Function): void;
connectRTU(path: string, options: SerialPortOptions): Promise<void>;
connectTCP(ip: string, options: TcpPortOptions, next: Function): void;
connectTCP(ip: string, options: TcpPortOptions): Promise<void>;
connectTcpRTUBuffered(ip: string, options: TcpRTUPortOptions, next: Function): void;
connectTcpRTUBuffered(ip: string, options: TcpRTUPortOptions): Promise<void>;
connectTelnet(ip: string, options: TelnetPortOptions, next: Function): void;
connectTelnet(ip: string, options: TelnetPortOptions): Promise<void>;
connectC701(ip: string, options: C701PortOptions, next: Function): void;
connectC701(ip: string, options: C701PortOptions): Promise<void>;
connectRTUBuffered(path: string, options: SerialPortOptions, next: Function): void;
connectRTUBuffered(path: string, options: SerialPortOptions): Promise<void>;
connectAsciiSerial(path: string, options: SerialPortOptions, next: Function): void;
connectAsciiSerial(path: string, options: SerialPortOptions): Promise<void>;
// Promise API
setID(id: number): void;
getID(): number;
setTimeout(duration: number): void;
getTimeout(): number;
readCoils(dataAddress: number, length: number): Promise<ReadCoilResult>;
readDiscreteInputs(dataAddress: number, length: number): Promise<ReadCoilResult>;
readHoldingRegisters(dataAddress: number, length: number): Promise<ReadRegisterResult>;
readInputRegisters(dataAddress: number, length: number): Promise<ReadRegisterResult>;
writeCoil(dataAddress: number, state: boolean): Promise<WriteCoilResult>;
writeCoils(dataAddress: number, states: Array<boolean>): Promise<WriteMultipleResult>;
writeRegister(dataAddress: number, value: number): Promise<WriteRegisterResult>;
writeRegisters(dataAddress: number, values: Array<number>): Promise<WriteMultipleResult>; // 16
}
interface NodeStyleCallback<T> {
(err: NodeJS.ErrnoException, param: T): void;
}
interface ReadCoilResult {
data: Array<boolean>;
buffer: Buffer;
}
interface ReadRegisterResult {
data: Array<number>;
buffer: Buffer;
}
interface WriteCoilResult {
address: number;
state: boolean;
}
interface WriteRegisterResult {
address: number;
value: number;
}
interface WriteMultipleResult {
address: number;
length: number;
}
interface SerialPortOptions {
baudRate?: number;
dataBits?: number;
stopBits?: number;
parity?: 'none' | 'even' | 'mark' | 'odd' | 'space';
rtscts?: boolean;
xon?: boolean;
xoff?: boolean;
xany?: boolean;
flowControl?: boolean | Array<string>;
bufferSize?: number;
parser?: any;
platformOptions?: SerialPortUnixPlatformOptions;
}
interface SerialPortUnixPlatformOptions {
vmin?: number;
vtime?: number;
}
interface TcpPortOptions {
port?: number;
}
interface TcpRTUPortOptions {
port?: number;
}
interface TelnetPortOptions {
port?: number;
}
interface C701PortOptions {
port?: number;
}
}
declare var ModbusRTU: ModbusRTU.IModbusRTU;
export = ModbusRTU ;