From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,52f068e6dc147923 X-Google-Attributes: gid103376,public From: "David C. Hoos, Sr." Subject: Re: Win NT + Object Ada: serial port I/O Date: 1999/02/16 Message-ID: #1/1 X-Deja-AN: 444923210 References: <79952r$2t$1@nnrp1.dejanews.com> <79cu2a$4iu$1@nnrp1.dejanews.com> <7abh8g$bvh$1@nnrp1.dejanews.com> Newsgroups: comp.lang.ada X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Date: 1999-02-16T00:00:00+00:00 List-Id: 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.