If the serial
package you are using is pySerial, take note of the definition of the Serial.read()
method:
read(size=1)
Parameter: size – Number of bytes to read.
Returns: Bytes read from the port.
Read size bytes from the serial port. If a timeout is set it may return less characters as requested. With no timeout it will block until the requested number of bytes is read.
Changed in version 2.5: Returns an instance of bytes when available (Python 2.6 and newer) and str otherwise.
Although you are trying to process byte
objects, you may (depending on Python version) be handling str
or bytes
(array) objects. These objects do not necessarily correspond to integer values.
Even when receiving byte
objects from read()
, the largest unsigned integer will be 255.
Comparing value
with 400 doesn't make sense. Try to find the type of the returned objects with a simple debugging output.
print type(value)
If you need to handle an str
object, check the use of ord()
for convertion.
(The flush
suggestion refers to the original question, which used print
, not tkinter
).
See how-to-flush-output-of-python-print, and try the command line shell, not the IDE which may affect output buffering.