From: tonyg <tonythegair@gmail.com>
Subject: Re: GNAT.Serial_Communications
Date: Wed, 20 Apr 2011 04:37:30 -0700 (PDT)
Date: 2011-04-20T04:37:30-07:00 [thread overview]
Message-ID: <efb1994c-58ce-4adb-a0e3-916b4858e359@v36g2000prm.googlegroups.com> (raw)
In-Reply-To: iokpeg$scf$1@dont-email.me
On Apr 19, 8:57 pm, "Alex Mentis" <f...@invalid.invalid> wrote:
> Ludovic Brenta wrote:
> > I think you'll have to create a task-specific binding to ioctl(2) to
> > set the flow control options before writing to the port.
>
> ...
>
> > If you're not sure what arguments to pass to ioctl, maybe you can try:
>
> > strace stty --file=/dev/ttyUSB0 -crtscts
>
> Does anyone know if the code below would work? I don't have a Linux box
> handy here, so I can't test it myself. I'm just going off of some notes
> on forking Linux child processes I acquired -- I've never actually done
> this, myself....
>
> ** begin code **
>
> with Ada.Text_IO; use Ada.Text_IO;
> with Interfaces.C;
> with Interfaces.C.Strings;
>
> procedure Main is
>
> procedure Config_Stty is
>
> package C renames Interfaces.C;
>
> -- create an array that contains each portion of the command
> -- to be executed
> -- array must contain a null pointer in the last element
> Stty_Cmd : C.Strings.Chars_Ptr_Array :=
> (C.Strings.New_String ("stty"),
> C.Strings.New_String ("--file=/dev/ttyUSB0"),
> C.Strings.New_String ("-crtscts"),
> C.Strings.Null_Ptr);
>
> -- create an Ada-style prototype as an interface to the C execvp
> -- function and associate the two with an Import pragma
> procedure Execvp (File : C.Strings.Chars_Ptr;
> Args : C.Strings.Chars_Ptr_Array);
> pragma Import (C, Execvp, "execvp");
>
> -- create an Ada-style prototype to the C fork function so
> -- you can call execvp then resume this program's execution
> function Fork return Long_Integer;
> pragma Import (C, Fork, "fork");
>
> -- create an Ada-style prototype to the C waitpid function so
> -- the parent will wait until the forked process completes
> procedure Waitpid (Pid : Long_Integer; Stat_Loc, Options :
> Integer);
> pragma Import (C, Waitpid, "waitpid");
>
> Pid : Long_Integer;
>
> begin -- Config_Stty
>
> Put_Line ("Configuring serial port...");
>
> -- create child process
> Pid := Fork;
>
> if Pid = 0 then -- I'm the child process
> -- call execvp with the stty command
> Execvp (Stty_Cmd (Stty_Cmd'First), Stty_Cmd);
> -- Execvp does not return unless there's an error;
> -- should probably check for that here and raise exception on
> error
> elsif Pid > 0 then -- I'm the parent process
> Waitpid (Pid, 0, 0);
> Put_Line ("Continuing execution...");
> else -- if Fork returns -1, then it was unsuccessful
> Put_Line ("Unable to create new process.");
> end if;
>
> end Config_Stty;
>
> begin -- Main
>
> Config_Stty;
>
> -- serial port's ready to go; do the rest of your stuff here...
>
> end Main;
I don't think this would work because the port's settings need to be
overwritten after it is opened, as Gnat sercom will open it with
control flow enabled. I suspect it may be best to modify the serial
communications package so that there is a control flow option within
the set port procedure. Or to make a copy of the sercom package, call
it something else, modify that and use it.
next prev parent reply other threads:[~2011-04-20 11:37 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-11 10:26 GNAT.Serial_Communications tonyg
2011-04-11 11:11 ` GNAT.Serial_Communications Brian Drummond
2011-04-13 7:49 ` GNAT.Serial_Communications tonyg
2011-04-13 14:12 ` GNAT.Serial_Communications Alex Mentis
2011-04-13 21:12 ` GNAT.Serial_Communications tonyg
2011-04-14 13:15 ` GNAT.Serial_Communications Alex Mentis
2011-04-14 17:52 ` GNAT.Serial_Communications Chris Moore
2011-04-15 13:58 ` GNAT.Serial_Communications tonyg
2011-04-15 16:32 ` GNAT.Serial_Communications tonyg
2011-04-15 17:12 ` GNAT.Serial_Communications Simon Clubley
2011-04-15 17:32 ` GNAT.Serial_Communications tonyg
2011-04-15 18:49 ` GNAT.Serial_Communications Simon Clubley
2011-04-16 0:07 ` GNAT.Serial_Communications tonyg
2011-04-16 8:29 ` GNAT.Serial_Communications Simon Clubley
2011-04-16 10:19 ` GNAT.Serial_Communications tonyg
2011-04-16 10:33 ` GNAT.Serial_Communications tonyg
2011-04-16 11:15 ` GNAT.Serial_Communications Brian Drummond
2011-04-16 12:03 ` GNAT.Serial_Communications tonyg
2011-04-16 15:12 ` GNAT.Serial_Communications Simon Clubley
2011-04-18 20:31 ` GNAT.Serial_Communications tonyg
2011-04-18 20:43 ` GNAT.Serial_Communications tonyg
2011-04-19 11:46 ` GNAT.Serial_Communications tonyg
2011-04-19 12:09 ` GNAT.Serial_Communications Ludovic Brenta
2011-04-19 13:53 ` GNAT.Serial_Communications tonyg
2011-04-19 19:06 ` GNAT.Serial_Communications Ludovic Brenta
2011-04-19 19:57 ` GNAT.Serial_Communications Alex Mentis
2011-04-20 11:37 ` tonyg [this message]
2011-04-20 14:22 ` GNAT.Serial_Communications Alex Mentis
2011-04-21 9:00 ` GNAT.Serial_Communications tonyg
2011-04-21 13:28 ` GNAT.Serial_Communications Alex Mentis
2011-04-22 13:55 ` GNAT.Serial_Communications Alex Mentis
2011-04-22 15:52 ` GNAT.Serial_Communications Brian Drummond
2011-04-19 13:32 ` GNAT.Serial_Communications Simon Clubley
2011-04-19 16:59 ` GNAT.Serial_Communications Simon Clubley
2011-04-20 10:17 ` GNAT.Serial_Communications Brian Drummond
2011-04-20 20:46 ` GNAT.Serial_Communications Brian Drummond
2011-04-21 4:28 ` GNAT.Serial_Communications Simon Wright
2011-04-21 9:12 ` GNAT.Serial_Communications tonyg
2011-04-21 10:14 ` GNAT.Serial_Communications tonyg
2011-04-22 15:54 ` GNAT.Serial_Communications Brian Drummond
2011-04-22 16:14 ` GNAT.Serial_Communications Simon Wright
2011-04-21 11:56 ` GNAT.Serial_Communications Simon Clubley
2011-04-15 18:01 ` GNAT.Serial_Communications Jeffrey Carter
2011-04-16 10:21 ` GNAT.Serial_Communications tonyg
2016-12-01 19:58 ` GNAT.Serial_Communications mario.blunk.gplus
2017-03-20 15:20 ` GNAT.Serial_Communications Jacob Sparre Andersen
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox