svghmi/svghmi_server.py
author Edouard Tisserant
Tue, 15 Oct 2019 17:14:48 +0200
branchsvghmi
changeset 2798 ddb2c4668a6b
parent 2788 2ed9ff826d03
child 2799 f5da343b9b63
permissions -rw-r--r--
SVGHMI : many details about communication implemented in JS, with side effects.
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
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
    28
    ctypes.POINTER(ctypes.c_char_p)]  # data ptr
2774
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 = [
2788
2ed9ff826d03 SVGHMI: Work in progress. C side mostly implemented, neither built nor tested.
Edouard Tisserant
parents: 2779
diff changeset
    34
    ctypes.c_uint32,  # size
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
    35
    ctypes.c_char_p]  # data ptr
2774
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):
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
    62
        # pass message to the C side recieve_message()
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
    63
        svghmi_recv_dispatch(len(msg), 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
    64
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
        # TODO multiclient : pass client index as well
2777
cdf6584953a0 SVGHMI: WIP for python<->C data exchange : message from browser hit the C side.
Edouard Tisserant
parents: 2776
diff changeset
    66
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    67
2774
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    68
    def sendMessage(self, msg):
9857b4b0d979 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2773
diff changeset
    69
        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
    70
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
    71
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
    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
    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
    74
        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
    75
        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
    76
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
    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
    78
        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
    79
        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
    80
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
    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
    82
        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
    83
        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
    84
        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
    85
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
    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
    87
        self._hmi_session.onMessage(msg)
2798
ddb2c4668a6b SVGHMI : many details about communication implemented in JS, with side effects.
Edouard Tisserant
parents: 2788
diff changeset
    88
        # print 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
    89
        #self.sendMessage(msg, binary)
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    90
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
    91
class HMIWebSocketServerFactory(WebSocketServerFactory):
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
    92
    protocol = HMIProtocol
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
    93
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
    94
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
    95
svghmi_listener = None
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    96
svghmi_send_thread = None
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
    97
2776
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
    98
def SendThreadProc():
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
    99
   global svghmi_session
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   100
   size = ctypes.c_uint32()
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
   101
   ptr = ctypes.c_char_p()
2776
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   102
   res = 0
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   103
   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
   104
         svghmi_session is not None and \
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   105
         svghmi_session.sendMessage(ctypes.string_at(ptr,size)) == 0:
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   106
         pass
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   107
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   108
       # TODO multiclient : dispatch to sessions
246ae685ab65 SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2775
diff changeset
   109
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
   110
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
   111
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
   112
# 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
   113
def _runtime_svghmi0_start():
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   114
    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
   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
    svghmi_root = Resource()
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
   117
    svghmi_root.putChild("ws", WebSocketResource(HMIWebSocketServerFactory()))
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
   118
2779
75c6a31caca6 SVGHMI: Work In Progress : fixed pointer types in ctypes interface, cleaned up server startup and cleanup code, changed document type to XHTML, cleaner JS script : encapsulated in a function and in CDATA.
Edouard Tisserant
parents: 2777
diff changeset
   119
    svghmi_listener = reactor.listenTCP(8008, Site(svghmi_root))
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
    # 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
   122
    svghmi_send_thread = Thread(target=SendThreadProc, name="SVGHMI Send")
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   123
    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
   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
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
   126
# 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
   127
def _runtime_svghmi0_stop():
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   128
    global svghmi_listener, svghmi_root, svghmi_send_thread
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   129
    svghmi_root.delEntity("ws")
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   130
    svghmi_root = None
2772
3f1dd8312710 SVGHMI: few fixes on serving
Edouard Tisserant
parents: 2771
diff changeset
   131
    svghmi_listener.stopListening()
2775
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   132
    svghmi_listener = None
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   133
    # plc cleanup calls svghmi_(locstring)_cleanup and unlocks send thread
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   134
    svghmi_send_thread.join()
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   135
    svghmi_send_thread = None
3b93409ba22c SVGHMI: WIP for python<->C data exchange
Edouard Tisserant
parents: 2774
diff changeset
   136