Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.13 KB | None | 0 0
  1.     def sensors(self):
  2.        
  3.         array_105_x = []
  4.         array_105_y = []
  5.         array_105_z = []
  6.         i = 0
  7.         pbar = tqdm(total=self.time_observation)
  8.        
  9.         self.arduino_port_sensor.reset_input_buffer()
  10.         self.arduino_port_sensor.write(str(1).encode())
  11.         time.sleep(6)
  12.         print("RECIEVED BACK SENSOR:",self.arduino_port_sensor.readline().decode())
  13.        
  14.         while i < self.time_observation:
  15.             value = self.arduino_port_sensor.readline()
  16.             value = value.decode('utf-8', 'ignore')
  17.             if value == '': #если данных нет
  18.                 print('empty')
  19.                 self.sensors() #перезапустить функцию
  20.             v = value.rstrip().replace(" ", "") #разделить данные и тд и тп
  21.             result = [x.strip() for x in v.split(',')]
  22.  
  23.             if len(result) == 4: #интересуют только "целые" строчки
  24.                 if i == 0:
  25.                     try:
  26.                         self.time_start = float(result[0])
  27.                     except ValueError:
  28.                         print('error:', result[0])
  29.                         pass
  30.                 try:
  31.                     array_105_x.append(float(result[1]))
  32.                     array_105_y.append(float(result[2]))
  33.                     array_105_z.append(float(result[3]))
  34.                     i+=1
  35.                     pbar.update(1)
  36.                 except ValueError:
  37.                     print(result)
  38.                     continue
  39.  
  40.         pbar.close()
  41.         self.arduino_port_sensor.reset_input_buffer()
  42.         while True:
  43.             self.arduino_port_sensor.write(str(0).encode())
  44.             try:
  45.                 value = int(self.arduino_port_sensor.readline().decode('utf-8', 'ignore').rstrip().replace(" ", ""))
  46.                 if value == 0:
  47.                     print ('данных нет, все ок', value)
  48.                     break
  49.             except ValueError:
  50.                 continue
  51.  
  52.         self.time_end = float(result[0])        
  53.         return [array_105_x, array_105_y, array_105_z]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement