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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,cc65ab136f46904d X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!v36g2000prm.googlegroups.com!not-for-mail From: tonyg Newsgroups: comp.lang.ada Subject: Re: GNAT.Serial_Communications Date: Wed, 20 Apr 2011 04:37:30 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: <31dd80b2-3fd3-4078-8774-c396a52c94a0@r6g2000vbz.googlegroups.com> <0d509f1c-4ca7-4595-a026-65c108558d76@bl1g2000vbb.googlegroups.com> <35515c03-f565-4fc4-ac1c-e9b7268123b3@dn9g2000vbb.googlegroups.com> <1144e8e4-4193-4ffd-a8d2-145c38993eb2@p16g2000vbi.googlegroups.com> <6301289c-f450-4d7f-8391-01e17d2555b9@z27g2000prz.googlegroups.com> NNTP-Posting-Host: 82.46.232.121 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1303299451 15527 127.0.0.1 (20 Apr 2011 11:37:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 20 Apr 2011 11:37:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: v36g2000prm.googlegroups.com; posting-host=82.46.232.121; posting-account=28F2IwkAAACL1Z5nRC-dE7zuvWdbWC7P User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-GB; rv:1.9.2.16) Gecko/20110323 Ubuntu/10.04 (lucid) Firefox/3.6.16,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:19889 Date: 2011-04-20T04:37:30-07:00 List-Id: On Apr 19, 8:57=A0pm, "Alex Mentis" 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. =A0 > > =A0... > > > If you're not sure what arguments to pass to ioctl, maybe you can try: > > > strace stty --file=3D/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 > > =A0 =A0procedure Config_Stty is > > =A0 =A0 =A0 package C renames Interfaces.C; > > =A0 =A0 =A0 -- create an array that contains each portion of the command > =A0 =A0 =A0 -- to be executed > =A0 =A0 =A0 -- array must contain a null pointer in the last element > =A0 =A0 =A0 Stty_Cmd : C.Strings.Chars_Ptr_Array :=3D > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(C.Strings.New_String ("stty"), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 C.Strings.New_String ("--file=3D/= dev/ttyUSB0"), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 C.Strings.New_String ("-crtscts")= , > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 C.Strings.Null_Ptr); > > =A0 =A0 =A0 -- create an Ada-style prototype as an interface to the C exe= cvp > =A0 =A0 =A0 -- function and associate the two with an Import pragma > =A0 =A0 =A0 procedure Execvp (File : C.Strings.Chars_Ptr; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Args : C.Strings.Chars_Pt= r_Array); > =A0 =A0 =A0 pragma Import (C, Execvp, "execvp"); > > =A0 =A0 =A0 -- create an Ada-style prototype to the C fork function so > =A0 =A0 =A0 -- you can call execvp then resume this program's execution > =A0 =A0 =A0 function Fork return Long_Integer; > =A0 =A0 =A0 pragma Import (C, Fork, "fork"); > > =A0 =A0 =A0 -- create an Ada-style prototype to the C waitpid function so > =A0 =A0 =A0 -- the parent will wait until the forked process completes > =A0 =A0 =A0 procedure Waitpid (Pid : Long_Integer; Stat_Loc, Options : > Integer); > =A0 =A0 =A0 pragma Import (C, Waitpid, "waitpid"); > > =A0 =A0 =A0 Pid : Long_Integer; > > =A0 =A0begin -- Config_Stty > > =A0 =A0 =A0 Put_Line ("Configuring serial port..."); > > =A0 =A0 =A0 -- create child process > =A0 =A0 =A0 Pid :=3D Fork; > > =A0 =A0 =A0 if Pid =3D 0 then -- I'm the child process > =A0 =A0 =A0 =A0 =A0-- call execvp with the stty command > =A0 =A0 =A0 =A0 =A0Execvp (Stty_Cmd (Stty_Cmd'First), Stty_Cmd); > =A0 =A0 =A0 =A0 =A0-- Execvp does not return unless there's an error; > =A0 =A0 =A0 =A0 =A0-- should probably check for that here and raise excep= tion on > error > =A0 =A0 =A0 elsif Pid > 0 then -- I'm the parent process > =A0 =A0 =A0 =A0 =A0Waitpid (Pid, 0, 0); > =A0 =A0 =A0 =A0 =A0Put_Line ("Continuing execution..."); > =A0 =A0 =A0 else -- if Fork returns -1, then it was unsuccessful > =A0 =A0 =A0 =A0 =A0Put_Line ("Unable to create new process."); > =A0 =A0 =A0 end if; > > =A0 =A0end Config_Stty; > > begin -- Main > > =A0 =A0Config_Stty; > > =A0 =A0-- 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.