Added PLCID variable accessible from C side, set with binarie's MD5. Added retain init and cleanup calls. Extended tests/python to test PLCID
--- a/runtime/PLCObject.py Fri Mar 13 17:19:58 2015 +0100
+++ b/runtime/PLCObject.py Fri Mar 13 22:36:52 2015 +0100
@@ -137,10 +137,15 @@
Load PLC library
Declare all functions, arguments and return values
"""
+ md5 = open(self._GetMD5FileName(), "r").read()
try:
self._PLClibraryHandle = dlopen(self._GetLibFileName())
self.PLClibraryHandle = ctypes.CDLL(self.CurrentPLCFilename, handle=self._PLClibraryHandle)
+ self.PLCID = ctypes.c_char_p.in_dll(self.PLClibraryHandle, "PLCID")
+ if len(md5) == 32 :
+ self.PLCID.value = md5
+
self._startPLC = self.PLClibraryHandle.startPLC
self._startPLC.restype = ctypes.c_int
self._startPLC.argtypes = [ctypes.c_int, ctypes.POINTER(ctypes.c_char_p)]
--- a/targets/Linux/plc_Linux_main.c Fri Mar 13 17:19:58 2015 +0100
+++ b/targets/Linux/plc_Linux_main.c Fri Mar 13 22:36:52 2015 +0100
@@ -232,6 +232,14 @@
pthread_mutex_lock(&python_mutex);
}
+void InitRetain(void)
+{
+}
+
+void CleanupRetain(void)
+{
+}
+
int CheckRetainBuffer(void)
{
return 1;
--- a/targets/Win32/plc_Win32_main.c Fri Mar 13 17:19:58 2015 +0100
+++ b/targets/Win32/plc_Win32_main.c Fri Mar 13 22:36:52 2015 +0100
@@ -244,6 +244,14 @@
WaitForSingleObject(python_sem, INFINITE);
}
+void InitRetain(void)
+{
+}
+
+void CleanupRetain(void)
+{
+}
+
int CheckRetainBuffer(void)
{
return 1;
--- a/targets/Xenomai/plc_Xenomai_main.c_noretain Fri Mar 13 17:19:58 2015 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-int CheckRetainBuffer(void)
-{
- return 1;
-}
-
-void ValidateRetainBuffer(void)
-{
-}
-
-void InValidateRetainBuffer(void)
-{
-}
-
-void Retain(unsigned int offset, unsigned int count, void *p)
-{
-}
-
-void Remind(unsigned int offset, unsigned int count, void *p)
-{
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/targets/Xenomai/plc_Xenomai_noretain.c Fri Mar 13 22:36:52 2015 +0100
@@ -0,0 +1,20 @@
+int CheckRetainBuffer(void)
+{
+ return 1;
+}
+
+void ValidateRetainBuffer(void)
+{
+}
+
+void InValidateRetainBuffer(void)
+{
+}
+
+void Retain(unsigned int offset, unsigned int count, void *p)
+{
+}
+
+void Remind(unsigned int offset, unsigned int count, void *p)
+{
+}
--- a/targets/__init__.py Fri Mar 13 17:19:58 2015 +0100
+++ b/targets/__init__.py Fri Mar 13 22:36:52 2015 +0100
@@ -39,8 +39,9 @@
targets = dict([(name, {"xsd":path.join(_base_path, name, "XSD"),
"class":_GetLocalTargetClassFactory(name),
"code": { fname: path.join(_base_path, name, fname)
- for fname in listdir(path.join(_base_path, name))
- if fname.startswith("plc_%s_main.c"%name)}})
+ for fname in listdir(path.join(_base_path, name))
+ if fname.startswith("plc_%s_main"%name) and
+ fname.endswith(".c")}})
for name in listdir(_base_path)
if path.isdir(path.join(_base_path, name))
and not name.startswith("__")])
--- a/targets/plc_debug.c Fri Mar 13 17:19:58 2015 +0100
+++ b/targets/plc_debug.c Fri Mar 13 22:36:52 2015 +0100
@@ -111,6 +111,7 @@
}
extern int CheckRetainBuffer(void);
+extern void InitRetain(void);
void __init_debug(void)
{
@@ -118,6 +119,7 @@
buffer_cursor = debug_buffer;
retain_offset = 0;
buffer_state = BUFFER_FREE;
+ InitRetain();
/* Iterate over all variables to fill debug buffer */
if(CheckRetainBuffer())
__for_each_variable_do(RemindIterator);
@@ -125,6 +127,7 @@
}
extern void InitiateDebugTransfer(void);
+extern void CleanupRetain(void);
extern unsigned long __tick;
@@ -132,6 +135,7 @@
{
buffer_cursor = debug_buffer;
InitiateDebugTransfer();
+ CleanupRetain();
}
void __retrieve_debug(void)
--- a/targets/plc_main_head.c Fri Mar 13 17:19:58 2015 +0100
+++ b/targets/plc_main_head.c Fri Mar 13 22:36:52 2015 +0100
@@ -25,6 +25,7 @@
IEC_TIME __CURRENT_TIME;
IEC_BOOL __DEBUG = 0;
unsigned long __tick = 0;
+char *PLCID = NULL;
/*
* Variable generated by C softPLC and plugins
--- a/tests/python/c_code@c_ext/cfile.xml Fri Mar 13 17:19:58 2015 +0100
+++ b/tests/python/c_code@c_ext/cfile.xml Fri Mar 13 22:36:52 2015 +0100
@@ -14,6 +14,7 @@
volatile char PtoC=1,CtoP=2;
extern long AtomicCompareExchange(long*,long, long);
+extern char *PLCID;
int Simple_C_Call(int val){
return val+1;
@@ -34,6 +35,7 @@
res=1;
}
printf("C code called by Python: toC %d fromC %d\n",toC,*fromC);
+ printf("PLCID id %s\n",PLCID);
return res;
}
--- a/tests/python/plc.xml Fri Mar 13 17:19:58 2015 +0100
+++ b/tests/python/plc.xml Fri Mar 13 22:36:52 2015 +0100
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<project xmlns="http://www.plcopen.org/xml/tc6_0201" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xsi:schemaLocation="http://www.plcopen.org/xml/tc6_0201">
<fileHeader companyName="" productName="Beremiz" productVersion="0.0" creationDateTime="2008-12-14T16:21:19"/>
- <contentHeader name="Beremiz Python Support Tests" modificationDateTime="2015-02-25T13:38:24">
+ <contentHeader name="Beremiz Python Support Tests" modificationDateTime="2015-03-13T22:06:10">
<coordinateInfo>
<pageSize x="1024" y="1024"/>
<fbd>