-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
better error recovery from loss of comms
- Loading branch information
1 parent
b9ac26e
commit 1a2c078
Showing
5 changed files
with
55 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,78 @@ | ||
// @flow | ||
|
||
import {Observable, ReplaySubject} from 'rx-lite'; | ||
import {opcua, nextSession, handleError} from './data/opcua'; | ||
import {opcua, sessions, handleError} from './data/opcua'; | ||
|
||
|
||
|
||
var sub = new ReplaySubject(1); | ||
|
||
nextSession().subscribe(session=>sub.onNext( | ||
new opcua.ClientSubscription(session,{ | ||
requestedPublishingInterval: 1000, | ||
requestedLifetimeCount: 10, | ||
requestedMaxKeepAliveCount: 2, | ||
maxNotificationsPerPublish: 10, | ||
publishingEnabled: true, | ||
priority: 10 | ||
}) | ||
)); | ||
sessions.subscribe(session=>{ | ||
console.log('session ...', session); | ||
if(session) { | ||
sub.onNext( | ||
new opcua.ClientSubscription(session,{ | ||
requestedPublishingInterval: 1000, | ||
requestedLifetimeCount: 10, | ||
requestedMaxKeepAliveCount: 2, | ||
maxNotificationsPerPublish: 10, | ||
publishingEnabled: true, | ||
priority: 10 | ||
}) | ||
); | ||
} else { | ||
sub.onNext(null); | ||
} | ||
}); | ||
|
||
|
||
class NodeSocket { | ||
destroy: Function; | ||
constructor(nodeId : string, io : any){ | ||
const _this=this; | ||
const timer = sub.select(subscription => Observable.create((obs)=> { | ||
console.log('erewego', nodeId, sub); | ||
try { | ||
|
||
// install monitored item | ||
//console.log('monitoring', nodeId); | ||
let monitoredItem = subscription.monitor({ | ||
nodeId: opcua.resolveNodeId(nodeId.split(':').slice(1).join()), | ||
attributeId: opcua.AttributeIds[nodeId.split(':')[0]] | ||
}, | ||
{ | ||
samplingInterval: 1000, | ||
discardOldest: true, | ||
queueSize: 10 | ||
}, | ||
opcua.read_service.TimestampsToReturn.Both | ||
); | ||
console.log("-monitoring", subscription.subscriptionId, nodeId); | ||
const timer = sub.select(subscription => Observable.create( | ||
obs=> { | ||
if(subscription) { | ||
try { | ||
|
||
// install monitored item | ||
//console.log('monitoring', nodeId); | ||
let monitoredItem = subscription.monitor({ | ||
nodeId: opcua.resolveNodeId(nodeId.split(':').slice(1).join()), | ||
attributeId: opcua.AttributeIds[nodeId.split(':')[0]] | ||
}, | ||
{ | ||
samplingInterval: 1000, | ||
discardOldest: true, | ||
queueSize: 10 | ||
}, | ||
opcua.read_service.TimestampsToReturn.Both | ||
); | ||
|
||
monitoredItem.on("changed",function(dataValue){ | ||
obs.onNext(dataValue); | ||
}); | ||
console.log("-monitoring", subscription.subscriptionId, nodeId); | ||
|
||
monitoredItem.on("changed",function(dataValue){ | ||
obs.onNext(dataValue); | ||
}); | ||
} catch(ex) { | ||
console.log("caught error", ex); | ||
obs.onError(ex); | ||
} | ||
return ()=>{}; //subscription.terminate(); | ||
} )).switch().subscribe(x => { | ||
} catch(ex) { | ||
console.log("caught error", ex); | ||
obs.onError(ex); | ||
} | ||
} else { | ||
obs.onNext(null); | ||
} | ||
return ()=>{}; | ||
} | ||
)).switch().subscribe(x => { | ||
_this.lastValue = { | ||
nodeId: nodeId, | ||
value: x | ||
}; | ||
|
||
}; | ||
io.to(nodeId).emit('update', _this.lastValue ); | ||
}); | ||
|
||
this.destroy = ()=> timer.dispose(); | ||
} | ||
|
||
} | ||
|
||
export default NodeSocket; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters