editors/DebugViewer.py
author Laurent Bessard
Thu, 10 Oct 2013 17:04:23 +0200
changeset 1355 9183fb765f16
parent 1215 786f2533200a
child 1363 e87e0166d0a7
permissions -rw-r--r--
Fixed bug when modifying power rail in LD Viewer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     1
#!/usr/bin/env python
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     3
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     4
#This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     5
#based on the plcopen standard. 
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     6
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     7
#Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     8
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
     9
#See COPYING file for copyrights details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    10
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    11
#This library is free software; you can redistribute it and/or
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    12
#modify it under the terms of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    13
#License as published by the Free Software Foundation; either
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    14
#version 2.1 of the License, or (at your option) any later version.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    15
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    16
#This library is distributed in the hope that it will be useful,
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    17
#but WITHOUT ANY WARRANTY; without even the implied warranty of
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    18
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    19
#General Public License for more details.
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    20
#
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    21
#You should have received a copy of the GNU General Public
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    22
#License along with this library; if not, write to the Free Software
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    23
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    24
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    25
from threading import Lock, Timer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    26
from time import time as gettime
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    27
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    28
import wx
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    29
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    30
REFRESH_PERIOD = 0.1        # Minimum time between 2 refresh
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    31
DEBUG_REFRESH_LOCK = Lock() # Common refresh lock for all debug viewers
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    32
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    33
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    34
#                               Debug Viewer Class
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    35
#-------------------------------------------------------------------------------
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    36
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    37
"""
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    38
Class that implements common behavior of every viewers able to display debug 
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    39
values
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    40
"""
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    41
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    42
class DebugViewer:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    43
    
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    44
    def __init__(self, producer, debug, subscribe_tick=True):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    45
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    46
        Constructor
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    47
        @param producer: Object receiving debug value and dispatching them to
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    48
        consumers
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    49
        @param debug: Flag indicating that Viewer is debugging
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    50
        @param subscribe_tick: Flag indicating that viewer need tick value to
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    51
        synchronize
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    52
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    53
        self.Debug = debug
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    54
        self.SubscribeTick = subscribe_tick
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    55
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    56
        # Flag indicating that consumer value update inhibited
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    57
        # (DebugViewer is refreshing)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    58
        self.Inhibited = False
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    59
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    60
        # List of data consumers subscribed to DataProducer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    61
        self.DataConsumers = {}
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    62
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    63
        # Time stamp indicating when last refresh have been initiated
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    64
        self.LastRefreshTime = gettime()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    65
        # Flag indicating that DebugViewer has acquire common debug lock
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    66
        self.HasAcquiredLock = False
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    67
        # Lock for access to the two preceding variable
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    68
        self.AccessLock = Lock()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    69
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    70
        # Timer to refresh Debug Viewer one last time in the case that a new
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    71
        # value have been received during refresh was inhibited and no one
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    72
        # after refresh was activated
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    73
        self.LastRefreshTimer = None
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    74
        # Lock for access to the timer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    75
        self.TimerAccessLock = Lock()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    76
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    77
        # Set DataProducer and subscribe tick if needed
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    78
        self.SetDataProducer(producer)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    79
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    80
    def __del__(self):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    81
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    82
        Destructor
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    83
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    84
        # Unsubscribe all data consumers
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    85
        self.UnsubscribeAllDataConsumers()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    86
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    87
        # Delete reference to DataProducer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    88
        self.DataProducer = None
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    89
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    90
        # Stop last refresh timer
877
7e695249be8d Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents: 875
diff changeset
    91
        if self.LastRefreshTimer is not None:
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    92
            self.LastRefreshTimer.cancel()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    93
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    94
        # Release Common debug lock if DebugViewer has acquired it
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
    95
        if self.HasAcquiredLock:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
    96
            DEBUG_REFRESH_LOCK.release()
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    97
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
    98
    def SetDataProducer(self, producer):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
    99
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   100
        Set Data Producer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   101
        @param producer: Data Producer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   102
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   103
        # In the case that tick need to be subscribed and DebugViewer is
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   104
        # debugging
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   105
        if self.SubscribeTick and self.Debug:
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   106
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   107
            # Subscribe tick to new data producer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   108
            if producer is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   109
                producer.SubscribeDebugIECVariable("__tick__", self)
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   110
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   111
            # Unsubscribe tick from old data producer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   112
            if getattr(self, "DataProducer", None) is not None:
