comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Read/write access to Unix character devices
Date: Mon, 21 Dec 2020 19:23:08 -0600	[thread overview]
Message-ID: <rrrhpt$a68$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 6ece98b8-a82e-40e7-9a0e-37b40a175fb0n@googlegroups.com

I would use Stream_IO for this, but you'd need help from your implementer to 
get timeouts/nonblocking I/O. If they have them, they'd be some sort of Form 
parameter (that's what the typically ignored Form parameter is for).

Stream_IO is a lot more flexible that Sequential_IO and Direct_IO. (Some 
implementations implement those older Ada 83 packages in terms of 
Stream_IO.)

                          Randy.

"philip...@gmail.com" <philip.munts@gmail.com> wrote in message 
news:6ece98b8-a82e-40e7-9a0e-37b40a175fb0n@googlegroups.com...
Lately I have been working with Unix (really Linux, FreeBSD, and OpenBSD) 
character devices (these happen to be USB raw HID devices, but the problem 
is more general than that).  The way these work is that each hardware device 
has a character device node file in /dev/, like /dev/hidraw1.  You open the 
file for both read and write access.  Then you can send a command to the 
device by writing a binary blob and get a response by subsequently reading a 
binary blob.  For what I am doing, it is important not to block on reads 
forever if there is not response forthcoming, so I need at least read 
timeouts.

So far, I have been binding the C library functions open(), close(), read(), 
write(), and poll() with pragma Import.  That works, but I have wondered if 
there is some way of accomplishing the same thing more portably.  The 
packages GNAT.Sockets and GNAT.Serial_Communicatons can be viewed as special 
case solutions, but I would like a general solution.

What I would really like is Ada.Sequential_IO with InOut_File and a timeout 
mechanism, perhaps like the select() wrapper in GNAT.Sockets.

So far I haven't found anything in the Ada. or GNAT. that supports 
InOut_File semantics (other than Direct_IO) let alone timeouts.  Does 
anybody have any suggestions?

Phil 


  reply	other threads:[~2020-12-22  1:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-21  4:59 Read/write access to Unix character devices philip...@gmail.com
2020-12-22  1:23 ` Randy Brukardt [this message]
2020-12-28 13:26 ` Björn Lundin
replies disabled

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