SVGHMI: change collect/send thread looping condition to fix infinite loop in some cases
--- a/svghmi/svghmi.c Tue Dec 03 09:46:12 2019 +0100
+++ b/svghmi/svghmi.c Mon Dec 09 10:43:54 2019 +0100
@@ -198,7 +198,11 @@
{
bzero(rbuf,sizeof(rbuf));
bzero(wbuf,sizeof(wbuf));
+
+ pthread_mutex_lock(&svghmi_send_WakeCondLock);
continue_collect = 1;
+ pthread_cond_signal(&svghmi_send_WakeCond);
+ pthread_mutex_unlock(&svghmi_send_WakeCondLock);
return 0;
}
@@ -230,12 +234,8 @@
int do_collect;
pthread_mutex_lock(&svghmi_send_WakeCondLock);
+ pthread_cond_wait(&svghmi_send_WakeCond, &svghmi_send_WakeCondLock);
do_collect = continue_collect;
- if(do_collect)
- {
- pthread_cond_wait(&svghmi_send_WakeCond, &svghmi_send_WakeCondLock);
- do_collect = continue_collect;
- }
pthread_mutex_unlock(&svghmi_send_WakeCondLock);
if(do_collect) {
--- a/svghmi/svghmi_server.py Tue Dec 03 09:46:12 2019 +0100
+++ b/svghmi/svghmi_server.py Mon Dec 09 10:43:54 2019 +0100
@@ -95,18 +95,23 @@
svghmi_send_thread = None
def SendThreadProc():
- global svghmi_session
- size = ctypes.c_uint32()
- ptr = ctypes.c_void_p()
- res = 0
- while True:
- res=svghmi_send_collect(ctypes.byref(size), ctypes.byref(ptr))
- if res == 0:
- # TODO multiclient : dispatch to sessions
- if svghmi_session is not None:
- svghmi_session.sendMessage(ctypes.string_at(ptr.value,size.value))
- elif res not in [errno.EAGAIN, errno.ENODATA]:
- break
+ global svghmi_session
+ size = ctypes.c_uint32()
+ ptr = ctypes.c_void_p()
+ res = 0
+ while True:
+ res=svghmi_send_collect(ctypes.byref(size), ctypes.byref(ptr))
+ if res == 0:
+ # TODO multiclient : dispatch to sessions
+ if svghmi_session is not None:
+ svghmi_session.sendMessage(ctypes.string_at(ptr.value,size.value))
+ elif res == errno.ENODATA:
+ # this happens when there is no data after wakeup
+ # because of hmi data refresh period longer than PLC common ticktime
+ pass
+ else:
+ # this happens when finishing
+ break