Page 1 of 1

Interrupts, Com Port and Circular buffer.

Posted: Mon Jan 03, 2022 10:40 am
by jay_dee
Hi guys,
In FAD, I have COM port component recieving serial data at a modest 9600 baud.
An interupt is used to collect the byte and pass it to a circular buffer. ( It is ignored if its 0 or 255 ).
A) If there a sensible frequecny for the interupt? Or is there a way to interupt only when reciecing a new character in the Com buffer?

B) Circuar buffer. The main loop looks for my data's start ":" and end ";" characters, then reads out all characters inbetween. This is currently working well. (I think this method was taken from your example or from Ben. :) )
I changed to 'Far Memory' and Storage type is 'last x values'. The process was significantly more reliable but im not sure why.

Is this assumption correct?
If the cirular buffer was a physical stack of characters...incomming data is always added to the top of the stack. Read data is always taken from the bottom of the stack. As such everything is proccessed sequentially. However if the incoming data is greater/faster than the reading process, un-read data will get pushed out of the stack by new incoming data.
Thanks, J.

Re: Interrupts, Com Port and Circular buffer.

Posted: Wed Jan 05, 2022 2:35 pm
by BenR
Hello,

Using the COM port component with a timer interrupt is a good idea. Ideally you should interrupt less frequently and when you do interrupt you should pull in as much data as is available. e.g. keep receiving in a loop with a timeout value of 0 until you get a value of 256. This will put less load on Flowcode jumping in and out of the interrupt and may mean you pull in whole commands in a single pass.

With the circular buffer component last x values will keep putting new data into the buffer and if the buffer becomes full throwing away older data, first x values will store values until the buffer is full and then throw away any new data. If you are reaching the limits of the buffer before you are able to process it then this is not ideal and it might be worth increasing the size of the buffer.

Near/far property shouldn't do anything in the App Developer runtime.