comp.lang.ada
 help / color / mirror / Atom feed
* Asynchronous I/O on a serial device
@ 2011-06-11 21:46 Kim Rostgaard Christensen
  2011-06-12  5:23 ` Randy Brukardt
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Kim Rostgaard Christensen @ 2011-06-11 21:46 UTC (permalink / raw)


Hi there

I am desperately trying to implement a protocol on top of a serial 
transport.

I am running Debian, and for the moment using /dev/ttyACM0 for reading. 
This works fine using standard the Text_IO package and In_File.
Only, when I need to write to the device It fails because It is in 
In_File mode - Obviously.
Reset on the file handle gives me a USE_ERROR exception, probably due to 
it being a special file - please correct me if I am wrong.

Do I need to implement this more system-near/specific, or is there some 
way I can do bi-directional communication like, for instance two file 
handles. (I tried Form => "shared=yes", and it also failed).

It is a usb device that emulates UART, and it seems to be contempt with 
just about any Baud setting.

/Kim



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-11 21:46 Asynchronous I/O on a serial device Kim Rostgaard Christensen
@ 2011-06-12  5:23 ` Randy Brukardt
  2011-06-12  7:33   ` Kim Rostgaard Christensen
  2011-06-12  5:42 ` Yannick Duchêne (Hibou57)
  2011-06-12 21:01 ` anon
  2 siblings, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2011-06-12  5:23 UTC (permalink / raw)


"Kim Rostgaard Christensen" <krc@retrospekt.dk> wrote in message 
news:it0noa$ce3$1@munin.nbi.dk...
> Hi there
>
> I am desperately trying to implement a protocol on top of a serial 
> transport.
>
> I am running Debian, and for the moment using /dev/ttyACM0 for reading. 
> This works fine using standard the Text_IO package and In_File.
> Only, when I need to write to the device It fails because It is in In_File 
> mode - Obviously.
> Reset on the file handle gives me a USE_ERROR exception, probably due to 
> it being a special file - please correct me if I am wrong.

Stream_IO allows changing the mode of an open stream (specifically to handle 
this sort of problem). But whether that is allowed in your specific compiler 
I can't say -- you'll have to experiment.

                        Randy.





^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-11 21:46 Asynchronous I/O on a serial device Kim Rostgaard Christensen
  2011-06-12  5:23 ` Randy Brukardt
