( raspbian, rp3)
I can send a string from PC console to my GUI (tkinter). An example:
$SK039AR878HT010;
( I send this command manually from console for testing purpose, but in future my console will be replaced by a machine)
This command basically indicates: SK=3.9, AR=87.8 and HT=10% ( progress bar). These values goes to the GUI and set these on the GUI accordingly.
In parallel, the GUI continuously also sends a similar string to the console ( in response to what I sent:$SK039AR878HT010;)
$ST039HT10;
(ST is set on the GUI manually)
Now the problem is the communication protocol says, there should be three digits after each variable. But as can be seen that for HT , it is followed by two digits i.e 10. The correct format is
$ST039HT010;
To achieve the same with ST ( as you can see 039 a three digit is there, which represent 3.9), I did this:
if self.App.stval<10:
self.App.port.write(serial.to_bytes(str.encode('$'+ 'ST'+'0' + str(int(self.App.stval*10))+'HT'+ str(int(self.App.mpb["value"]))+';' )) )
else:
self.App.port.write(serial.to_bytes(str.encode('$'+ 'ST' + str(int(self.App.stval*10))+'HT'+str(int(self.App.mpb["value"]))+';' )) )
here stval is value of ST ( set temperature, done from GUI) which is 3.9 deg C in above case.
That is, whenever I have ST value (stval) less than 10 , I insert a '0'. ST is thus followed by three digits.
I am unable to develop a logic , (also as I am new to python) as to how to do the same three digit formatting with HT? HT is a value on progress bar ( whole number) , and cant go beyond 100%, while ST is room temperature which will hardly exceed 50% ( can be decimal).
I will really appreciate for helping me out in this regard.