File tree 4 files changed +28
-5
lines changed
4 files changed +28
-5
lines changed Original file line number Diff line number Diff line change
1
+ import * as events from 'events' ;
2
+ import { SerialPortOpenOptions } from "serialport"
3
+ import { FCallback , IServiceVector } from './ServerTCP' ;
4
+ import { ErrorCallback } from '@serialport/stream' ;
5
+
6
+ export class ServerSerial extends events . EventEmitter {
7
+ constructor ( vector : IServiceVector , options : IServerSerialOptions ) ;
8
+ close ( cb : FCallback ) : void ;
9
+ }
10
+
11
+ type IServerSerialOptions = SerialPortOpenOptions < any > & {
12
+ debug ?: boolean ,
13
+ unitID ?: number ,
14
+ openCallback ?: ErrorCallback
15
+ }
16
+
17
+ export declare interface ServerSerial {
18
+ on ( event : 'socketError' , listener : FCallback ) : this;
19
+ on ( event : 'error' , listener : FCallback ) : this;
20
+ on ( event : 'initialized' , listener : FCallback ) : this;
21
+ }
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ export class ServerTCP extends events.EventEmitter {
5
5
close ( cb : FCallback ) : void ;
6
6
}
7
7
8
- interface IServiceVector {
8
+ export interface IServiceVector {
9
9
getCoil ?:
10
10
( ( addr : number , unitID : number , cb : FCallbackVal < boolean > ) => void ) |
11
11
( ( addr : number , unitID : number ) => Promise < boolean > ) |
@@ -58,5 +58,5 @@ export declare interface ServerTCP {
58
58
on ( event : 'initialized' , listener : FCallback ) : this;
59
59
}
60
60
61
- type FCallbackVal < T > = ( err : Error | null , value : T ) => void ;
62
- type FCallback = ( err : Error | null ) => void ;
61
+ export type FCallbackVal < T > = ( err : Error | null , value : T ) => void ;
62
+ export type FCallback = ( err : Error | null ) => void ;
Original file line number Diff line number Diff line change 1
1
import { ModbusRTU } from "./ModbusRTU" ;
2
2
export * from "./ServerTCP" ;
3
+ export * from "./ServerSerial" ;
3
4
4
5
export default ModbusRTU ;
Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ class ServerSerial extends EventEmitter {
237
237
const optionsWithBindingandSerialport = Object . assign ( { } , serialportOptions , optionsWithBinding ) ;
238
238
239
239
// create a serial server
240
- modbus . _serverPath = new SerialPort ( optionsWithBindingandSerialport ) ;
240
+ modbus . _serverPath = new SerialPort ( optionsWithBindingandSerialport , options . openCallback ) ;
241
241
242
242
// create a serial server with a timeout parser
243
243
modbus . _server = modbus . _serverPath . pipe ( new ServerSerialPipeHandler ( optionsWithSerialPortTimeoutParser ) ) ;
@@ -253,7 +253,7 @@ class ServerSerial extends EventEmitter {
253
253
// remember open sockets
254
254
modbus . socks = new Map ( ) ;
255
255
256
- modbus . _server . on ( "open" , function ( ) {
256
+ modbus . _serverPath . on ( "open" , function ( ) {
257
257
modbus . socks . set ( modbus . _server , 0 ) ;
258
258
259
259
modbusSerialDebug ( {
@@ -270,6 +270,7 @@ class ServerSerial extends EventEmitter {
270
270
modbus . socks . delete ( modbus . _server ) ;
271
271
} ) ;
272
272
273
+ modbus . emit ( "initialized" ) ;
273
274
} ) ;
274
275
275
276
modbus . _server . on ( "data" , function ( data ) {
You can’t perform that action at this time.
0 commit comments