@ 2011-06-12  5:42 ` Yannick Duchêne (Hibou57)
  2011-06-12  7:49   ` Kim Rostgaard Christensen
  2011-06-12 21:01 ` anon
  2 siblings, 1 reply; 11+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-06-12  5:42 UTC (permalink / raw)


Le Sat, 11 Jun 2011 23:46:47 +0200, Kim Rostgaard Christensen  
<krc@retrospekt.dk> a écrit:

> Hi there
Hi you :)

> I am desperately trying to implement a protocol on top of a serial  
> transport.
>
> I am running Debian, and for the moment using /dev/ttyACM0 for reading.  
> This works fine using standard the Text_IO package
Not good in my opinion (see later)

> and In_File.
> Only, when I need to write to the device It fails because It is in  
> In_File mode - Obviously.
> Reset on the file handle gives me a USE_ERROR exception, probably due to  
> it being a special file - please correct me if I am wrong.
I do not know about your device node, so I could not say if its writable  
or not, but note you also have Inout_File in Ada (do not know what it  
named Inout_File instead of In_Out_File, but that's another story) beside  
of In_File, so could perfectly have input and output on the file.

> Do I need to implement this more system-near/specific, or is there some  
> way I can do bi-directional communication like, for instance two file  
> handles. (I tried Form => "shared=yes", and it also failed).
I would not say more system specific, but rather more close to some  
implicit specifications here: I am not sure you have good reasons [*] to  
use Text_IO, and you may better have a file of some basic type, like bytes  
or characters (well, a file of the more atomic type your protocol defines).

[*] If something is missing we do not know, tell us.

-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-12  5:23 ` Randy Brukardt
@ 2011-06-12  7:33   ` Kim Rostgaard Christensen
  0 siblings, 0 replies; 11+ messages in thread
From: Kim Rostgaard Christensen @ 2011-06-12  7:33 UTC (permalink / raw)


On 2011-06-12 07:23, Randy Brukardt wrote:
> "Kim Rostgaard Christensen"<krc@retrospekt.dk>  wrote in message
> news:it0noa$ce3$1@munin.nbi.dk...
>> Hi there
>>
>> I am desperately trying to implement a protocol on top of a serial
>> transport.
>>
>> I am running Debian, and for the moment using /dev/ttyACM0 for reading.
>> This works fine using standard the Text_IO package and In_File.
>> Only, when I need to write to the device It fails because It is in In_File
>> mode - Obviously.
>> Reset on the file handle gives me a USE_ERROR exception, probably due to
>> it being a special file - please correct me if I am wrong.
>
> Stream_IO allows changing the mode of an open stream (specifically to handle
> this sort of problem). But whether that is allowed in your specific compiler
> I can't say -- you'll have to experiment.
>
>                          Randy.
>
>
I'm pretty sure I tried Stream_IO and it gave me the same result - 
USE_ERROR, or something similar. The problem is that it is a special 
file. Reset works like a charm on regular files, both in Text and Stream_IO

/Kim



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-12  5:42 ` Yannick Duchêne (Hibou57)
@ 2011-06-12  7:49   ` Kim Rostgaard Christensen
  2011-06-12 10:35     ` Kim Rostgaard Christensen
  2011-06-12 11:04     ` Yannick Duchêne (Hibou57)
  0 siblings, 2 replies; 11+ messages in thread
From: Kim Rostgaard Christensen @ 2011-06-12  7:49 UTC (permalink / raw)


On 2011-06-12 07:42, Yannick Duch�ne (Hibou57) wrote:
> Le Sat, 11 Jun 2011 23:46:47 +0200, Kim Rostgaard Christensen
> <krc@retrospekt.dk> a �crit:
>
>> Hi there
> Hi you :)
Ca va ? ;-)

...
> I do not know about your device node, so I could not say if its writable
> or not, but note you also have Inout_File in Ada (do not know what it
> named Inout_File instead of In_Out_File, but that's another story)
> beside of In_File, so could perfectly have input and output on the file.
The node is writeable, everything works via minicom. A googling reveals, 
at lest to me, that Inout_File is placed solely in the Direct_IO 
package. I will try it out later today.
I will look forward to the Inout_File/In_Out_File tale, someday.

>> Do I need to implement this more system-near/specific, or is there
>> some way I can do bi-directional communication like, for instance two
>> file handles. (I tried Form => "shared=yes", and it also failed).
> I would not say more system specific, but rather more close to some
> implicit specifications here: I am not sure you have good reasons [*] to
> use Text_IO, and you may better have a file of some basic type, like
> bytes or characters (well, a file of the more atomic type your protocol
> defines).
My reasons for using Text_IO is that is a QnD way of getting the input 
protocol logic implemented, while I was fiddling around with the 
bi-directional part.
The protocol is line based ascii encoded base16 values, but the parser 
is not pretty as of this writing (the QnD part)
I agree that it should be changed to something more application specific.

I was suggested to use POSIX.IO, but this is, from my point of view too 
system specific for my primitive application.

/Kim




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-12  7:49   ` Kim Rostgaard Christensen
@ 2011-06-12 10:35     ` Kim Rostgaard Christensen
  2011-06-12 11:04     ` Yannick Duchêne (Hibou57)
  1 sibling, 0 replies; 11+ messages in thread
From: Kim Rostgaard Christensen @ 2011-06-12 10:35 UTC (permalink / raw)


