@@ -91,7 +91,8 @@ export class SequentIO extends i2cDeviceBase {
91
91
protected ensureIOChannels ( label , type , arr , count ) {
92
92
try {
93
93
for ( let i = 1 ; i <= count ; i ++ ) {
94
- if ( typeof arr . find ( elem => elem . id === i ) === 'undefined' ) arr . push ( { id : i , name : `${ label } #${ i } ` , type : type , enabled : false } ) ;
94
+ let ch = arr . find ( elem => elem . id === i ) ;
95
+ if ( typeof ch === 'undefined' ) arr . push ( { id : i , name : `${ label } #${ i } ` , type : type , enabled : false } ) ;
95
96
}
96
97
arr . sort ( ( a , b ) => { return a . id - b . id } ) ;
97
98
arr . length = count ;
@@ -120,6 +121,19 @@ export class SequentIO extends i2cDeviceBase {
120
121
public get out0_10 ( ) : any [ ] { return typeof this . outputs . out0_10 === 'undefined' ? this . outputs . out0_10 = [ ] : this . outputs . out0_10 ; }
121
122
public get outDrain ( ) : any [ ] { return typeof this . outputs . outDrain === 'undefined' ? this . outputs . outDrain = [ ] : this . outputs . outDrain ; }
122
123
public get calibration ( ) : any { return typeof this . calibration === 'undefined' ? this . info . calibration = { } : this . info . calibration ; }
124
+ protected async initOutputs ( outputs : any [ ] , fn : ( ord : number , val : number ) => void ) {
125
+ if ( typeof fn === 'function' ) {
126
+ for ( let i = 0 ; i < outputs . length ; i ++ ) {
127
+ let o = outputs [ i ] ;
128
+ if ( o . enabled === true ) {
129
+ if ( typeof o . value === 'number' ) {
130
+ console . log ( o ) ;
131
+ await fn . apply ( this , [ o . id , o . value ] ) ;
132
+ }
133
+ }
134
+ }
135
+ }
136
+ }
123
137
protected packRS485Port ( port ) : Buffer {
124
138
let buffer = Buffer . from ( [ 0 , 0 , 0 , 0 , 0 ] ) ;
125
139
buffer . writeUInt16LE ( port . baud & 0x00FFFF , 0 ) ;
@@ -442,6 +456,8 @@ export class SequentMegaIND extends SequentIO {
442
456
this . ensureIOChannels ( 'OUT 4-20' , '420OUT' , this . out4_20 , 4 ) ;
443
457
this . ensureIOChannels ( 'IN Digital' , 'DIN' , this . inDigital , 4 ) ;
444
458
this . ensureIOChannels ( 'OUT Open Drain' , 'ODOUT' , this . outDrain , 4 ) ;
459
+ await this . initOutputs ( this . out0_10 , this . set0_10Output ) ;
460
+ await this . initOutputs ( this . out4_20 , this . set4_20Output ) ;
445
461
if ( this . device . isActive ) await this . getRS485Port ( ) ;
446
462
return Promise . resolve ( true ) ;
447
463
}
@@ -889,6 +905,8 @@ export class SequentMegaBAS extends SequentIO {
889
905
// Set up all the I/O channels. We want to create a values data structure for all potential inputs and outputs.
890
906
this . ensureIOChannels ( 'IN 0-10' , 'AIN' , this . in0_10 , 8 ) ;
891
907
this . ensureIOChannels ( 'OUT 0-10' , 'AOUT' , this . out0_10 , 4 ) ;
908
+ await this . initOutputs ( this . out0_10 , this . set0_10Output ) ;
909
+
892
910
if ( this . device . isActive ) await this . getRS485Port ( ) ;
893
911
return Promise . resolve ( true ) ;
894
912
}
0 commit comments