comp.lang.ada
 help / color / mirror / Atom feed
* RE: How to convert record?
@ 2001-10-31 19:40 Beard, Frank
  2001-11-01  2:13 ` Adrian Hoe
  0 siblings, 1 reply; 24+ messages in thread
From: Beard, Frank @ 2001-10-31 19:40 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'


-----Original Message-----
From: byhoe@greenlime.com [mailto:byhoe@greenlime.com]

> You are wrong. Try compile the following example and you will get 14
> and 16 for each.

I'm not wrong.  Your posts on this thread said nothing about requiring
it to be 11 bytes.  You were asking how to convert it to a POSIX IO_Buffer.

What I was saying is, if ALL YOU WANT TO DO is send and receive it across
homogeneous platforms then you don't need to worry about the size.  Let
the system, via 'size of the object, do it for you.  The compiler will 
do what is more efficient for it's processing.  There's no reason to
work against it unless you have to.

If you are sending it to a device that requires it to be 11 bytes, then
that's a different issue.  And of course a rep spec and pragma pack are
going to make a difference in the size, but that wasn't the issue either.

Your thread on "Size and pack" only led me to believe you expected 11
bytes, but got 14.  NOT that it HAD to be 11.  Expecting one thing and
getting something else does not imply a requirement.

So, which is it?  Does it have to be 11, or are you just sending it to
an equivalent peer system.




^ permalink raw reply	[flat|nested] 24+ messages in thread
* RE: How to convert record?
@ 2001-10-30 19:05 Beard, Frank
  2001-10-31  4:10 ` Adrian Hoe
  0 siblings, 1 reply; 24+ messages in thread
From: Beard, Frank @ 2001-10-30 19:05 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

But using this method it doesn't matter whether it's packed
or not, or whether it's 14 or 11 bytes.  the_Command'size
will give you the size of the "object" being passed in, which
will be translated to the equivalent size IO_Buffer.  So long 
as the receiver is on the same platform (same hardware and
same OS), or represents the data the same way, it will work.
So, there is no need to "take care of" the_Command'Size.

Frank

-----Original Message-----
From: byhoe@greenlime.com [mailto:byhoe@greenlime.com]
Sent: Monday, October 29, 2001 8:18 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: How to convert record?


"Beard, Frank" <beardf@spawar.navy.mil> wrote in message
news:<mailman.1004379548.31870.comp.lang.ada@ada.eu.org>...
> One other thing you might want to consider:
> 
> 
> procedure Write_ABCD (the_Command : Command) is
> 
>    Length : Posix.IO_Count :=
> Posix.IO_Count(the_Command'size/Posix.Posix_Character'size);
>    Buffer : IO_Buffer (1 .. positive(length));
>    for Buffer use at the_Command'address;
> 
> begin
> 
>    POSIX.IO.write (File_Descriptor, Buffer, Length);
> 
> end Write_ABCD;
> 
> 
> I've used it on both Windows and a couple of Unix flavors without
> any problems, but we were always communicating between homogenous 
> platforms (same hardware, same OS).  If you are in a heterogeneous
> environment, you have to use a different method, but you have the
> same problem with Unchecked_Conversion.
> 
> I like it because it's fairly straight forward and it doesn't copy
> data like Unchecked_Conversion, which is particularly good when
> dealing with large buffers.
> 
> Frank


Then you would have to take care of the_Command'Size. The 8-byte
record will give you no problem at all. See my post thread "Size and
Pack".



