Re: piSerial prints wrong information
Posted: 31 Jan 2021, 19:34
Hello!
The chip goes to sleep after 10 seconds (or 1.3 seconds if so configured, ChipMode bit 2) after it last woke.
So even if you do subsequent requests, it will enter sleep mode eventually.
This is intentionally by design for security reasons.
There are three situations:
* Chip is awake. piSerial will succeed.
* Chip is asleep. piSerial will succeed too.
* Chip is about to go to sleep. piSerial will fail.
You can confirm this by running piSerial and then running it again right away. Or by waiting >10 seconds after first run.
To get the error, you kind of need to get "lucky".
So, what could Kunbus do about it?
A long running program can maintain its own timer and track the state of the chip. It can then send the chip to idle or sleep mode before it goes to sleep automatically, and wake it up again.
But piSerial is running on demand and cannot know the current state.
To synchronize it, send the chip to sleep and then wake it again. Then try reading the "After Wake" token until it works. Reading from the chip wakes it up too.
Only then send the read command and read its result. At the end, send the chip to sleep or idle mode.
Why are you executing piSerial in a loop anyway? It's not like the output will change. Call it once and cache the value. Then use only the cached value.
The chip goes to sleep after 10 seconds (or 1.3 seconds if so configured, ChipMode bit 2) after it last woke.
So even if you do subsequent requests, it will enter sleep mode eventually.
This is intentionally by design for security reasons.
There are three situations:
* Chip is awake. piSerial will succeed.
* Chip is asleep. piSerial will succeed too.
* Chip is about to go to sleep. piSerial will fail.
You can confirm this by running piSerial and then running it again right away. Or by waiting >10 seconds after first run.
To get the error, you kind of need to get "lucky".
So, what could Kunbus do about it?
A long running program can maintain its own timer and track the state of the chip. It can then send the chip to idle or sleep mode before it goes to sleep automatically, and wake it up again.
But piSerial is running on demand and cannot know the current state.
To synchronize it, send the chip to sleep and then wake it again. Then try reading the "After Wake" token until it works. Reading from the chip wakes it up too.
Only then send the read command and read its result. At the end, send the chip to sleep or idle mode.
Why are you executing piSerial in a loop anyway? It's not like the output will change. Call it once and cache the value. Then use only the cached value.