...
> The node is writeable, everything works via minicom. A googling reveals,
> at lest to me, that Inout_File is placed solely in the Direct_IO
> package. I will try it out later today.
No luck. Direct_IO apparently only works on seekable files and gives a 
use error as well.

/Kim



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-12  7:49   ` Kim Rostgaard Christensen
  2011-06-12 10:35     ` Kim Rostgaard Christensen
@ 2011-06-12 11:04     ` Yannick Duchêne (Hibou57)
  2011-06-12 18:06       ` Kim Rostgaard Christensen
  1 sibling, 1 reply; 11+ messages in thread
From: Yannick Duchêne (Hibou57) @ 2011-06-12 11:04 UTC (permalink / raw)


Le Sun, 12 Jun 2011 09:49:04 +0200, Kim Rostgaard Christensen  
<krc@retrospekt.dk> a écrit:

> On 2011-06-12 07:42, Yannick Duchêne (Hibou57) wrote:
>> Le Sat, 11 Jun 2011 23:46:47 +0200, Kim Rostgaard Christensen
>> <krc@retrospekt.dk> a écrit:
>>
>>> Hi there
>> Hi you :)
> Ca va ? ;-)

Ouwaouaw, une grenouille (a froggy ;) ). Tu me connais d'où, dis moi, je  
veux tout savoir :) Sur un forum ? Sur l'autre c.l.a (celui des frenchy) ?

Le Sun, 12 Jun 2011 12:35:58 +0200, Kim Rostgaard Christensen  
<krc@retrospekt.dk> a écrit:

> ...
>> The node is writeable, everything works via minicom. A googling reveals,
>> at lest to me, that Inout_File is placed solely in the Direct_IO
>> package. I will try it out later today.
> No luck. Direct_IO apparently only works on seekable files and gives a  
> use error as well.
>
> /Kim
I had a quick first idea I did not tell about, because I've never tried  
such a thing so far with Ada : could you open it twice, so as to get one  
stream for input and another stream for output ?

I may have a try on a tty (should be close enough) later today or tomorrow  
(but can't promise anything).

-- 
“Syntactic sugar causes cancer of the semi-colons.”  [Epigrams on  
Programming — Alan J. — P. Yale University]
“Structured Programming supports the law of the excluded muddle.” [Idem]
“c++; /* this makes c bigger but returns the old value */” [Anonymous]



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-12 11:04     ` Yannick Duchêne (Hibou57)
@ 2011-06-12 18:06       ` Kim Rostgaard Christensen
  0 siblings, 0 replies; 11+ messages in thread
From: Kim Rostgaard Christensen @ 2011-06-12 18:06 UTC (permalink / raw)


On 2011-06-12 13:04, Yannick Duchêne (Hibou57) wrote:
>> Ca va ? ;-)
>
> Ouwaouaw, une grenouille (a froggy ;) ). Tu me connais d'où, dis moi, je
> veux tout savoir :) Sur un forum ? Sur l'autre c.l.a (celui des frenchy) ?

Je regrette de dire qui n'ont jamais eu le plaisir (or something like that)
No, I'm just a Dane using every excuse he gets, for using his limited 
(and very rusty) French.