> 
> -----Original Message-----
> From: joseph_kwan@greenlime.com [mailto:joseph_kwan@greenlime.com]
> 
> 
> Hello,
> 
> I just started to learn Ada and have been playing/working with Ada for
> two weeks now.
> 
> I want to send a command buffer to serial port using florist's POSIX
> interface but I have encountered problems in converting record to
> POSIX.IO.IO_Buffer or Ada.Streams.Stream_Element_Array. How can I
> overcome this problem?
> 
> package ABCD is
> 
>    type Command is
>       record
>           A : Character;
>           B : Character;
>           C : Integer;
>           D : Long_Integer;
>       end record;    -- total 8 bytes;
> 
> ...
> end ABCD;
> 
> 
> POSIX.IO.write (File_Descriptor, Command, Length);
> 
> where 
> 
>    procedure Write
>      (File           : in File_Descriptor;
>       Buffer         : in IO_Buffer;
>       Last           : out POSIX.IO_Count;
>       Masked_Signals : in POSIX.Signal_Masking
>                      := POSIX.RTS_Signals);
> 
> I have searched the CLA but do not find any solutions. Can you please
> help?
> 
> Thank you.
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 24+ messages in thread
* RE: How to convert record?
@ 2001-10-29 18:16 Beard, Frank
  2001-10-30  1:17 ` Adrian Hoe
  0 siblings, 1 reply; 24+ messages in thread
From: Beard, Frank @ 2001-10-29 18:16 UTC (permalink / raw)
  To: 'comp.lang.ada@ada.eu.org'

One other thing you might want to consider:


procedure Write_ABCD (the_Command : Command) is

   Length : Posix.IO_Count :=
Posix.IO_Count(the_Command'size/Posix.Posix_Character'size);
   Buffer : IO_Buffer (1 .. positive(length));
   for Buffer use at the_Command'address;

begin

   POSIX.IO.write (File_Descriptor, Buffer, Length);

end Write_ABCD;


I've used it on both Windows and a couple of Unix flavors without
any problems, but we were always communicating between homogenous 
platforms (same hardware, same OS).  If you are in a heterogeneous
environment, you have to use a different method, but you have the
same problem with Unchecked_Conversion.

I like it because it's fairly straight forward and it doesn't copy
data like Unchecked_Conversion, which is particularly good when
dealing with large buffers.

Frank


-----Original Message-----
From: joseph_kwan@greenlime.com [mailto:joseph_kwan@greenlime.com]


Hello,

I just started to learn Ada and have been playing/working with Ada for
two weeks now.

I want to send a command buffer to serial port using florist's POSIX
interface but I have encountered problems in converting record to
POSIX.IO.IO_Buffer or Ada.Streams.Stream_Element_Array. How can I
overcome this problem?

package ABCD is

   type Command is
      record
          A : Character;
          B : Character;
          C : Integer;
          D : Long_Integer;
      end record;    -- total 8 bytes;

...
end ABCD;


POSIX.IO.write (File_Descriptor, Command, Length);

where 

   procedure Write
     (File           : in File_Descriptor;
      Buffer         : in IO_Buffer;
      Last           : out POSIX.IO_Count;
      Masked_Signals : in POSIX.Signal_Masking
                     := POSIX.RTS_Signals);

I have searched the CLA but do not find any solutions. Can you please
help?

Thank you.
_______________________________________________
comp.lang.ada mailing list
comp.lang.ada@ada.eu.org
http://ada.eu.org/mailman/listinfo/comp.lang.ada



^ permalink raw reply	[flat|nested] 24+ messages in thread
* How to convert record?
@ 2001-10-21  9:56 Joseph Kwan
  2001-10-22 11:30 ` John McCabe
  0 siblings, 1 reply; 24+ messages in thread
From: Joseph Kwan @ 2001-10-21  9:56 UTC (permalink / raw)


Hello,

I just started to learn Ada and have been playing/working with Ada for
two weeks now.

I want to send a command buffer to serial port using florist's POSIX
interface but I have encountered problems in converting record to
POSIX.IO.IO_Buffer or Ada.Streams.Stream_Element_Array. How can I
overcome this problem?

package ABCD is

   type Command is
      record
          A : Character;
          B : Character;
          C : Integer;
          D : Long_Integer;
      end record;    -- total 8 bytes;

...
end ABCD;


POSIX.IO.write (File_Descriptor, Command, Length);

where 

   procedure Write
     (File           : in File_Descriptor;
      Buffer         : in IO_Buffer;
      Last           : out POSIX.IO_Count;
      Masked_Signals : in POSIX.Signal_Masking
                     := POSIX.RTS_Signals);

I have searched the CLA but do not find any solutions. Can you please
help?

Thank you.



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

end of thread, other threads:[~2001-11-01  2:13 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-31 19:40 How to convert record? Beard, Frank
2001-11-01  2:13 ` Adrian Hoe
  -- strict thread matches above, loose matches on Subject: below --
2001-10-30 19:05 Beard, Frank
2001-10-31  4:10 ` Adrian Hoe
2001-10-29 18:16 Beard, Frank
2001-10-30  1:17 ` Adrian Hoe
2001-10-21  9:56 Joseph Kwan
2001-10-22 11:30 ` John McCabe
2001-10-25 11:40   ` Joseph Kwan
2001-10-25 12:38     ` sk
2001-10-25 17:12       ` Jeffrey L. Susanj
2001-10-25 12:48     ` David C. Hoos
2001-10-29  1:42       ` Joseph Kwan
2001-10-29 13:35         ` Marc A. Criley
2001-10-25 12:48     ` Marc A. Criley
2001-10-25 12:54       ` sk
2001-10-25 15:41         ` Ted Dennison
2001-10-26  3:21           ` Smark
2001-10-26  5:45             ` James Rogers
2001-10-26 17:46               ` Smark
2001-10-26 14:30             ` Ted Dennison
2001-10-26 17:42               ` Smark
2001-10-26 20:02                 ` Ted Dennison
2001-10-26 23:10             ` Jeffrey Carter

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