[Lazarus] Bls: Example of full screen console program anywhere?
Mr Bee
pak.lebah at yahoo.com
Thu May 5 03:33:20 CEST 2016
If the Free Vision code seems a bit complicated and complex to you, you may want to study the classic CRT unit (from the Turbo Pascal era). Basically it "draws" chars to the console screen, using method like ClrScr, GotoXY, WhereX, WhereY, etc. It's also able to read keystrokes, using method like ReadKey, Keypressed, etc. I think it's good enough for console app with simple interactions. However, I'm not sure whether it works with SSH and unicode.
–Mr Bee
Pada Jumat, 29 April 2016 1:28, Bo Berglund <bo.berglund at gmail.com> menulis:
On Thu, 28 Apr 2016 15:23:01 +0200, Bo Berglund
<bo.berglund at gmail.com> wrote:
I went ahead and created a new Console Application in Lazarus where I
use the same object for controlling the GPIO pins as I did in the GUI
program.
The Console program just initializes the control object then enters
into a repeat loop reading a key from the user and then interpreting
the key in a case construct for valid commands.
It exits if the q key is pressed.
When I run this in Lazarus all operates according to plan but as soon
as I try to run it outside of the GUI, for example in a terminal in
Raspbian or in a PuTTY terminal connected by SSH to the RPi literally
nothing works of the stuff that should happen in the repeat loop!
What I get is the greeting message and then when I press the keys that
should produce the action nothing at all happens including pressing q,
which is the exit code out of the loop and should terminate the
program.
For some reason it was possible to close it using Ctrl-C, though.
In Lazarus I use the debug window "Terminal Output" and here
everything planned works fine!
What a mystery! This is the first time I have encountered such a
difference!
After some further debugging I found that the keypresses are not even
handled in the repeat loop. It uses this type of construct:
//Display main screen
Writeln('Controls are:');
Writeln('p = Toggle 12V SS Power ON/OFF');
Writeln('w = Toggle WiFi Power feed ON/OFF');
Writeln('l = Toggle Alarm Lamp ON/OFF');
Writeln('s = Start SS by sending a 1s pulse');
Writeln('q = Quit the program and reset the control lines');
Writeln('Press any key!');
//Check input and act on commands
repeat
Read(cKey);
case cKey of
'p': //SS Power toggle command
...
until cKey = 'q';
end;
I added debug printing to the case sections to see what was sent in
and the answer was NOTHING!
It seems like Read() does not return anything for a simple key press
unlike what happens in the Lazarus debug window. So the program
probably just hangs on the Read(cKey) command, but in Lazarus it does
not so it is impossible to debug...
Then I tested to use the Enter key and surprise! Now the relays
operate...
But this should happen exactly when the key is pressed not when Enter
is also pressed later. I use Read() instead of Readln() just in order
to get one single key to process...
What could be done to fix this?
>
>--
>Bo Berglund
>Developer in Sweden
--
Bo Berglund
Developer in Sweden
--
_______________________________________________
Lazarus mailing list
Lazarus at lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20160505/e7918192/attachment-0005.html>
More information about the Lazarus
mailing list