comp.lang.ada
 help / color / mirror / Atom feed
* How to use GNAT.Serial_Communications ?
@ 2013-09-14  1:39 elbric0
  2013-09-14  5:42 ` Simon Wright
  0 siblings, 1 reply; 3+ messages in thread
From: elbric0 @ 2013-09-14  1:39 UTC (permalink / raw)


Hi,

I am learning Ada and try to figure how to communicate with an electronic device on a serial port.

I think the code to print 'A' to COM1 on Windows should be about that.

----------------------------------------------------------------
with GNAT.Serial_Communications; use GNAT.Serial_Communications;

procedure Test_Serial is

   Serial : Serial_Port;
   C : Character;

begin

   Open (Port => Serial, Name => Name (1));

   C := 'A';

   Character'Write (Serial, C);

   Close (Serial);

end Test_Serial;
----------------------------------------------------------------

However the type of the first parameter of Character'Write is not correct. I get this error message: "expected access to Ada.Streams.Root_Stream_Type'Class".

Can someone tell me what I should put there instead of Serial?

Do you know any tutorial or code example that can help me?

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to use GNAT.Serial_Communications ?
  2013-09-14  1:39 How to use GNAT.Serial_Communications ? elbric0
@ 2013-09-14  5:42 ` Simon Wright
  2013-09-14 12:10   ` jasmin.stlaurent
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Wright @ 2013-09-14  5:42 UTC (permalink / raw)


elbric0 <jasmin.stlaurent@gmail.com> writes:

> with GNAT.Serial_Communications; use GNAT.Serial_Communications;
>
> procedure Test_Serial is
>
>    Serial : Serial_Port;

     Serial : aliased Serial_Port;

>    C : Character;
>
> begin
>
>    Open (Port => Serial, Name => Name (1));
>
>    C := 'A';
>
>    Character'Write (Serial, C);

     Character'Write (Serial'Access, C);

>    Close (Serial);
>
> end Test_Serial;
> ----------------------------------------------------------------
>
> However the type of the first parameter of Character'Write is not
> correct. I get this error message: "expected access to
> Ada.Streams.Root_Stream_Type'Class".
>
> Can someone tell me what I should put there instead of Serial?

... as above; in GNAT.Serial_Communications,

   type Serial_Port is new Ada.Streams.Root_Stream_Type with private;

and, as the error message said, you need an access to one of those.

Serial has to be declared aliased so that 'Access can be taken
(otherwise, who knows, it might be kept in a register).

> Do you know any tutorial or code example that can help me?

Sorry, someone else may.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to use GNAT.Serial_Communications ?
  2013-09-14  5:42 ` Simon Wright
@ 2013-09-14 12:10   ` jasmin.stlaurent
  0 siblings, 0 replies; 3+ messages in thread
From: jasmin.stlaurent @ 2013-09-14 12:10 UTC (permalink / raw)


Thanks Simon! Now it works.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-09-14 12:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-14  1:39 How to use GNAT.Serial_Communications ? elbric0
2013-09-14  5:42 ` Simon Wright
2013-09-14 12:10   ` jasmin.stlaurent

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