Hi,
I’m reading data from a UART configured like this:
rs422 <- hardware.uart57; rs422.configure(4800, 8, PARITY_NONE, 1, NO_CTSRTS, rs422_read);
Then the rs422_read function:
`
function rs422_read() {
local response = “”;
local c = rs422.read();
// -1 is UART read empty
while (c!=-1) {
response = response + c.tochar();
c=rs422.read();
if (c==-1)
server.log("**********Got a -1");
}
server.log(response);
}
`
This is logging:
2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] $ 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] H 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] C 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] H 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] D 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] T 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] , 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] 1 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] 8 2016-03-09 15:48:42 UTC+11 [Device] **********Got a -1 2016-03-09 15:48:42 UTC+11 [Device] 4.6,T*22
All that should be on the same line. Does the UART callback get called every time a separate byte comes in? If so, why didn’t that happen on the last line (4.6,T*22)?
I’ve also tried logging the status using CALLBACK_WITH_FLAGS, and it’s usually ‘1’ (ie READ_READY), but sometimes it’s 0 and sometimes it’s 65, values which aren’t documented here: https://electricimp.com/docs/api/hardware/uart/configure/#callback
Do they indicate what’s going on?
Thanks,
James