From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: GNAT.Serial_Communication and Streams Date: Sun, 22 Nov 2015 14:54:04 -0700 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Sun, 22 Nov 2015 21:51:45 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="caa759af2a9c666aec02942f6fe5abd6"; logging-data="15310"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+QE136Lfupe7Fg8xngCd2fCs5cRp+51p8=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: X-Mozilla-News-Host: news://freenews.netfront.net Cancel-Lock: sha1:7Sq3e6xp72TssaF7HgO0gOmaF1Y= Xref: news.eternal-september.org comp.lang.ada:28497 Date: 2015-11-22T14:54:04-07:00 List-Id: 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