Hi,
we are trying to use the QuickOPC together with the PowerShell to establish a simple data logger. The script gets all Nodes that are linked to the top Node, defined in the parameter. Then the array for the EasyUAMonitoredItemArguments is established.
That works all fine, the subscription are established and the data are logged. The big issue with that is, that the logger crashes in an non deterministic way. Sometimes it crashes immediately, sometimes it runs for 5 minutes.
The PowerShell ISE (5.1) as well as the PowerShell (V5.1) are crashing without giving further details. Just a message box, that the PowerShell has crashed and will be restarted. Thus I have no idea, what to do to avoid this behavior.
Any idea how to make it more robust. Using the PowerShell is a requirement, thus using any other programming language is not an option.
try {
Add-Type -Path 'C:\Program Files (x86)\OPC Labs QuickOPC 2017.2\Assemblies\net452\OpcLabs.EasyOpcUA.dll'
}
catch
{}
function writeDataLog($myEventArgs) {
$OutString = $myEventArgs.Arguments.NodeDescriptor.DisplayString + ";" + $myEventArgs.AttributeData.Value + ";" + $myEventArgs.AttributeData.DisplayString
$OutString >> .\DataLogger.csv
}
#Definition
$DataNodes = [OpcLabs.EasyOpc.UA.AddressSpace.UANodeElementCollection]::new()
$DataNode = [OpcLabs.EasyOpc.UA.AddressSpace.UANodeElement]::new()
$arrMonitoredItems = @()
$client = New-Object OpcLabs.EasyOpc.UA.EasyUAClient
# Definition für Data Transport Server
$sEndPoint = "opc.tcp://TEXUS-Dellap:49580"
$browseNode = "nsu=urn:NationalInstruments:uaserver:LabVIEW;ns=2;s=CAMP.ExpName"
$DataNode.NodeId = $browseNode
. C:\Workspace\PowerShell\ClassServerAccess.ps1
$myServer = [ServerAccessOPCUA]::new($client, $sEndPoint)
$tmpCollection = $myServer.getChildNodes($DataNode)
$tmpCollection > .\collection.txt
foreach($OPCUANode in $tmpCollection) {
if ($OPCUANode.NodeClass -like "Variable") {
$DataNodes.add($OPCUANode)
}
}
$DataNodes.Count >> .\collection.txt
#$DataNodes.add($DataNode)
foreach($DataNode in $DataNodes) {
$myVar = [ OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments]::new("", $sEndPoint, $DataNode.NodeID)
$myVar.SubscriptionParameters = 1000
$myVar.MonitoringParameters = 100
$arrMonitoredItems += $myVar
}
$myEventHandler = Register-ObjectEvent -InputObject $client -EventName DataChangeNotification -Action { try {writeDataLog $EventArgs} Catch{} }
$client.SubscribeMultipleMonitoredItems($arrMonitoredItems)