# HG changeset patch # User Edouard Tisserant # Date 1568285807 -7200 # Node ID 9857b4b0d979059a2e5d95f617ea37368729ac23 # Parent 6e5e752372c838501dec26ea02cc602c405c290b SVGHMI: WIP for python<->C data exchange diff -r 6e5e752372c8 -r 9857b4b0d979 svghmi/svghmi_server.py --- a/svghmi/svghmi_server.py Thu Sep 12 12:55:32 2019 +0200 +++ b/svghmi/svghmi_server.py Thu Sep 12 12:56:47 2019 +0200 @@ -21,6 +21,30 @@ svghmi_session = None +svghmi_send_collect = PLCBinary.svghmi_send_collect +svghmi_send_collect.restype = ctypes.c_int # error or 0 +svghmi_send_collect.argtypes = [ + ctypes.POINTER(ctypes.c_uint32), # size + ctypes.POINTER(ctypes.c_void_p)] # data ptr +# TODO multiclient : switch to arrays + +svghmi_recv_dispatch = PLCBinary.svghmi_recv_dispatch +svghmi_recv_dispatch.restype = ctypes.c_int # error or 0 +svghmi_recv_dispatch.argtypes = [ + ctypes.POINTER(ctypes.c_uint32), # size + 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() + while res == 0: + res = svghmi_send_collect(ctypes.byref(size), ctypes.byref(ptr)) + + # TODO multiclient : dispatch to sessions + svghmi_session.sendMessage(ctypes.string_at(ptr,size)) + class HMISession(object): def __init__(self, protocol_instance): global svghmi_session @@ -53,6 +77,8 @@ # TODO multiclient : pass client index as well pass + def sendMessage(self, msg): + self.sendMessage(msg, True) class HMIProtocol(WebSocketServerProtocol):