serial_port.write(temp.encode())#отправка значения
else:
output=str(subprocess.Popen(['netcat','localhost','7634'],stdout=subprocess.PIPE,stderr=subprocess.STDOUT).communicate()[0])#получаем output от hddtemp
#b'|/dev/sda2|ST340014A|41|C|'
ifoutput=="b''":
print('Hddtemp output is empty, make sure it is running. If not, launch it with $sudo hddtemp -d')
exit()
#вычленяем значение температуры:
temp_pos_end=output.find('|C|')
temp_pos_start=output.rfind('|',0,temp_pos_end)+1
temp=output[temp_pos_start:temp_pos_end]
try:
int(temp)
#print(temp + ' C')
serial_port.write('a'.encode())
serial_port.write(temp.encode())#отправка значения
exceptValueError:
print('Error: Failed to get a temperature value from hddtemp output')
else:
print('Unknown query from serial device')
exceptOSError:
ifconnected:
print('Serial divice was disconnected. Trying to reconnect...')