comp.lang.ada
 help / color / mirror / Atom feed
From: Roga Danar <nospam@nospam.com>
Subject: One for the Apex guys.
Date: 1998/11/09
Date: 1998-11-09T16:57:34+00:00	[thread overview]
Message-ID: <36472DB8.2498A65B@nospam.com> (raw)

Hi,

  I am still attempting to simply write to a port using Apex Ada
exclusively.  I found some code in the Predefined Subsystem that looked
like it would allow me to do what I wanted.

  Other suggestion solution worked fine but I am require to stay with
Apex.

  I am using Rational Apex Ada95.  The comments tell me that the
Initailize procedure needs to called in elaboration to setup default
files.

Below is the code and the error message I am getting.

Thanks in advance for any help.

######################################  Elaboration code
###################################


package Test_Comm_Elab is

    Ns : constant String := "";

    function Null_Str return String;

end Test_Comm_Elab;

--
-- File Name: test_comm_elab.2.ada
--

with Apex_Predefined_Io_Implementation;
use Apex_Predefined_Io_Implementation;

with Apex_Predefined_Io_Implementation.Text_Io_Support;
use Apex_Predefined_Io_Implementation.Text_Io_Support;

with Ada.Text_Io;
with Ada.Exceptions;
use Ada.Exceptions;

package body Test_Comm_Elab is

    procedure Pl (Item : String) renames Ada.Text_Io.Put_Line;

    function Null_Str return String is
    begin
        return Ns;
    end Null_Str;

begin

    Initialize (Client => Text_Io);

exception
    when E: others =>
        Pl ("Error during elaboration or Initialization call ** " &
            Ada.Exceptions.Exception_Name (E));
end Test_Comm_Elab;


####################################### Main Test Driver
########################################
--
-- File Name: test_comm.2.ada
--

with Apex_Predefined_Io_Implementation;
with Apex_Predefined_Io_Implementation.Common_Io;
with Apex_Predefined_Io_Implementation.Text_Io_Support;

with Apex_Predefined_Io_Implementation.Os_Dependent_Io;

--with Win_Show;
with Port_Des;

with Ada;
with Ada.Text_Io;
with Ada.Exceptions;

with Test_Comm_Elab;

pragma Elaborate (Test_Comm_Elab);
procedure Test_Comm is

    package Io_Imp renames Apex_Predefined_Io_Implementation;
    package Common_Io renames Io_Imp.Common_Io;
    package Os_Dep_Id renames Io_Imp.Os_Dependent_Io;

    package T_Io renames Io_Imp.Text_Io_Support;

    use Io_Imp;

    procedure Create (File : in out Common_Io.File_Type;
                      Mode : in File_Mode;
                      Kind : in File_Kind;
                      Name : in String := "";
                      Form : in String := "";
                      Client : in Client_Kind := Unknown)
       renames Common_Io.Create;

    Com1_Name : Port_Des.Port_Name_Type := Port_Des.Port_Com1;
    Com2_Name : Port_Des.Port_Name_Type := Port_Des.Port_Com2;
    Com3_Name : Port_Des.Port_Name_Type := Port_Des.Port_Com3;
    Com4_Name : Port_Des.Port_Name_Type := Port_Des.Port_Com4;

    type Port_Info_Rec is
        record
            Port_File_Kind : Io_Imp.File_Kind := Io_Imp.Associated;
            Port_File_Mode : Io_Imp.File_Mode := Io_Imp.Inout_File;
            Com_Port_File : Common_Io.File_Type := Common_Io.Null_File;
            Com_Port_Name : Port_Des.Port_Name_Type := Com1_Name;
            Com_Port_Client : Client_Kind := Text_Io;
        end record;

    P_Rec : Port_Info_Rec;

    Com1_Info : constant Port_Info_Rec := P_Rec;

    Com2_Info : constant Port_Info_Rec :=
       (Port_File_Kind => P_Rec.Port_File_Kind,
        Port_File_Mode => P_Rec.Port_File_Mode,
        Com_Port_File => Common_Io.Null_File,
        Com_Port_Client => Text_Io,
        Com_Port_Name => Com2_Name);

    Com3_Info : constant Port_Info_Rec :=
       (Port_File_Kind => P_Rec.Port_File_Kind,
        Port_File_Mode => P_Rec.Port_File_Mode,
        Com_Port_File => Common_Io.Null_File,
        Com_Port_Client => Text_Io,
        Com_Port_Name => Com3_Name);

    Com4_Info : constant Port_Info_Rec :=
       (Port_File_Kind => P_Rec.Port_File_Kind,
        Port_File_Mode => P_Rec.Port_File_Mode,
        Com_Port_File => Common_Io.Null_File,
        Com_Port_Client => Text_Io,
        Com_Port_Name => Com4_Name);

    type Port_Info_Array is array (Port_Des.Ports_Type) of
