graphics/DebugDataConsumer.py
changeset 1736 7e61baa047f0
parent 1730 64d8f52bc8c8
child 1737 a39c2918c015
equal deleted inserted replaced
1735:c02818d7e29f 1736:7e61baa047f0
    34 DAY = 24 * HOUR       # Number of microseconds in one day
    34 DAY = 24 * HOUR       # Number of microseconds in one day
    35 
    35 
    36 # Date corresponding to Epoch (1970 January the first)
    36 # Date corresponding to Epoch (1970 January the first)
    37 DATE_ORIGIN = datetime.datetime(1970, 1, 1)
    37 DATE_ORIGIN = datetime.datetime(1970, 1, 1)
    38 
    38 
       
    39 
    39 def get_microseconds(value):
    40 def get_microseconds(value):
    40     """
    41     """
    41     Function converting time duration expressed in day, second and microseconds
    42     Function converting time duration expressed in day, second and microseconds
    42     into one expressed in microseconds
    43     into one expressed in microseconds
    43     @param value: Time duration to convert
    44     @param value: Time duration to convert
    45     """
    46     """
    46     return float(value.days * DAY + \
    47     return float(value.days * DAY + \
    47                  value.seconds * SECOND + \
    48                  value.seconds * SECOND + \
    48                  value.microseconds)
    49                  value.microseconds)
    49     return
    50     return
       
    51 
    50 
    52 
    51 def generate_time(value):
    53 def generate_time(value):
    52     """
    54     """
    53     Function converting time duration expressed in day, second and microseconds
    55     Function converting time duration expressed in day, second and microseconds
    54     into a IEC 61131 TIME literal
    56     into a IEC 61131 TIME literal
    88     # In any case microseconds have to be added to TIME literal
    90     # In any case microseconds have to be added to TIME literal
    89     data += "%gms" % (microseconds % SECOND / 1000.)
    91     data += "%gms" % (microseconds % SECOND / 1000.)
    90 
    92 
    91     return data
    93     return data
    92 
    94 
       
    95 
    93 def generate_date(value):
    96 def generate_date(value):
    94     """
    97     """
    95     Function converting time duration expressed in day, second and microseconds
    98     Function converting time duration expressed in day, second and microseconds
    96     into a IEC 61131 DATE literal
    99     into a IEC 61131 DATE literal
    97     @param value: Time duration to convert
   100     @param value: Time duration to convert
    98     @return: IEC 61131 DATE literal
   101     @return: IEC 61131 DATE literal
    99     """
   102     """
   100     return (DATE_ORIGIN + value).strftime("DATE#%Y-%m-%d")
   103     return (DATE_ORIGIN + value).strftime("DATE#%Y-%m-%d")
   101 
   104 
       
   105 
   102 def generate_datetime(value):
   106 def generate_datetime(value):
   103     """
   107     """
   104     Function converting time duration expressed in day, second and microseconds
   108     Function converting time duration expressed in day, second and microseconds
   105     into a IEC 61131 DATE_AND_TIME literal
   109     into a IEC 61131 DATE_AND_TIME literal
   106     @param value: Time duration to convert
   110     @param value: Time duration to convert
   107     @return: IEC 61131 DATE_AND_TIME literal
   111     @return: IEC 61131 DATE_AND_TIME literal
   108     """
   112     """
   109     return (DATE_ORIGIN + value).strftime("DT#%Y-%m-%d-%H:%M:%S.%f")
   113     return (DATE_ORIGIN + value).strftime("DT#%Y-%m-%d-%H:%M:%S.%f")
       
   114 
   110 
   115 
   111 def generate_timeofday(value):
   116 def generate_timeofday(value):
   112     """
   117     """
   113     Function converting time duration expressed in day, second and microseconds
   118     Function converting time duration expressed in day, second and microseconds
   114     into a IEC 61131 TIME_OF_DAY literal
   119     into a IEC 61131 TIME_OF_DAY literal
   145 
   150 
   146 #-------------------------------------------------------------------------------
   151 #-------------------------------------------------------------------------------
   147 #                            Debug Data Consumer Class
   152 #                            Debug Data Consumer Class
   148 #-------------------------------------------------------------------------------
   153 #-------------------------------------------------------------------------------
   149 
   154 
   150 """
       
   151 Class that implements an element that consumes debug values
       
   152 Value update can be inhibited during the time the associated Debug Viewer is
       
   153 refreshing
       
   154 """
       
   155 
   155 
   156 class DebugDataConsumer:
   156 class DebugDataConsumer:
       
   157     """
       
   158     Class that implements an element that consumes debug values
       
   159     Value update can be inhibited during the time the associated Debug Viewer is
       
   160     refreshing
       
   161     """
   157 
   162 
   158     def __init__(self):
   163     def __init__(self):
   159         """
   164         """
   160         Constructor
   165         Constructor
   161         """
   166         """