> I had a quick first idea I did not tell about, because I've never tried
> such a thing so far with Ada : could you open it twice, so as to get one
> stream for input and another stream for output ?
>
> I may have a try on a tty (should be close enough) later today or
> tomorrow (but can't promise anything).

I'm pretty sure I also went down that road. It raised a USE_ERROR and I 
tracked it down to a paragraph in s-fileio.adb where it raises an error 
if the shared=yes is not set on the file.
As previously mentioned this did not help :-\

/Kim



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-11 21:46 Asynchronous I/O on a serial device Kim Rostgaard Christensen
  2011-06-12  5:23 ` Randy Brukardt
  2011-06-12  5:42 ` Yannick Duchêne (Hibou57)
@ 2011-06-12 21:01 ` anon
  2011-06-14  6:37   ` Kim Rostgaard Christensen
  2 siblings, 1 reply; 11+ messages in thread
From: anon @ 2011-06-12 21:01 UTC (permalink / raw)


To connect to the UART device directly you should use to use the 
Gnat.Sockets.* or AdaSockets packages.

Or you could use PolyORB packages which contains a number of serial
I/O packages. Like:  GNAT.Serial_Communications;


Download => Libre.Adacore.com


In <it0noa$ce3$1@munin.nbi.dk>, Kim Rostgaard Christensen <krc@retrospekt.dk> writes:
>Hi there
>
>I am desperately trying to implement a protocol on top of a serial 
>transport.
>
>I am running Debian, and for the moment using /dev/ttyACM0 for reading. 
>This works fine using standard the Text_IO package and In_File.
>Only, when I need to write to the device It fails because It is in 
>In_File mode - Obviously.
>Reset on the file handle gives me a USE_ERROR exception, probably due to 
>it being a special file - please correct me if I am wrong.
>
>Do I need to implement this more system-near/specific, or is there some 
>way I can do bi-directional communication like, for instance two file 
>handles. (I tried Form => "shared=yes", and it also failed).
>
>It is a usb device that emulates UART, and it seems to be contempt with 
>just about any Baud setting.
>
>/Kim




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-12 21:01 ` anon
@ 2011-06-14  6:37   ` Kim Rostgaard Christensen
  2011-06-15 17:02     ` Simon Clubley
  0 siblings, 1 reply; 11+ messages in thread
From: Kim Rostgaard Christensen @ 2011-06-14  6:37 UTC (permalink / raw)


On 2011-06-12 23:01, anon@att.net wrote:
> To connect to the UART device directly you should use to use the
> Gnat.Sockets.* or AdaSockets packages.
>
> Or you could use PolyORB packages which contains a number of serial
> I/O packages. Like:  GNAT.Serial_Communications;

The GNAT.Serial_Communications is just what I needed, although It gives 
some extra conversion overhead.

Can anyone give an example on how to use Gnat.Sockets/AdaSockets for 
accessing a UART device? I have only used it for IPv4 networking and 
Bluetooth.

Best
Kim



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Asynchronous I/O on a serial device
  2011-06-14  6:37   ` Kim Rostgaard Christensen
@ 2011-06-15 17:02     ` Simon Clubley
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Clubley @ 2011-06-15 17:02 UTC (permalink / raw)


On 2011-06-14, Kim Rostgaard Christensen <krc@retrospekt.dk> wrote:
> On 2011-06-12 23:01, anon@att.net wrote:
>> To connect to the UART device directly you should use to use the
>> Gnat.Sockets.* or AdaSockets packages.
>>
>> Or you could use PolyORB packages which contains a number of serial
>> I/O packages. Like:  GNAT.Serial_Communications;
>
> The GNAT.Serial_Communications is just what I needed, although It gives 
> some extra conversion overhead.
>

You may wish to read through a thread from about 2 months ago about this
package in which it was discovered that it is forcing RTS/CTS flow control.

This will cause you problems unless your device is using RTS/CTS flow
control.

Simon.

-- 
Simon Clubley, clubley@remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-06-15 17:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-11 21:46 Asynchronous I/O on a serial device Kim Rostgaard Christensen
2011-06-12  5:23 ` Randy Brukardt
2011-06-12  7:33   ` Kim Rostgaard Christensen
2011-06-12  5:42 ` Yannick Duchêne (Hibou57)
2011-06-12  7:49   ` Kim Rostgaard Christensen
2011-06-12 10:35     ` Kim Rostgaard Christensen
2011-06-12 11:04     ` Yannick Duchêne (Hibou57)
2011-06-12 18:06       ` Kim Rostgaard Christensen
2011-06-12 21:01 ` anon
2011-06-14  6:37   ` Kim Rostgaard Christensen
2011-06-15 17:02     ` Simon Clubley

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