Uart.read(x) returns always one byte
Posted: Wed Nov 05, 2014 8:50 pm
I'm using the UART in 9600,8,E,1 mode. With the latest updates, everything runs fine with the parity and bit settings. So far so good.
However... I was running into another issue that somebody might clarify / explain.
So I'm basically doing:
txdata is an array of 40 bytes that is transmitted ok on my logic analyser.
The target board happily responds with 0x00 immediately afterwards as an acknowledge byte (confirmed on the logic analyser). After another 40msec I get the rest of the response (7 Bytes).
The script is written such that read(1) first checks the ack byte, then another read(3) reads the header etc. as it parses through the received data.
However, read(3) does not return 3 bytes but only one byte...
So if I do
the first three bytes of the frame are correctly printed on the REPL. But if I do
It prints out exactly the same. So it looks as the read(x) does not return x bytes but always one byte. readall by the way always returns the correct frame.
Am I missing something here? Has anybody experienced a similar thing?
However... I was running into another issue that somebody might clarify / explain.
So I'm basically doing:
Code: Select all
self.serial = UART(port)
self.serial.init(9600, bits=8, parity = 0, timeout = 500)
self.serial.write(txdata)
ans = self.serial.read(1)
... check for acknowledge etc
The target board happily responds with 0x00 immediately afterwards as an acknowledge byte (confirmed on the logic analyser). After another 40msec I get the rest of the response (7 Bytes).
The script is written such that read(1) first checks the ack byte, then another read(3) reads the header etc. as it parses through the received data.
However, read(3) does not return 3 bytes but only one byte...
So if I do
Code: Select all
ans = self.serial.read(1)
print (ans)
ans = self.serial.read(1)
print (ans)
ans = self.serial.read(1)
print (ans)
Code: Select all
ans = self.serial.read(1)
print (ans)
ans = self.serial.read(3)
print (ans)
ans = self.serial.read(2)
print (ans)
Am I missing something here? Has anybody experienced a similar thing?