Firstly the value of 100 is arbitrary. Secondly, the Serial Port has been opened and all was working well until I started to put together previously worked parts. Thirdly, data is always available at the port (at a rate of 100 samples per second), so I can’t see how the condition is never met.
This is the offending code:
Do until Serial1.BytesAvailable > 100
tempBuffer = Serial1.ReadAll(encodings.ASCII)
loop
What I was thinking should happen is that the loop continues until at least 100 bytes are read from the serial port, then that value is assigned to tempBuffer.
Unfortunately it causes the program to a hang (Not Responding). I don’t get any errors and have to abort using the debug stop icon. I’ve tried debugging including a hard coded break, but even that does not allow me to “see” what is happening either.
I’ve spent at least 2hrs reading stuff from the web, and none the wiser. I’m left with wondering if this is a debugging issue or poor programming on my behalf.
What happens if bytesAvailable is > 100 initially? From the code you posted, bytes will never be read.
Else you start to read all available bytes into TempBuffer. So bytesAvailable will be reset. If the serial doesnt have at least 100 Bytes during the next round, you will again read into TempBuffer and, depending on serial1s speed, the loop end condition may never be read.
It would look different if your code were
Do until Serial1.BytesAvailable > 100
loop
tempBuffer = Serial1.ReadAll(encodings.ASCII)
Or are there other parts of your code that catch these circumstances?
After some experimenting, none of the above suggetions worked. In the end I used a timer and then everything fell into place.
I guess my mind is still looking at programming in a “procedural” sense, and difficult to see the “event driven” side. I’d prefer that I make that “event” happen.