forked from yaacov/node-modbus-serial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModbusRTU.d.ts
132 lines (111 loc) · 4.72 KB
/
ModbusRTU.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import {Socket} from 'net';
export class ModbusRTU {
constructor(port?: any);
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>;
connectUDP(ip: string, options: UdpPortOptions, next: Function): void;
connectUDP(ip: string, options: UdpPortOptions): 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>;
connectAsciiTelnet(ip: string, options: TelnetPortOptions, next: Function): void;
connectAsciiTelnet(ip: string, options: TelnetPortOptions): Promise<void>;
connectSocket(socket: Socket, options: TcpPortOptions, next: Function): void;
connectSocket(socket: Socket, options: TcpPortOptions): 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
isOpen: boolean;
}
export interface NodeStyleCallback<T> {
(err: NodeJS.ErrnoException, param: T): void;
}
export interface ReadCoilResult {
data: Array<boolean>;
buffer: Buffer;
}
export interface ReadRegisterResult {
data: Array<number>;
buffer: Buffer;
}
export interface WriteCoilResult {
address: number;
state: boolean;
}
export interface WriteRegisterResult {
address: number;
value: number;
}
export interface WriteMultipleResult {
address: number;
length: number;
}
export 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;
}
export interface SerialPortUnixPlatformOptions {
vmin?: number;
vtime?: number;
}
export interface TcpPortOptions {
port?: number;
localAddress?: string;
family?: number;
}
export interface UdpPortOptions {
port?: number;
localAddress?: string;
family?: number;
}
export interface TcpRTUPortOptions {
port?: number;
localAddress?: string;
family?: number;
}
export interface TelnetPortOptions {
port?: number;
}
export interface C701PortOptions {
port?: number;
}