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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!news.stack.nl!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Hello, and help with GNAT and Windows USB programming Date: Mon, 10 Feb 2014 10:01:06 +0100 Organization: cbb software GmbH Message-ID: <1te1z431ssp0n$.seqpj6fveef2.dlg@40tude.net> References: Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: I5Na6+WsEzT8WoegI0VZTA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 3276 Xref: number.nntp.dca.giganews.com comp.lang.ada:184768 Date: 2014-02-10T10:01:06+01:00 List-Id: On Sun, 9 Feb 2014 11:59:41 -0800 (PST), Gumpy wrote: > 1. When your laptop has several ports, how do you know or find out which > port a device has been plugged into? Ultimately, I will need a couple > ports for the thermocouple interface and the relay board. Most USB devices come with a C library to access it. I strongly recommend you to use such a library instead of communicating directly to the device, unless you have direct contact to the device vendor. Interfacing a library is pretty straightforward in Ada. At least you must know the class of the USB device. Many vendors simply use the HID (human interface device) as it is easier to use. But you never know. The actual communication protocol heavily depends on the class, and the application level protocol is all vendor-specific. In short, you must contact the vendor for the protocol specification. But better, use the library. Regarding ports, USB supports notifications of device connection and disconnection through the WM_DEVICECHANGE windows message. Typically you would have to handle this message in your application. From there you can read the device ID and act correspondingly. The idea is that you don't need to know the port the device is connected to, differently to RS232, which has no device identification. But again, if you have a vendor library it would handle all that for you. > 2. Using GNAT, and potentially GNAT.Serial_Communications, how does one > open a USB port and read and write character strings to it (the > thermocouple interface has a simple character based command language for > setup and taking temperature readings). That does not work without a hardware converter USB to RS232, as others mentioned. Even with the converter it still might not work in the end. > 3. Does anyone have any specific code examples for communicating on a USB > port that they would like to share, or a link to some example(s) online > somewhere? I have but it is a proprietary code, sorry. However you can find examples in the MSDN. It is complicated, but not a rocket science. Basically you need only Win32Ada. You read from the device using ReadFile. It should be overlapping I/O as it works best with serial communication. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de