Hi again,
Attached is my simple OPC plugin implementation.
- OPC.zip
- (29.06 KiB) Downloaded 236 times
Hopefully it will also find your installed KNX OPC server. I do not believe there is a memory leak because memory is released and given back to the OS. This can be studied by setting a low value of memory usage in the options and then minimize EG.
I have found a way to use this memory release feature and to limit the memory usage also in non minimized mode, using a little trick (maybe some have an opinion on this, maybe some would think this should be a part of EG option settings itself)
The trick I use is the following
In the code I have the following import:
Code: Select all
import eg
import OpenOPC
import time
from eg.WinApi.Dynamic import (
OpenProcess,
PROCESS_SET_QUOTA,
SetProcessWorkingSetSize,
FormatError,
)
In the init of the plugin, I have added:
Code: Select all
def __init__(self):
self.hHandle = OpenProcess(PROCESS_SET_QUOTA, 0, eg.processId)
The code for the thread looks like this:
Code: Select all
def ThreadWorker(self, stopThreadEvent):
eg.config.limitMemorySize = self.limitMemorySize
while not stopThreadEvent.isSet():
stopThreadEvent.wait(self.iDelay)
if not self.bOpcObjectCreated:
self.findOpcServer()
for i in range (0,len(self.tags)):
tag = str(self.tags[i])
#print tag
tag_items = self.items[i]
#print tag_items
for j in range (0,len(tag_items)):
value, quality, time = self.opc.read(tag_items[j])
print tag_items[j], "Value: ", value
if self.q > 100 or self.q == 0:
SetProcessWorkingSetSize(
self.hHandle,
3670016,
self.limitMemorySize * 1048576
)
self.q = 1
self.q += 1
self.opc.close()
self.bOpcObjectCreated = False
print self.text.infoThreadStopped
Specifically note the following:
Code: Select all
eg.config.limitMemorySize = self.limitMemorySize
and
Code: Select all
SetProcessWorkingSetSize(
self.hHandle,
3670016,
self.limitMemorySize * 1048576
)
The setting dialog for the OPC server looks typically like this with a drop-down to select the OPC server you like to connect to. The setting for maximum memory usage will be used in all modes (minimized, maximized, windowed)