comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Hello, and help with GNAT and Windows USB programming
Date: Mon, 10 Feb 2014 10:01:06 +0100
Date: 2014-02-10T10:01:06+01:00	[thread overview]
Message-ID: <1te1z431ssp0n$.seqpj6fveef2.dlg@40tude.net> (raw)
In-Reply-To: da704cfc-3bda-4c39-8a2f-358bb171df37@googlegroups.com

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


  parent reply	other threads:[~2014-02-10  9:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-09 19:59 Hello, and help with GNAT and Windows USB programming Gumpy
2014-02-09 20:29 ` sbelmont700
2014-02-09 21:00 ` björn lundin
2014-02-09 22:18   ` Gumpy
2014-02-09 23:37     ` Dennis Lee Bieber
2014-02-09 23:26 ` Dennis Lee Bieber
2014-02-10  9:01 ` Dmitry A. Kazakov [this message]
2014-02-12  6:21 ` Per Sandberg
2014-02-19 17:54   ` Gumpy
replies disabled

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