Port_Info_Rec;

    Port_Info : Port_Info_Array := (Port_Des.Com1 => Com1_Info,
                                    Port_Des.Com2 => Com2_Info,
                                    Port_Des.Com3 => Com3_Info,
                                    Port_Des.Com4 => Com4_Info);

    Control_Block : Os_Dep_Id.Os_Control_Block :=
Os_Dep_Id.Null_Control_Block;

--    procedure Show (S : String;
--                    Caption : in String := " *** Testing *** ")
--      renames Win_Show.Display;

    procedure Putl (Item : String) renames Ada.Text_Io.Put_Line;

begin

--    T_Io.Initialize (Client => Text_Io);

    for Port in Port_Des.Com1 .. Port_Des.Com4 loop -- ports loop

-- Get a lock
--
        Putl ("# Getting Lock for: " & Port_Des.Ports_Type'Image
(Port));
        Common_Io.Acquire (Port_Info (Port).Com_Port_File);

-- Open the port
--
        Putl ("Creating File on port");
        Create_Block:
            begin

                Create (File => Port_Info (Port).Com_Port_File,
                        Mode => Port_Info (Port).Port_File_Mode,
                        Kind => Io_Imp.Associated,
                        Name => Port_Info (Port).Com_Port_Name,
                        Client => Text_Io);


                -- T_Io.Create (File => Port_Info (Port).Com_Port_File,
                --              Mode => Port_Info (Port).Port_File_Mode,

                --              Name => Port_Info (Port).Com_Port_Name,
                --              Client => Text_Io);
                --
                declare

                    procedure Pl (File : T_Io.File_Type; Item : String)
                       renames T_Io.String_Io.Put_Line;

                begin

                    Putl ("# Writing to port #");
                    Pl (File => Port_Info (Port).Com_Port_File,
                        Item => " ### This is Port testing string ###
");

                exception
                    when E: others =>
                        Putl ("Write failed: " &
                              Ada.Exceptions.Exception_Name (E));
                        raise;
                end;

            exception
                when E: others =>
                    Putl ("Create failed: " &
                          Ada.Exceptions.Exception_Name (E));
            end Create_Block;

            --
            --       Control_Block := Common_Io.Os_Dependent_Control;
            --
            -- Os_Dep_Id.Write (Ctrl => Control_Block,
            --                              Item =>
    end loop;

    Putl ("Test DONE!");

exception
    when E: others =>
        Putl ("Unknown exception: " & Ada.Exceptions.Exception_Name
(E));
end Test_Comm;


######################## ERROR MESSAGE ###############################

z:\project\sdf\communication\design\apex.ss\mvs_test.wrk\win_sockets>test_comm

Error during elaboration or Initialization call **
ADA.IO_EXCEPTIONS.STATUS_ERROR
# Getting Lock for: COM4
Creating File on port
Create failed: ADA.IO_EXCEPTIONS.USE_ERROR
Test DONE!





                 reply	other threads:[~1998-11-09  0:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
replies disabled

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