Problem of output buffer when using bitlash
I am trying to use Arduino Uno via bitlash: a command-line terminal Serial Interface.
When I add the bitlash to Arduino IDE library and run the bitlash demo script, it build a COM server inside Arduino, and I could control the pins by sending text command from command line terminal tools (such as HyperTerminal in windows) to the Arduino COM.
For example, to read the digital pin 12:
it returns the pin 12’s digital readout: 0
This command blinks the LED connected to D7.
Now I want to use Matlab Serial interface to talk to bitlash COM server inside Arduino.
Obj1 is the COM object.
aStr = ‘print d12’;
% to get the output, run: disp(fgetl(obj1))
print d12 Note: bitlash always echo the command itself, weird
Then Matlab was blocked until timeout, because output buffer is empty.
Usually I run many commands which I do not need the output.
After that, I run a command to read digital value, the output was stored in output buffer.
The problem is that to get that results, I need to run many rounds of disp(fgetl(obj1)) to get the old buffer out, then I could get the most fresh results, and then the output buffer was empty.
I tried to call Matlab function flushoutput(obj1), but it has no effect.
So this is very inconvenient for me to get the output I want.
Is there a way to auto-flush the output buffer so that only the last line remains in output buffer, so that I can read it directly.
Call the tline = fgetl(obj1) repeatedly is a bad idea because I cannot tell how much times to call. And when it returns the last fresh line of output buffer, more calling will block the Matlab until timeout, which is very unwanted.