1089
5cd1f8df71aa Fixed bug when transferring program and a output located variable is forced
Laurent Bessard
parents: 1069
diff changeset
   113
                self.DataProducer.UnsubscribeDebugIECVariable("__tick__", self)
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   114
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   115
        # Save new data producer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   116
        self.DataProducer = producer
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   117
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   118
    def IsDebugging(self):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   119
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   120
        Get flag indicating if Debug Viewer is debugging
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   121
        @return: Debugging flag
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   122
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   123
        return self.Debug
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   124
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   125
    def Inhibit(self, inhibit):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   126
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   127
        Set consumer value update inhibit flag
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   128
        @param inhibit: Inhibit flag
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   129
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   130
        # Inhibit every data consumers in list
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   131
        for consumer, iec_path in self.DataConsumers.iteritems():
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   132
            consumer.Inhibit(inhibit)
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   133
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   134
        # Save inhibit flag
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   135
        self.Inhibited = inhibit
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   136
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   137
    def AddDataConsumer(self, iec_path, consumer):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   138
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   139
        Subscribe data consumer to DataProducer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   140
        @param iec_path: Path in PLC of variable needed by data consumer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   141
        @param consumer: Data consumer to subscribe
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   142
        @return: List of value already received [(tick, data),...] (None if
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   143
        subscription failed)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   144
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   145
        # Return immediately if no DataProducer defined
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   146
        if self.DataProducer is None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   147
            return None
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   148
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   149
        # Subscribe data consumer to DataProducer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   150
        result = self.DataProducer.SubscribeDebugIECVariable(
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   151
                        iec_path, consumer)
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   152
        if result is not None and consumer != self:
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   153
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   154
            # Store data consumer if successfully subscribed and inform
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   155
            # consumer of variable data type
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   156
            self.DataConsumers[consumer] = iec_path
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   157
            consumer.SetDataType(self.GetDataType(iec_path))
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   158
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   159
        return result
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   160
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   161
    def RemoveDataConsumer(self, consumer):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   162
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   163
        Unsubscribe data consumer from DataProducer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   164
        @param consumer: Data consumer to unsubscribe
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   165
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   166
        # Remove consumer from data consumer list
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   167
        iec_path = self.DataConsumers.pop(consumer, None)
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   168
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   169
        # Unsubscribe consumer from DataProducer
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   170
        if iec_path is not None:
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   171
            self.DataProducer.UnsubscribeDebugIECVariable(
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   172
                        iec_path, consumer)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   173
    
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   174
    def SubscribeAllDataConsumers(self):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   175
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   176
        Called to Subscribe all data consumers contained in DebugViewer.
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   177
        May be overridden by inherited classes.
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   178
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   179
        # Subscribe tick if needed
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   180
        if self.SubscribeTick and self.Debug and self.DataProducer is not None:
1089
5cd1f8df71aa Fixed bug when transferring program and a output located variable is forced
Laurent Bessard
parents: 1069
diff changeset
   181
            self.DataProducer.SubscribeDebugIECVariable("__tick__", self)
897
3cd39bc7dbad Added support for defining extension file editor as DebugViewer
Laurent Bessard
parents: 887
diff changeset
   182
    
1205
638d1d430d24 Fixed bug Viewer not refreshed when debugging
Laurent Bessard
parents: 1176
diff changeset
   183
    def UnsubscribeAllDataConsumers(self, tick=True):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   184
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   185
        Called to Unsubscribe all data consumers.
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   186
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   187
        if self.DataProducer is not None:
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   188
            
1210
9a35da8f714b Fixed bug when closing debug tab or beremiz frame with variable debugged and PLC is running
Laurent Bessard
parents: 1205
diff changeset
   189
            # Unscribe tick if needed
9a35da8f714b Fixed bug when closing debug tab or beremiz frame with variable debugged and PLC is running
Laurent Bessard
parents: 1205
diff changeset
   190
            if self.SubscribeTick and tick and self.Debug:
9a35da8f714b Fixed bug when closing debug tab or beremiz frame with variable debugged and PLC is running
Laurent Bessard
parents: 1205
diff changeset
   191
                self.DataProducer.UnsubscribeDebugIECVariable("__tick__", self)
9a35da8f714b Fixed bug when closing debug tab or beremiz frame with variable debugged and PLC is running
Laurent Bessard
parents: 1205
diff changeset
   192
            
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   193
            # Unsubscribe all data consumers in list
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   194
            for consumer, iec_path in self.DataConsumers.iteritems():
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   195
                self.DataProducer.UnsubscribeDebugIECVariable(
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   196
                            iec_path, consumer)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   197
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   198
        self.DataConsumers = {}
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   199
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   200
    def GetDataType(self, iec_path):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   201
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   202
        Return variable data type.
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   203
        @param iec_path: Path in PLC of variable
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   204
        @return: variable data type (None if not found)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   205
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   206
        if self.DataProducer is not None:
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   207
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   208
            # Search for variable informations in project compilation files
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   209
            data_type = self.DataProducer.GetDebugIECVariableType(
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   210
                            iec_path.upper())
1102
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
   211
            if data_type is not None:
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
   212
                return data_type
cd4a996ddaa7 Fixed bug with debugging global variables
Laurent Bessard
parents: 1089
diff changeset
   213
            
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   214
            # Search for variable informations in project data
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
   215
            infos = self.DataProducer.GetInstanceInfos(iec_path)
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
   216
            if infos is not None:
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
   217
                return infos["type"]
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   218
        
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   219
        return None
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   220
    
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
   221
    def IsNumType(self, data_type):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   222
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   223
        Indicate if data type given is a numeric data type
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   224
        @param data_type: Data type to test
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   225
        @return: True if data type given is numeric
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   226
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   227
        if self.DataProducer is not None:
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   228
            return self.DataProducer.IsNumType(data_type)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   229
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   230
        return False
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
   231
    
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   232
    def ForceDataValue(self, iec_path, value):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   233
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   234
        Force PLC variable value
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   235
        @param iec_path: Path in PLC of variable to force
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   236
        @param value: Value forced
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   237
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   238
        if self.DataProducer is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   239
            self.DataProducer.ForceDebugIECVariable(iec_path, value)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   240
    
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   241
    def ReleaseDataValue(self, iec_path):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   242
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   243
        Release PLC variable value
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   244
        @param iec_path: Path in PLC of variable to release
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   245
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   246
        if self.DataProducer is not None:
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   247
            self.DataProducer.ReleaseDebugIECVariable(iec_path)
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   248
    
