1
votes

I'm trying to read data on a serial communication "COM1", using ADA based on RS 422, as the following.

S_Port : Serial_Port;
Buffer : Ada.Streams.Stream_Element_Array(1..150);
GNAT.Serial_Communications.Open(Port => S_Port,Name => "COM1");
GNAT.Serial_Communications.Set(
                               Port => S_Port, Parity => Even, Block => False,
               TimeOut => 4.0
              );


GNAT.Serial_Communications.Read(S_Port,Buffer,Last);

The problem is that although the value of 'Last' changes from 9 to 27, the buffer has much more than 9 or 27 bytes. I thought I can use 'Last' to mark the end of a message, but that is not the case? Also I can't seem to have an unbounded buffer to use the READ function, and must define a certain size?

Thanks in advance.

1

1 Answers

3
votes

I've not worked with this, but the fact that Last is changing values suggests that data is in fact being read in.

Assuming that's happening, since you're reading into a fixed size buffer, there's going to be junk in it unless you initialize the whole thing first. The elements in indices 1..Last will be overwritten, and the rest will be left as the original garbage values.

So the data that was read in is available in Buffer(1 .. Last).