Menu

Text_and_Numerical_IO Log in to Edit

IO of Text and Integer Numbers (Signed and Unsigned)

Since AVR-Ada 1.2 there is a new and hopefully cleaner approach to text IO and numerical IO. It is applied via the serial line in the package AVR.Serial. The new approach intends to replace the existing packages AVR.UART and AVR.Int_Img. The general idea originates in Dmitry Kazakov's strings edit package. We also reused quite some of his code.

Text IO

The new package AVR.Serial replaces the pure text IO part of the previous package AVR.UART. AVR.Serial provides the usual routines for sending and receiving Characters and Strings. Strings can be of various formats, notably

  • standard AVR strings
  • C-style zero ended strings
  • strings in program address space
  • formatted strings from the output channel of AVR.Strings.Edit (coming in v1.3)

Input is read into

  • standard AVR strings
  • the input channel of AVR.Strings.Edit (coming in v1.3)

Editing Output

Put ("Hello");

string_edit

Put ("World", Field => 10, Justify => Right, Fill => '.');

string_edit2

Implementation of Text IO

We have a generic package AVR.Generic_Text_IO. The package takes as generic parameters routines for sending and receiving single characters. The package AVR.UART_Basic_Polled provides these routines plus an 'Init' routine and some constants for the different baud rates.

The package AVR.Generic_Text_IO gets instantiated with the help of AVR.UART_Basic_Polled in the

package_relations_avr-serial

Numerical IO

The new package System.Int_Img provides an Ada interface to highly optimized assembler code for converting unsigned numbers to a textual (ASCII) representation. It can handle numbers in the range 0 .. 2^32 - 1 (4294967295) and any radix in the range 2 .. 36. The most direct way to access this routine is through Put_U32 in the package AVR.Strings.Edit.Generic_Integers.

--  Put the unsigned number 'Value' into the buffer 'Target'. 'Last' is
--  the index of the last valid character in 'Target'. A string of
--  length 10 can hold all numbers up to 2^32 base 10. So don't use
--  it for base 2!
procedure Put_U32 (Value  : in Unsigned_32;
                   Base   : in Number_Base := 10;
                   Target : in out AStr11;
                   Last   : out Unsigned_8);

Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.