1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
5 -- G N A T . S E R I A L _ C O M M U N I C A T I O N S --
9 -- Copyright (C) 2007-2008, AdaCore --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 2, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING. If not, write --
19 -- to the Free Software Foundation, 51 Franklin Street, Fifth Floor, --
20 -- Boston, MA 02110-1301, USA. --
22 -- As a special exception, if other files instantiate generics from this --
23 -- unit, or you link this unit with other files to produce an executable, --
24 -- this unit does not by itself cause the resulting executable to be --
25 -- covered by the GNU General Public License. This exception does not --
26 -- however invalidate any other reasons why the executable file might be --
27 -- covered by the GNU Public License. --
29 -- GNAT was originally developed by the GNAT team at New York University. --
30 -- Extensive contributions were provided by Ada Core Technologies Inc. --
32 ------------------------------------------------------------------------------
34 -- Serial communications package, implemented on Windows and GNU/Linux
39 package GNAT.Serial_Communications is
41 Serial_Error : exception;
42 -- Raised when a communication problem occurs
44 type Port_Name is new String;
45 -- A serial com port name
47 function Name (Number : Positive) return Port_Name;
48 -- Returns the port name for the given port number
51 (B1200, B2400, B4800, B9600, B19200, B38400, B57600, B115200);
52 -- Speed of the communication
54 type Data_Bits is (B8, B7);
57 type Stop_Bits_Number is (One, Two);
58 -- One or two stop bits
60 type Parity_Check is (None, Even, Odd);
61 -- Either no parity check or an even or odd parity
63 type Serial_Port is new Ada.Streams.Root_Stream_Type with private;
66 (Port : out Serial_Port;
68 -- Open the given port name. Raises Serial_Error if the port cannot be
73 Rate : Data_Rate := B9600;
74 Bits : Data_Bits := B8;
75 Stop_Bits : Stop_Bits_Number := One;
76 Parity : Parity_Check := None;
77 Block : Boolean := True;
78 Timeout : Duration := 10.0);
79 -- The communication port settings. If Block is set then a read call
80 -- will wait for the whole buffer to be filed. If Block is not set then
81 -- the given Timeout (in seconds) is used. Note that the timeout precision
82 -- may be limited on some implementation (e.g. on GNU/Linux the maximum
83 -- precision is a tenth of seconds).
85 overriding procedure Read
86 (Port : in out Serial_Port;
87 Buffer : out Ada.Streams.Stream_Element_Array;
88 Last : out Ada.Streams.Stream_Element_Offset);
89 -- Read a set of bytes, put result into Buffer and set Last accordingly.
90 -- Last is set to 0 if no byte has been read.
92 overriding procedure Write
93 (Port : in out Serial_Port;
94 Buffer : Ada.Streams.Stream_Element_Array);
95 -- Write buffer into the port
97 procedure Close (Port : in out Serial_Port);
103 type Port_Data_Access is access Port_Data;
105 type Serial_Port is new Ada.Streams.Root_Stream_Type with record
106 H : Port_Data_Access;
109 Data_Rate_Value : constant array (Data_Rate) of Interfaces.C.unsigned :=
119 end GNAT.Serial_Communications;