firstly, I would like to thanks to whomever would help me.
- Environment
I am using Python v2.7 in Windows 8 OS. I am using COM4 to tal
In order to be able to communicate with a device, you have to know what the protocol is for that communication. Whoever designed the protocol had to define a way for you to know how many bytes to read. If you have a specification, it probably covers that question.
So, there is either a way to determine number of bytes beforehand or to detect the end of transmission, e.g. by the existance of a special end character.
Without some sort of specification, we can only guess what the protocol is.
'\0'
) at the end? If there is one, you could read character-by-character until it appears.ser = serial.Serial(..., timeout=2, ...)
). Then try to read everything. When there is nothing more to read, the read
function will freeze indefinitely, unless there is a timeout. If you set a reasonably long timeout and no date is received in that time, you can assume the transmission is over.