Jul-28-2022, 04:37 PM
Good afternoon, there is a code that removes parameters, the request is made 2 times and if the answers match, the data is written to the database. I did not have any problems with this, if the data is not equal - it is printed (the data is not equal) and the program ends. Tell me, how to send the request again under the else condition?
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
timeout=1,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS)
cmd = bytearray([0x1])
ser.write(cmd)
reply = ser.read(22)
out = reply[11:16]
print(out)
time.sleep(0)
cmd = bytearray([0x1])
ser.write(cmd)
reply = ser.read(22)
out2 = reply[11:16]
print(out2)
if out == out2:
cursor = connection.cursor()
sql = "Update silos1 set weight = %s, date = %s where id = %s "
datetime.strptime("12/31/2000", "%m/%d/%Y")
newHireDate = datetime.today()
rowCount = cursor.execute(sql, (out, newHireDate, 1 ) )
connection.commit()
print ("ok", newHireDate)
else:
print ("data is not correct")
connection.close()
