--- a/svghmi/svghmi.c Mon Sep 16 10:54:15 2019 +0200
+++ b/svghmi/svghmi.c Mon Sep 16 11:44:20 2019 +0200
@@ -1,4 +1,5 @@
#include <pthread.h>
+#include <errno.h>
#include "iec_types_all.h"
#include "POUS.h"
#include "config.h"
@@ -6,6 +7,7 @@
#define DEFAULT_REFRESH_PERIOD_MS 100
#define HMI_BUFFER_SIZE %(buffer_size)d
+#define HMI_ITEM_COUNT %(item_count)d
/* PLC reads from that buffer */
static char rbuf[HMI_BUFFER_SIZE];
@@ -51,6 +53,8 @@
%(variable_decl_array)s
};
+static char sendbuf[HMI_BUFFER_SIZE];
+
typedef void(*hmi_tree_iterator)(hmi_tree_item_t*);
void traverse_hmi_tree(hmi_tree_iterator fp)
{
@@ -92,7 +96,7 @@
}
}
}
-
+
/* if new value differs from previous one */
if(memcmp(dest_p, visible_value_p, __get_type_enum_size(dsc->type)) != 0){
/* copy and flag as set */
@@ -141,6 +145,8 @@
static pthread_cond_t UART_WakeCond = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t UART_WakeCondLock = PTHREAD_MUTEX_INITIALIZER;
+static int continue_collect;
+
int __init_svghmi()
{
bzero(rbuf,sizeof(rbuf));
@@ -175,11 +181,13 @@
/* PYTHON CALLS */
int svghmi_send_collect(uint32_t *size, void *ptr){
+ int do_collect;
pthread_mutex_lock(&UART_WakeCondLock);
do_collect = continue_collect;
- if do_collect;
+ if(do_collect){
pthread_cond_wait(&UART_WakeCond, &UART_WakeCondLock);
do_collect = continue_collect;
+ }
pthread_mutex_unlock(&UART_WakeCondLock);
--- a/svghmi/svghmi_server.py Mon Sep 16 10:54:15 2019 +0200
+++ b/svghmi/svghmi_server.py Mon Sep 16 11:44:20 2019 +0200
@@ -35,18 +35,6 @@
ctypes.POINTER(ctypes.c_void_p)] # data ptr
# TODO multiclient : switch to arrays
-def SendThreadProc():
- assert(svghmi_session)
- size = ctypes.c_uint32()
- ptr = ctypes.c_void_p()
- res = 0
- while svghmi_send_collect(ctypes.byref(size), ctypes.byref(ptr)) == 0 and \
- svghmi_session is not None and \
- svghmi_session.sendMessage(ctypes.string_at(ptr,size)) == 0:
- pass
-
- # TODO multiclient : dispatch to sessions
-
class HMISession(object):
def __init__(self, protocol_instance):
global svghmi_session
@@ -106,6 +94,18 @@
svghmi_listener = None
svghmi_send_thread = None
+def SendThreadProc():
+ global svghmi_session
+ size = ctypes.c_uint32()
+ ptr = ctypes.c_void_p()
+ res = 0
+ while svghmi_send_collect(ctypes.byref(size), ctypes.byref(ptr)) == 0 and \
+ svghmi_session is not None and \
+ svghmi_session.sendMessage(ctypes.string_at(ptr,size)) == 0:
+ pass
+
+ # TODO multiclient : dispatch to sessions
+
# Called by PLCObject at start
def _runtime_svghmi0_start():