comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Win NT + Object Ada: serial port I/O
Date: 1999/02/16
Date: 1999-02-16T00:00:00+00:00	[thread overview]
Message-ID: <DDkrrqaW#GA.247@pet.hiwaay.net> (raw)
In-Reply-To: 7abh8g$bvh$1@nnrp1.dejanews.com


lynch@cci.de wrote in message <7abh8g$bvh$1@nnrp1.dejanews.com>...
>In article <79cu2a$4iu$1@nnrp1.dejanews.com>,
>  dennison@telepath.com wrote:
>> In article <79952r$2t$1@nnrp1.dejanews.com>,
>>   lynch@cci.de wrote:
>> > Does anyone have any information/experience programming serial ports in
Ada
>on
>> > a Windows platform? I can think of two ways to do this:

On Windows NT, I use Ordinary File IO -- i.e. I open the file "COM2:" (or
whatever),
using  Gnat.Os_Lib.Open_Read_Write to get a file descriptor.

It should be easy to port the Gnat.OS_lib functions needed to compile with
other Ada compilers, for it uses pragma interface to the C library.

To deal with the ports settings, I write a file called _portsu.bat "on the
fly" with parameters supplied by my program.  Here's an example of
_portsu.bat:
@echo off
mode COM2 baud=2400 data=8 parity=N stop=1

I then execute this batch file with a call to the following subprogram:
----------------------------------------------------------------------------
----
with Interfaces.C;
function Execute_Shell_Command (The_Command_String : String)
      return Interfaces.C.Int is
   Rcsid : constant String:=
      "$Id: execute_shell_command.adb,v 1.3 1998/03/30 02:29:50 dave Exp $";
   package C renames Interfaces.C;
   function System (S : C.Char_Array) return C.Int;
   pragma Import (C, System, "system");
begin
   return System (C.To_C (The_Command_String));
end Execute_Shell_Command;
----------------------------------------------------------------------------
----

The call to the subprogram looks like:
The_Command_Status := Execute_Shell_Command ("_portsu > nul");

When doing serial port programming on Unix systems, I use the Florist
bindings to Posix functions for performing these operations, but when I had
to do it for Win NT, I was in a hurry, and needed something I knew how to
do, so I use this "kludge" -- but it works.

One day, I'll figure out how to do it directly.

The mode setting needs to be done before the file is opened.

I hope this helps.

David C. Hoos, Sr.









  parent reply	other threads:[~1999-02-16  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-02-03  0:00 Win NT + Object Ada: serial port I/O lynch
1999-02-03  0:00 ` news.oxy.com
1999-02-04  0:00   ` lynch
1999-02-04  0:00     ` news.oxy.com
1999-02-04  0:00 ` dennison
1999-02-04  0:00   ` Tom Moran
1999-02-16  0:00   ` lynch
1999-02-16  0:00     ` dennison
1999-02-16  0:00     ` David C. Hoos, Sr. [this message]
1999-02-16  0:00       ` dennison
1999-02-16  0:00     ` dennison
1999-02-17  0:00       ` Peter Hend�n
1999-02-16  0:00     ` Steve Doiel
replies disabled

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