svghmi/svghmi_server.py
author Edouard Tisserant
Mon, 16 Sep 2019 10:54:15 +0200
branchsvghmi
changeset 2775 3b93409ba22c
parent 2774 9857b4b0d979
child 2776 246ae685ab65
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
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    38
def SendThreadProc():
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    39
   assert(svghmi_session)
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    40
   size = ctypes.c_uint32()
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    41
   ptr = ctypes.c_void_p()
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    42
   res = 0
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    43
   while svghmi_send_collect(ctypes.byref(size), ctypes.byref(ptr)) == 0 and \
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    44
         svghmi_session is not None and \
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    45
         svghmi_session.sendMessage(ctypes.string_at(ptr,size)) == 0:
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    46
         pass
2774
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    47
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    48
       # TODO multiclient : dispatch to sessions
2774
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    49
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
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
    51
    def __init__(self, protocol_instance):
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    52
        global svghmi_session
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    53
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    54
        # TODO: kill existing session for robustness
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    55
        assert(svghmi_session is None)
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    56
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    57
        svghmi_session = self
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    58
        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
    59
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
        # TODO multiclient :
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    61
        # 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
    62
        # 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
    63
        # 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
    64
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
    65
    def __del__(self):
2773
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    66
        global svghmi_session
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    67
        assert(svghmi_session)
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    68
        svghmi_session = None
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    69
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    70
        # TODO multiclient :
6e5e752372c8 SVGHMI: single session for now
Edouard Tisserant
parents: 2772
diff changeset
    71
        # 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
    72
2772
3f1dd8312710 SVGHMI: few fixes on serving
Edouard Tisserant
parents: 2771
diff changeset
    73
    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
    74
        # 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
    75
        #    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
    76
        #        - 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
    77
        #        - 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
    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
        # 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
    80
        pass
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    81
2774
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    82
    def sendMessage(self, msg):
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    83
        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
    84
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
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
    86
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
    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
    88
        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
    89
        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
    90
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
    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
    92
        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
    93
        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
    94
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
    95
    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
    96
        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
    97
        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
    98
        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
    99
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
   100
    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
   101
        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
   102
        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
   103
        #self.sendMessage(msg, binary)
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   104
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
   105
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
   106
svghmi_listener = None
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   107
svghmi_send_thread = None
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
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