08-19-2020 01:56 PM
In the script I'm running to process data, I will occasionally get the following error, it will run fine again as soon as I restart DIAdem:
Error Type: ACCESS VIOLATION
Error Address: 000358F4
Module name: DIAdata.dll
I've been making some changes to improve the robustness and speed of the script that have helped reduce the occurrence of this, and have also made the error happen at a more predictable spot. It seems to happen pretty regularly at this stage of the script below. I have maybe 1000 channels that are being loaded into the Portal. One of the first things I do is to take from a text file list only those 300-400 channels that I care about. I use the following for that. It's typically during one of these ChnCopys that I get the error and I need to restart DIAdem before it can continue.
08-21-2020 05:33 PM
Hi DIAdemUser81,
I'm not convinced that copying 400 or so channels you want to keep is the best way to go, though that's an ugly error that I wish wasn't happening to you. How about if instead you add a prefix to all the loaded channel names, such as "<DeleteMe> ", then when you find a particular channel in the external ASCII file you remove that prefix from the channel name, then when you're done reading the ASCII file request all the remaining "<DeleteMe> " channels and delete them, leaving just the channels you want, uncopied.
Set Group = Data.Root.ChannelGroups(1)
FOR Each Group In Data.Root.ChannelGroups
FOR Each Channel in Group.Channels
Channel.Name = "<DeleteMe> " & Channel.Name
NEXT
NEXT ' Group
Set Group = Data.Root.ChannelGroups(1)
Set Channel = Group.Channels(1) : Channel.Name = Mid(Channel.Name, 12)
Set Channel = Group.Channels("<DeleteMe> RPM") : Channel.Name = Mid(Channel.Name, 12)
Set DeleteChannels = Data.GetChannels("<DeleteMe> *")
Call Data.Remove(DeleteChannels)
Brad Turpin
Principal Technical Support Engineer
National Instruments
08-25-2020 01:30 PM
Good news and bad news. The good news is I've put in that routine as suggested below and it seems to work well. The channels aren't ordered as I had them in the text file, but it was getting to be such a large list people would just search for the channel they need anyway.
The bad news is I'm still getting the Access Violation Error, this time in a different part of the script. This script is running a series of calculations - on the order of several hundred similar to what is copied below. I wonder if Event Search is more processor friendly?
Call Calculate("Ch(""[1]/Cool1below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+"&s&"/2)")
Call Calculate("Ch(""[1]/Cool2below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+3*"&s&"/2)+CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+"&s&"/2)")
Call Calculate("Ch(""[1]/Cool3below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+5*"&s&"/2)+CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+3*"&s&"/2)")
Call Calculate("Ch(""[1]/Cool4below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+7*"&s&"/2)+CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+5*"&s&"/2)")
Call Calculate("Ch(""[1]/Cool5below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+9*"&s&"/2)+CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+7*"&s&"/2)")
Call Calculate("Ch(""[1]/Cool6below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+11*"&s&"/2)+CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+9*"&s&"/2)")
Call Calculate("Ch(""[1]/Cool7below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+13*"&s&"/2)+CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+11*"&s&"/2)")
Call Calculate("Ch(""[1]/Cool8below"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")>"&L&"+15*"&s&"/2)+CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+13*"&s&"/2)")
Call Calculate("Ch(""[1]/Cool8plus"") = Ch(""[1]/CoolantTemperature"") + CTNV(Ch(""[1]/CoolantTemperature"")<="&L&"+15*"&s&"/2)")
08-25-2020 01:40 PM
And now this ... I always know I've reached the depths of DIAdem when my errors are in the original German. I got the following error after restarting DIAdem following one of the Access Violation Errors mentioned here
08-26-2020 06:31 PM - edited 08-26-2020 06:41 PM
Hi DIAdemUser81,
I don't see anything wrong with the code you provide, though of course I don't know what values you have stored in variables "L" and "s" at the moment that the execution turns ugly. I can think of several ways to improve the execution and debugging of your existing code, but you make a good point about the ChnEvent...() possibly being the better option. Here are my thoughts on your existing code:
Try setting external variables outside the Calculation, such as R1 and R2, then use those variable names in the text of the formula natively. Additionally, instead of the formula looking up the channel by name each time, create a channel object after looking it up once and pass the object to the Calculation:
R1 = L
R2 = s
Set CoolTempChannel = Data.GetChannel("[1]/CoolantTemperature")
Symbols = Array("CoolTemp")
Channels = Array(CoolTempChannel)
Call Calculate("Ch(""[1]/Cool1below"") = CoolTemp + CTNV(CoolTemp> R1+ 1*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool2below"") = CoolTemp + CTNV(CoolTemp> R1+ 3*R2/2) + CTNV(CoolTemp<=R1+ 1*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool3below"") = CoolTemp + CTNV(CoolTemp> R1+ 5*R2/2) + CTNV(CoolTemp<=R1+ 3*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool4below"") = CoolTemp + CTNV(CoolTemp> R1+ 7*R2/2) + CTNV(CoolTemp<=R1+ 5*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool5below"") = CoolTemp + CTNV(CoolTemp> R1+ 9*R2/2) + CTNV(CoolTemp<=R1+ 7*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool6below"") = CoolTemp + CTNV(CoolTemp> R1+11*R2/2) + CTNV(CoolTemp<=R1+ 9*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool7below"") = CoolTemp + CTNV(CoolTemp> R1+13*R2/2) + CTNV(CoolTemp<=R1+11*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool8below"") = CoolTemp + CTNV(CoolTemp> R1+15*R2/2) + CTNV(CoolTemp<=R1+13*R2/2)", Symbols, Channels)
Call Calculate("Ch(""[1]/Cool8plus"") = CoolTemp + CTNV(CoolTemp<=R1+15*R2/2)", Symbols, Channels)
It may make sense to look into using the ChnEvent...() functions instead of these Calculations, though I think you'll find the amount of code to do so many lines longer than what you already have to do the same job. They ChnEvent...() code should run faster and might run more reliably, though.
Let me know if you want help with that,
Brad Turpin
Principal Technical Support Engineer
NI