comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R. Carter" <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: GNAT.Serial_Communication and Streams
Date: Sun, 22 Nov 2015 14:54:04 -0700
Date: 2015-11-22T14:54:04-07:00	[thread overview]
Message-ID: <n2tddf$eue$1@dont-email.me> (raw)
In-Reply-To: <d6318f11-df2c-49bd-928c-2abb766f9c9a@googlegroups.com>

On 11/22/2015 02:40 PM, rrr.eee.27@gmail.com wrote:
>    procedure Send_Command (Cmd : String)
>    is
>       Output_Max_Length : constant Ada.Streams.Stream_Element_Offset := 50;
>       Output : Ada.Streams.Stream_Element_Array (1 .. Output_Max_Length);
>    begin
>       for I in 1 .. Cmd'Length loop
>          Output (Ada.Streams.Stream_Element_Offset(I)) := Character'Pos(Cmd (Cmd'First + I - 1));
>       end loop;
>       Output (Cmd'Length+1) := Character'Pos(ASCII.LF);

What happens when Cmd'Length > 49?

>       GNAT.Serial_Communication.Write (P, Output(1..Cmd'Length+1));
>    end Send_Command;
> 
> 
> That works but feels completely strange to me. I'm sure that I'm missing something here. There must be an easier way to fill the output buffer with a standard string.

What about

procedure Send (Cmd : in String) is
   Local  : constant String := Cmd & Ada.Characters.Latin_1.LF;
   Output : constant Ada.Streams.Stream_Element_Array (1 .. Local'Length);
   pragma Import (Ada, Output);
   for Output'Address use Local'Address;
begin -- Send
   GNAT.Serial_Communication.Write (P, Output)?
end Send;

?

-- 
Jeff Carter
"When danger reared its ugly head, he bravely
turned his tail and fled."
Monty Python and the Holy Grail
60

  parent reply	other threads:[~2015-11-22 21:54 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-22 21:40 GNAT.Serial_Communication and Streams rrr.eee.27
2015-11-22 21:52 ` Simon Wright
2015-11-22 21:54 ` Jeffrey R. Carter [this message]
2015-11-24  1:29   ` Randy Brukardt
2015-11-24 16:09     ` Jeffrey R. Carter
2015-11-24  8:28   ` Dmitry A. Kazakov
2015-11-24 10:28     ` Simon Wright
2015-11-24 10:45       ` Dmitry A. Kazakov
2015-11-25  6:24         ` Shark8
2015-11-25  8:07           ` Simon Wright
2015-11-25  8:52           ` Dmitry A. Kazakov
2015-11-25 12:45             ` Shark8
2015-11-25 17:43               ` Dmitry A. Kazakov
2015-11-29  8:45                 ` Shark8
2015-11-29  9:33                   ` Dmitry A. Kazakov
2015-11-29 11:34                     ` Simon Wright
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox