* Ada Tasks and Keyboard I/O
@ 1997-06-13 0:00 David H. Haley
1997-06-14 0:00 ` Robert Dewar
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: David H. Haley @ 1997-06-13 0:00 UTC (permalink / raw)
I have developed a software package in Ada and thought it would be nice
to have the time perodically updated on the screen while waiting for the
user to input a value from the keyboard.
This "sounds" easy enough to do using tasks; however, once the program
reaches the Get(My_Number) statement all other tasks come to a grinding
halt waiting for this keyboard I/O to occur <grr>.
Any ideas how I can accomplish the requirement in para 1 ? I am using
Meridian OpenAda Dos ver 4.1.4, an ADA 83 compiler.
Thank you very much in advance.
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada Tasks and Keyboard I/O
1997-06-13 0:00 Ada Tasks and Keyboard I/O David H. Haley
` (2 preceding siblings ...)
1997-06-14 0:00 ` Larry Kilgallen
@ 1997-06-14 0:00 ` John Herro
3 siblings, 0 replies; 6+ messages in thread
From: John Herro @ 1997-06-14 0:00 UTC (permalink / raw)
"David H. Haley" <dhaley@onlink.net> writes:
> I have developed a software package in Ada and
> thought it would be nice to have the time perodically
> updated on the screen while waiting for the user to
> input a value from the keyboard.
> This "sounds" easy enough to do using tasks;
> however, once the program reaches the Get(My_Number)
> statement, all other tasks come to a grinding halt waiting
> for this keyboard I/O to occur <grr>. ... I am using
> Meridian OpenAda Dos ver 4.1.4, an Ada 83 compiler.
You can use Meridian's TTY.Char_Ready function, and get one
character at a time only when each character is ready. The
following program, which doesn't even use tasking, continually
displays the time while checking for keyboard character ready.
You could optionally improve the program by displaying the
time only if the number of seconds has changed since the last
display, making the display less busy.
The program could also be improved by using a user-defined type
instead of Long_Integer in Show_Time, but the use of the package
TTY makes this program non-portable anyway.
Also, the program will have to be enhanced if you want to process
backspace characters, etc.
- John Herro
Software Innovations Technology
http://members.aol.com/AdaTutor
ftp://members.aol.com/AdaTutor
with TTY; use TTY;
procedure Test is
C : Character := '*';
-- Char. typed by the user.
Number : String(1 .. 40);
Num_Len : Integer := 0;
procedure Show_Time is separate;
begin
Clear_Screen;
Put(Row => 5, Column => 1,
Item => "Type a number:");
while C /= ASCII.CR loop
Show_Time;
if Char_Ready then
-- Get the character:
C := Get(No_Echo => True);
-- Store the character:
Num_Len := Num_Len + 1;
Number(Num_Len) := C;
if C /= ASCII.CR then
-- Echo the character:
Put(Row => 6,
Column => Num_Len,
Item => C);
end if;
end if;
end loop;
Put(Row => 8, Column => 1,
Item => "Your number is " &
Number(1 .. Num_Len));
end Test;
with Calendar; use Calendar;
separate (Test)
procedure Show_Time is
Year, Month, Day : Integer;
Seconds : Duration;
Temp, Hour, Min, Sec : Long_Integer;
begin
Split(Clock, Year, Month, Day, Seconds);
-- Convert seconds since midnight to
-- hours, minutes, seconds:
Temp := Long_Integer(Seconds);
Hour := Temp/3600;
Temp := Temp - 3600*Hour;
Min := Temp/60;
Sec := Temp - 60*Min;
-- Display 2 digits, forcing
-- leading 0 if necessary:
Put(Row => 1, Column => 1,
Item => Long_Integer'Image(
100 + Hour)(3 .. 4) & ":");
Put(Row => 1, Column => 4,
Item => Long_Integer'Image(
100 + Min)(3 .. 4) & ":");
Put(Row => 1, Column => 7,
Item => Long_Integer'Image(
100 + Sec)(3 .. 4));
end Show_Time;
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada Tasks and Keyboard I/O
1997-06-13 0:00 Ada Tasks and Keyboard I/O David H. Haley
1997-06-14 0:00 ` Robert Dewar
@ 1997-06-14 0:00 ` Dale Stanbrough
1997-06-14 0:00 ` Larry Kilgallen
1997-06-14 0:00 ` John Herro
3 siblings, 0 replies; 6+ messages in thread
From: Dale Stanbrough @ 1997-06-14 0:00 UTC (permalink / raw)
David H. Haley writes:
"I have developed a software package in Ada and thought it would be nice
to have the time perodically updated on the screen while waiting for the
user to input a value from the keyboard.
This "sounds" easy enough to do using tasks; however, once the program
reaches the Get(My_Number) statement all other tasks come to a grinding
halt waiting for this keyboard I/O to occur <grr>.
Any ideas how I can accomplish the requirement in para 1 ? I am using
Meridian OpenAda Dos ver 4.1.4, an ADA 83 compiler."
Link with
bamp -I
to provide task preemption, then as one of the first things your program
does (perhaps even in a task elaboration section)...
task_control.pre_emption_on;
This will prevent iio.get from hogging all the limelight.
Package task_control is described as (on p32 of the compiler's user guide)...
package Task_Control is
procedure Pre_Emption_On;
procedure Pre_Emption_Off;
procedure Set_Time_Slice (Quota : Duration);
end Task_Control;
I always did have quite a soft spot for the Meridian Ada compiler. It
seemed to (almost) always do what was expected of it.
Dale
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada Tasks and Keyboard I/O
1997-06-13 0:00 Ada Tasks and Keyboard I/O David H. Haley
1997-06-14 0:00 ` Robert Dewar
1997-06-14 0:00 ` Dale Stanbrough
@ 1997-06-14 0:00 ` Larry Kilgallen
1997-06-14 0:00 ` Robert Dewar
1997-06-14 0:00 ` John Herro
3 siblings, 1 reply; 6+ messages in thread
From: Larry Kilgallen @ 1997-06-14 0:00 UTC (permalink / raw)
In article <33A12825.1C80@onlink.net>, "David H. Haley" <dhaley@onlink.net> writes:
> I have developed a software package in Ada and thought it would be nice
> to have the time perodically updated on the screen while waiting for the
> user to input a value from the keyboard.
>
> This "sounds" easy enough to do using tasks; however, once the program
> reaches the Get(My_Number) statement all other tasks come to a grinding
> halt waiting for this keyboard I/O to occur <grr>.
From an Ada perspective, your task with the "Get" is still computing.
Some compilers support pragma TIME_SLICE to alleviate this for
equal priority tasks, depending on operating system constraints.
> Any ideas how I can accomplish the requirement in para 1 ? I am using
> Meridian OpenAda Dos ver 4.1.4, an ADA 83 compiler.
^^^
Your program must be doing what the operating system views as
asynchronous I/O, so if you insist on DOS it may be that you
must use an add-on OS extender that makes it behave less like
DOS. Some Ada compilers come with such extenders.
Larry Kilgallen
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada Tasks and Keyboard I/O
1997-06-13 0:00 Ada Tasks and Keyboard I/O David H. Haley
@ 1997-06-14 0:00 ` Robert Dewar
1997-06-14 0:00 ` Dale Stanbrough
` (2 subsequent siblings)
3 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1997-06-14 0:00 UTC (permalink / raw)
David says
<<This "sounds" easy enough to do using tasks; however, once the program
reaches the Get(My_Number) statement all other tasks come to a grinding
halt waiting for this keyboard I/O to occur <grr>.
Any ideas how I can accomplish the requirement in para 1 ? I am using
Meridian OpenAda Dos ver 4.1.4, an ADA 83 compiler.
Thank you very much in advance.
>>
The easiest way to accomplish this is to switch to an Ada compiler that
handles this situation properly. What you need is a compiler that follows
the implementation advice concerning Get_Immediate. I am talking about
an Ada 95 compiler of course here.
Alternatively you can interface to an appropriate OS routine to do the
input instead of using Get.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Ada Tasks and Keyboard I/O
1997-06-14 0:00 ` Larry Kilgallen
@ 1997-06-14 0:00 ` Robert Dewar
0 siblings, 0 replies; 6+ messages in thread
From: Robert Dewar @ 1997-06-14 0:00 UTC (permalink / raw)
Larry said
<<Your program must be doing what the operating system views as
asynchronous I/O, so if you insist on DOS it may be that you
must use an add-on OS extender that makes it behave less like
DOS. Some Ada compilers come with such extenders.
>>
It requires nothing this heavy to implement this "properly" on DOS for
the special case of keyboard IO, which is the case you really want handled.
For examle, on the Alsys compilers for DOS, keyboard I/O was always handled
by a polling technique something like
loop
delay epsilon;
if keyboard data present
read it
exit
end if;
end loop;
and you can manually program this if you want, by callng the appropriate
Int 21 routines.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1997-06-14 0:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-06-13 0:00 Ada Tasks and Keyboard I/O David H. Haley
1997-06-14 0:00 ` Robert Dewar
1997-06-14 0:00 ` Dale Stanbrough
1997-06-14 0:00 ` Larry Kilgallen
1997-06-14 0:00 ` Robert Dewar
1997-06-14 0:00 ` John Herro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox