I try to write a small communication program with an Arduino using the GNAT.Serial_Communications
package.
Establishing the communication to the Arduino works fine.
I'm using the Serial_Communications.Read()
function to get the Information. Now I want to convert the data stored in a Stream_Element_Array
into an Integer
.
I tried the Integer'Value()
function but it's not working and I receive the error message: expected type "Standard.String"
Using String'Value()
results in: prefix of value attribute must be scalar type
.
I can't find any information about the conversion of a Stream_Element_Array
.
Serial_Communications.Open
(Port => Port,
Name => Port_Name);
Serial_Communications.Set
(Port => Port,
Rate => Serial_Communications.B115200,
Bits => Serial_Communications.CS8,
Stop_Bits => Serial_Communications.One,
Parity => Serial_Communications.Even);
Serial_Communications.Read(Port => Port,
Buffer => Buffer,
Last => Last);
Int_value := Integer'Value(String'Value(Buffer(1)));
Serial_Communications.Close(Port => Port);
From what I've seen in the ARM, a Stream_Element
is a modular type and should by the way already be cast to an Integer
type.
Something like
Int_value := Integer(Buffer(Buffer'First));
should directly work but I didn't test anything ;)