svghmi/svghmi_server.py
author Edouard Tisserant
Mon, 16 Sep 2019 11:44:20 +0200
branchsvghmi
changeset 2776 246ae685ab65
parent 2775 3b93409ba22c
child 2777 cdf6584953a0
permissions -rw-r--r--
SVGHMI: WIP for python<->C data exchange
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     1
#!/usr/bin/env python
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     3
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     4
# This file is part of Beremiz
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     5
# Copyright (C) 2019: Edouard TISSERANT
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     6
# See COPYING file for copyrights details.
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     7
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     8
from __future__ import absolute_import
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
     9
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    10
from twisted.web.server import Site
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    11
from twisted.web.resource import Resource
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    12
from twisted.internet import reactor
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    13
from twisted.web.static import File
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    14
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    15
from autobahn.twisted.websocket import WebSocketServerFactory, WebSocketServerProtocol
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    16
from autobahn.twisted.resource import  WebSocketResource
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    17
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    18
# TODO multiclient :
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    19
# session list lock
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    20
# svghmi_sessions = []
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    21
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    22
svghmi_session = None
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    23
2774
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    24
svghmi_send_collect = PLCBinary.svghmi_send_collect
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    25
svghmi_send_collect.restype = ctypes.c_int # error or 0
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    26
svghmi_send_collect.argtypes = [
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    27
    ctypes.POINTER(ctypes.c_uint32),  # size
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    28
    ctypes.POINTER(ctypes.c_void_p)]  # data ptr
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    29
# TODO multiclient : switch to arrays
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    30
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    31
svghmi_recv_dispatch = PLCBinary.svghmi_recv_dispatch
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    32
svghmi_recv_dispatch.restype = ctypes.c_int # error or 0
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    33
svghmi_recv_dispatch.argtypes = [
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    34
    ctypes.c_uint32,                  # size
2774
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    35
    ctypes.POINTER(ctypes.c_void_p)]  # data ptr
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    36
# TODO multiclient : switch to arrays
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    37
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    38
class HMISession(object):
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    39
    def __init__(self, protocol_instance):
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    40
        global svghmi_session
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    41
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    42
        # TODO: kill existing session for robustness
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    43
        assert(svghmi_session is None)
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    44
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    45
        svghmi_session = self
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    46
        self.protocol_instance = protocol_instance
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    47
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    48
        # TODO multiclient :
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    49
        # svghmi_sessions.append(self)
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    50
        # get a unique bit index amont other svghmi_sessions,
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    51
        # so that we can match flags passed by C->python callback
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    52
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    53
    def __del__(self):
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    54
        global svghmi_session
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    55
        assert(svghmi_session)
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    56
        svghmi_session = None
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    57
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    58
        # TODO multiclient :
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    59
        # svghmi_sessions.remove(self)
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    60
2772
3f1dd8312710 SVGHMI: few fixes on serving
Edouard Tisserant
parents: 2771
diff changeset
    61
    def onMessage(self, msg):
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    62
        # TODO :  pass it to the C side recieve_message()
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    63
        #    update HMITree
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    64
        #        - values
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    65
        #        - refresh rates / subsriptions
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    66
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    67
        # TODO multiclient : pass client index as well
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    68
        pass
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    69
2774
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    70
    def sendMessage(self, msg):
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    71
        self.sendMessage(msg, True)
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    72
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    73
class HMIProtocol(WebSocketServerProtocol):
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    74
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    75
    def __init__(self, *args, **kwargs):
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    76
        self._hmi_session = None
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    77
        WebSocketServerProtocol.__init__(self, *args, **kwargs)
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    78
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    79
    def onOpen(self):
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    80
        self._hmi_session = HMISession(self)
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    81
        print "open"
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    82
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    83
    def onClose(self, wasClean, code, reason):
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    84
        del self._hmi_session
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    85
        self._hmi_session = None
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    86
        print "close"
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    87
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    88
    def onMessage(self, msg, isBinary):
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    89
        self._hmi_session.onMessage(msg)
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    90
        print msg
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    91
        #self.sendMessage(msg, binary)
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    92
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    93
svghmi_root = None
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
    94
svghmi_listener = None
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    95
svghmi_send_thread = None
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    96
2776
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
    97
def SendThreadProc():
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
    98
   global svghmi_session
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
    99
   size = ctypes.c_uint32()
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   100
   ptr = ctypes.c_void_p()
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   101
   res = 0
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   102
   while svghmi_send_collect(ctypes.byref(size), ctypes.byref(ptr)) == 0 and \
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   103
         svghmi_session is not None and \
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   104
         svghmi_session.sendMessage(ctypes.string_at(ptr,size)) == 0:
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   105
         pass
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   106
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   107
       # TODO multiclient : dispatch to sessions
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   108
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   109
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   110
# Called by PLCObject at start
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   111
def _runtime_svghmi0_start():
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   112
    global svghmi_listener, svghmi_root, svghmi_send_thread
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   113
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   114
    svghmi_root = Resource()
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   115
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   116
    wsfactory = WebSocketServerFactory()
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   117
    wsfactory.protocol = HMIProtocol
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   118
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   119
    svghmi_root.putChild("ws", WebSocketResource(wsfactory))
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   120
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   121
    sitefactory = Site(svghmi_root)
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   122
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   123
    svghmi_listener = reactor.listenTCP(8008, sitefactory)
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   124
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   125
    # start a thread that call the C part of SVGHMI
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   126
    svghmi_send_thread = Thread(target=SendThreadProc, name="SVGHMI Send")
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   127
    svghmi_send_thread.start()
2771
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   128
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   129
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   130
# Called by PLCObject at stop
361366b891ca WIP on svghmi, now builds and runs. HTTP serving + WS transport ready, missing actual data to transmit and thread to collect it.
Edouard Tisserant
parents:
diff changeset
   131
def _runtime_svghmi0_stop():
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   132
    global svghmi_listener, svghmi_root, svghmi_send_thread
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   133
    svghmi_root.delEntity("ws")
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   134
    svghmi_root = None
2772
3f1dd8312710 SVGHMI: few fixes on serving
Edouard Tisserant
parents: 2771
diff changeset
   135
    svghmi_listener.stopListening()
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   136
    svghmi_listener = None
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   137
    # plc cleanup calls svghmi_(locstring)_cleanup and unlocks send thread
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   138
    svghmi_send_thread.join()
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   139
    svghmi_send_thread = None
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   140