import { Socket, SocketConstructorOpts, TcpSocketConnectOpts } from 'net'; import { TestPort } from "./TestPort"; /** * Subset of `serialport` `SerialPort.list()` entries — defined here so typings do not require * `@serialport/bindings-cpp` at install time when using `npm install --no-optional`. Values from * `getPorts()` are compatible with `PortInfo` when `serialport` is installed. */ export interface ModbusSerialPortListEntry { path: string; manufacturer?: string; serialNumber?: string; pnpId?: string; locationId?: string; productId?: string; vendorId?: string; } export class ModbusRTU { constructor(port?: any); static TestPort: typeof TestPort static getPorts(): Promise open(callback?: Function): void; close(callback?: Function): void; destroy(callback?: Function): void; writeFC1(address: number, dataAddress: number, length: number, next: NodeStyleCallback): void; writeFC2(address: number, dataAddress: number, length: number, next: NodeStyleCallback): void; writeFC3(address: number, dataAddress: number, length: number, next: NodeStyleCallback): void; writeFC4(address: number, dataAddress: number, length: number, next: NodeStyleCallback): void; writeFC5(address: number, dataAddress: number, state: boolean, next: NodeStyleCallback): void; writeFC6(address: number, dataAddress: number, value: number, next: NodeStyleCallback): void; writeFC15(address: number, dataAddress: number, states: Array, next: NodeStyleCallback): void; writeFC16(address: number, dataAddress: number, values: Array, next: NodeStyleCallback): void; writeFC22(address: number, dataAddress: number, andMask: number, orMask: number, next: NodeStyleCallback): void; writeFC23(address: number, startingReadAddress: number, numReadRegisters: number, startingWriteAddress: number, numWriteRegisters: number, valuesToWrite: Array | Buffer, next: NodeStyleCallback): void; writeCustomFC(address: number, functionCode: number, data: Array, next: NodeStyleCallback): void; // Connection shorthand API connectRTU(path: string, options: SerialPortOptions, next: Function): void; connectRTU(path: string, options: SerialPortOptions): Promise; connectTCP(ip: string, options: TcpPortOptions, next: Function): void; connectTCP(ip: string, options: TcpPortOptions): Promise; connectUDP(ip: string, options: UdpPortOptions, next: Function): void; connectUDP(ip: string, options: UdpPortOptions): Promise; connectTcpRTUBuffered(ip: string, options: TcpRTUPortOptions, next: Function): void; connectTcpRTUBuffered(ip: string, options: TcpRTUPortOptions): Promise; connectTelnet(ip: string, options: TelnetPortOptions, next: Function): void; connectTelnet(ip: string, options: TelnetPortOptions): Promise; connectC701(ip: string, options: C701PortOptions, next: Function): void; connectC701(ip: string, options: C701PortOptions): Promise; connectRTUBuffered(path: string, options: SerialPortOptions, next: Function): void; connectRTUBuffered(path: string, options: SerialPortOptions): Promise; connectAsciiSerial(path: string, options: SerialPortOptions, next: Function): void; connectAsciiSerial(path: string, options: SerialPortOptions): Promise; linkTCP(socket: Socket, options: TcpPortOptions, next: Function): void; linkTCP(socket: Socket, options: TcpPortOptions): Promise; linkTcpRTUBuffered(socket: Socket, options: TcpRTUPortOptions, next: Function): void; linkTcpRTUBuffered(socket: Socket, options: TcpRTUPortOptions): Promise; linkTelnet(socket: Socket, options: TelnetPortOptions, next: Function): void; linkTelnet(socket: Socket, options: TelnetPortOptions): Promise; connectRTUSocket(socket: Socket, next: Function): void; connectRTUSocket(socket: Socket): Promise; // Promise API setID(id: number): void; getID(): number; setTimeout(duration: number): void; getTimeout(): number; readCoils(dataAddress: number, length: number): Promise; readDiscreteInputs(dataAddress: number, length: number): Promise; readHoldingRegisters(dataAddress: number, length: number): Promise; readRegistersEnron(dataAddress: number, length: number): Promise; readInputRegisters(dataAddress: number, length: number): Promise; writeCoil(dataAddress: number, state: boolean): Promise; writeCoils(dataAddress: number, states: Array): Promise; writeRegister(dataAddress: number, value: number): Promise; writeRegisterEnron(dataAddress: number, value: number): Promise; writeRegisters(dataAddress: number, values: Array | Buffer): Promise; // 16 maskWriteRegister(dataAddress: number, andMask: number, orMask: number): Promise; customFunction(functionCode: number, data: Array): Promise; on(event: 'close', listener: () => unknown): this; on(event: 'error', listener: (error: unknown) => unknown): this; readDeviceIdentification(deviceIdCode: number, objectId: number): Promise; reportServerID(deviceIdCode: number): Promise; isOpen: boolean; } export interface NodeStyleCallback { (err: NodeJS.ErrnoException, param: T): void; } export interface CustomFunctionResult { data: Array; buffer: Buffer; } export interface ReadCoilResult { data: Array; buffer: Buffer; } export interface ReadRegisterResult { data: Array; 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 WriteMaskRegisterResult { address: number; andMask: number; orMask: number; } export interface ReadDeviceIdentificationResult { data: string[]; conformityLevel: number; } export interface ReportServerIDResult { serverId: number; running: boolean; additionalData: Buffer; } 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; bufferSize?: number; parser?: any; platformOptions?: SerialPortUnixPlatformOptions; } export interface SerialPortUnixPlatformOptions { vmin?: number; vtime?: number; } export interface TcpPortOptions extends TcpSocketConnectOpts { port: number; localAddress?: string; family?: number; ip?: string; timeout?: number; socket?: Socket; socketOpts?: SocketConstructorOpts; } export interface UdpPortOptions { port?: number; localAddress?: string; family?: number; } export interface TcpRTUPortOptions { port?: number; localAddress?: string; family?: number; } export interface TelnetPortOptions { port?: number; timeout?: number; socket?: Socket; } export interface C701PortOptions { port?: number; }