@@ -82,33 +82,20 @@ def __init__(self, intermediate_yaml_path):
8282
8383 # Simple data has PLC tags, without the index (T101, 1) becomes T101
8484 self .plc_data , self .simple_plc_data = self .generate_plcs ()
85- #self.saved_values = [['iteration', 'timestamp']]
8685
8786 for PLC in self .intermediate_yaml ['plcs' ]:
8887 if 'sensors' not in PLC :
8988 PLC ['sensors' ] = list ()
9089
9190 if 'actuators' not in PLC :
9291 PLC ['actuators' ] = list ()
93- #self.saved_values[0].extend(PLC['sensors'])
94- #self.saved_values[0].extend(PLC['actuators'])
9592
9693 self .update_cache_flag = False
9794 self .plcs_ready = False
9895
99-
100- #self.previous_cache = {}
101- #for ip in self.plc_data:
102- # self.previous_cache[ip] = [0] * len(self.plc_data[ip])
103-
104-
105- #self.cache = {}
106- #for ip in self.plc_data:
107- # self.cache[ip] = [0] * len(self.plc_data[ip])
108-
10996 columns_list = ['iteration' , 'timestamp' ]
11097 columns_list .extend (self .get_scada_tags ())
111- # self.cache = dict.fromkeys(self.get_scada_tags())
98+
11299
113100 self .cache = pd .DataFrame (columns = columns_list )
114101 self .cache .loc [0 ] = 0
@@ -272,7 +259,6 @@ def sigint_handler(self, sig, frame):
272259 Shutdown protocol for the scada, writes the output before exiting.
273260 """
274261 self .stop_cache_update ()
275- #self.cache_thread.join()
276262 self .write_output ()
277263 self .scada_run = False
278264 self .logger .debug ("SCADA shutdown" )
@@ -285,10 +271,6 @@ def write_output(self):
285271 results = self .cache
286272 results .to_csv (self .output_path , index = False )
287273
288- #with self.output_path.open(mode='w') as output:
289- # writer = csv.writer(output)
290- # writer.writerows(self.saved_values)
291-
292274 def generate_plcs (self ):
293275 """
294276 Generates a list of tuples, the first part being the ip of a PLC,
@@ -341,11 +323,12 @@ def update_cache(self, lock, cache_update_time):
341323 try :
342324 values = self .receive_multiple (self .plc_data [plc_ip ], plc_ip )
343325 values_float = [float (x ) for x in values ]
344- with lock :
345- clock = int (self .get_master_clock ())
346- self .cache .loc [clock , self .simple_plc_data [plc_ip ]] = values_float
347- self .cache .loc [clock , 'iteration' ] = clock
348- self .updated_plc [plc_ip ] = True
326+ if len (values_float ) == len (self .simple_plc_data [plc_ip ]):
327+ with lock :
328+ clock = int (self .get_master_clock ())
329+ self .cache .loc [clock , self .simple_plc_data [plc_ip ]] = values_float
330+ self .cache .loc [clock , 'iteration' ] = clock
331+ self .updated_plc [plc_ip ] = True
349332 except Exception as e :
350333 self .logger .error (
351334 "PLC receive_multiple with tags {tags} from {ip} failed with exception '{e}'" .format (
0 commit comments