From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Path: eternal-september.org!reader02.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: Read/write access to Unix character devices Date: Mon, 21 Dec 2020 19:23:08 -0600 Organization: JSA Research & Innovation Message-ID: References: <6ece98b8-a82e-40e7-9a0e-37b40a175fb0n@googlegroups.com> Injection-Date: Tue, 22 Dec 2020 01:23:09 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="10440"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:60924 List-Id: 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" 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