902
ffa8ee5ee2fe Adding support for defining a time range for DebugVariablePanel graphics and navigating across the recording.
Laurent Bessard
parents: 897
diff changeset
   249
    def NewDataAvailable(self, tick, *args, **kwargs):
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   250
        """
1215
786f2533200a Rewrite DebugVariablePanel
Laurent Bessard
parents: 1210
diff changeset
   251
        Called by DataProducer for each tick captured
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   252
        @param tick: PLC tick captured
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   253
        All other parameters are passed to refresh function 
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   254
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   255
        # Stop last refresh timer
877
7e695249be8d Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents: 875
diff changeset
   256
        self.TimerAccessLock.acquire()
875
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 857
diff changeset
   257
        if self.LastRefreshTimer is not None:
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 857
diff changeset
   258
            self.LastRefreshTimer.cancel()
a8952b79caec Fix bug in Debug refresh lock that, with too much data to debug, flooded GUI and blocked it
Laurent Bessard
parents: 857
diff changeset
   259
            self.LastRefreshTimer=None
877
7e695249be8d Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents: 875
diff changeset
   260
        self.TimerAccessLock.release()
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   261
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   262
        # Only try to refresh DebugViewer if it is visible on screen and not
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   263
        # already refreshing
887
d3c6c4ab8b28 Adding support for displaying graphs of debugged numeric variables in 2D and 3D in DebugVariablePanel
Laurent Bessard
parents: 880
diff changeset
   264
        if self.IsShown() and not self.Inhibited:
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   265
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   266
            # Try to get acquire common refresh lock if minimum period between
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   267
            # two refresh has expired
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   268
            if gettime() - self.LastRefreshTime > REFRESH_PERIOD and \
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   269
               DEBUG_REFRESH_LOCK.acquire(False):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   270
                self.StartRefreshing(*args, **kwargs)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   271
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   272
            # If common lock wasn't acquired for any reason, restart last
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   273
            # refresh timer
933
6c320534627e Fixed bug with LastRefreshTimer
Laurent Bessard
parents: 904
diff changeset
   274
            else:
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   275
                self.StartLastRefreshTimer(*args, **kwargs)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   276
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   277
        # In the case that DebugViewer isn't visible on screen and has already
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   278
        # acquired common refresh lock, reset DebugViewer
877
7e695249be8d Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents: 875
diff changeset
   279
        elif not self.IsShown() and self.HasAcquiredLock:
7e695249be8d Fix bug debug viewers are block when a Graphic Viewer in debug mode is hidden
Laurent Bessard
parents: 875
diff changeset
   280
            DebugViewer.RefreshNewData(self)
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   281
    
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   282
    def ShouldRefresh(self, *args, **kwargs):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   283
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   284
        Callback function called when last refresh timer expired
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   285
        All parameters are passed to refresh function
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   286
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   287
        # Cancel if DebugViewer is not visible on screen
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   288
        if self and self.IsShown():
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   289
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   290
            # Try to acquire common refresh lock
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   291
            if DEBUG_REFRESH_LOCK.acquire(False):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   292
                self.StartRefreshing(*args, **kwargs)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   293
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   294
            # Restart last refresh timer if common refresh lock acquired failed
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   295
            else:
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   296
                self.StartLastRefreshTimer(*args, **kwargs)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   297
    
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   298
    def StartRefreshing(self, *args, **kwargs):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   299
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   300
        Called to initiate a refresh of DebugViewer
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   301
        All parameters are passed to refresh function
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   302
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   303
        # Update last refresh time stamp and flag for common refresh
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   304
        # lock acquired
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   305
        self.AccessLock.acquire()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   306
        self.HasAcquiredLock = True
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   307
        self.LastRefreshTime = gettime()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   308
        self.AccessLock.release()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   309
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   310
        # Inhibit data consumer value update
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   311
        self.Inhibit(True)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   312
        
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   313
        # Initiate DebugViewer refresh
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   314
        wx.CallAfter(self.RefreshNewData, *args, **kwargs)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   315
    
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   316
    def StartLastRefreshTimer(self, *args, **kwargs):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   317
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   318
        Called to start last refresh timer for the minimum time between 2
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   319
        refresh
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   320
        All parameters are passed to refresh function
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   321
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   322
        self.TimerAccessLock.acquire()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   323
        self.LastRefreshTimer = Timer(
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   324
            REFRESH_PERIOD, self.ShouldRefresh, args, kwargs)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   325
        self.LastRefreshTimer.start()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   326
        self.TimerAccessLock.release()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   327
    
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   328
    def RefreshNewData(self, *args, **kwargs):
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   329
        """
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   330
        Called to refresh DebugViewer according to values received by data
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   331
        consumers
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   332
        May be overridden by inherited classes
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   333
        Can receive any parameters depending on what is needed by inherited
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   334
        class 
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   335
        """
814
5743cbdff669 Integration of PLCOpenEditor into Beremiz
Laurent Bessard
parents:
diff changeset
   336
        if self:
1176
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   337
            # Activate data consumer value update
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   338
            self.Inhibit(False)
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   339
            
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   340
            # Release common refresh lock if acquired and update
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   341
            # last refresh time
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   342
            self.AccessLock.acquire()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   343
            if self.HasAcquiredLock:
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   344
                DEBUG_REFRESH_LOCK.release()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   345
                self.HasAcquiredLock = False
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   346
            if gettime() - self.LastRefreshTime > REFRESH_PERIOD:
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   347
                self.LastRefreshTime = gettime()
f4b434672204 Moved and rewrote DebugViewer and DebusDataConsumer classes
Laurent Bessard
parents: 1173
diff changeset
   348
            self.AccessLock.release()