comp.lang.ada
 help / color / mirror / Atom feed
* Hello, and help with GNAT and Windows USB programming
@ 2014-02-09 19:59 Gumpy
  2014-02-09 20:29 ` sbelmont700
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Gumpy @ 2014-02-09 19:59 UTC (permalink / raw)


First, hello. I'm new here. Forgive me if I'm unfamiliar with this and guide me. 

Next, I've been an embedded software engineer for 25+ years, with 18+ in Ada, though I have not worked with Ada for nearly a decade. Pretty much all of my career has been embedded real-time applications, so I've had very little experience with the PC environment, other than from a user perspective. 

I'm also an up and coming potter. It's a hobby I intend to use to help support my retirement some day. 

I have decided that in order to get myself back into Ada and also learn something about programming in the PC environment that I am going to build a kiln controller to convert my manual electric pottery kiln to a fully automatic kiln. I know I could buy an add-on controller for a few hundred dollars, but what's the challenge in that? I figure I can build a simple system that suits my needs and is expandable as I see fit. I can define custom firing schedules that other systems don't accommodate. Ultimately, I may set it up to control multiple kilns.

So, to start with, I found a USB based thermocouple interface that will be used to sense the temperature inside the kiln. I'll add a USB based relay board to this, and the control software will tie it all together. 

I've never worked in programming a PC environment, and have no experience with programming USB ports. I'm not finding a lot of information online, but did find some past messages in this forum which alluded to Linux USB stuff. I thought I'd put out a request for some help and see if anyone will respond. 

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. 

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). 

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'm sure this probably is easier than I'm making it out, but I'm realizing I've forgotten (archived) a good deal of my Ada knowledge in the past decade of non-use, and so I'm just a bit overwhelmed trying to get up and running. I have  the TDC-GCC-64 compilation system installed on my Vista laptop, and have it functional. My Hello World is working and I have found GNAT.Serial_Communications. That's about it so far. 

Any help that along these lines, including code snippets would be greatly appreciated. 

Craig


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

* Re: Hello, and help with GNAT and Windows USB programming
  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
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: sbelmont700 @ 2014-02-09 20:29 UTC (permalink / raw)


Without getting too much into it, no, it's not easier than you are making it, and likely much harder.  USB is a bus topology, unlike RS-232, so there are no more point-to-point connections; even if your device is the only one plugged in.  Essentially, you have to 'tag' your data with the ID of the device (et al) and send it to ALL devices, and all the devices except yours ignore it (similar to Ethernet).  You can do it directly through CreateFile() and IOCTL codes, or by now there are probably high level libraries that simplify things (it's been awhile for me, as well).  Even still, I doubt they would be written in Ada.

-sb

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

* Re: Hello, and help with GNAT and Windows USB programming
  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:26 ` Dennis Lee Bieber
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: björn lundin @ 2014-02-09 21:00 UTC (permalink / raw)


Den söndagen den 9:e februari 2014 kl. 20:59:41 UTC+1 skrev Gumpy:
> 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). 

if the card is using serial comm, then you want to by a usb-to-serial converter.
It will act like a virtual com-port then
Use it like this (the code spoke with an Arduaino) 

with GNAT.Serial_Communications;
with Ada.Streams;
procedure Serial_Talker is
  TTY : GNAT.Serial_Communications.Serial_Port;
  ------------------------
  function String_To_Stream ( The_String : in String) return Ada.Streams.Stream_Element_Array is
    Return_Value : Ada.Streams.Stream_Element_Array(1..The_String'length);
  begin
    for Count in 1..Ada.Streams.Stream_Element_Offset(The_String'Length) loop
       Return_Value(Count) := Character'pos(The_String(Integer(Count)));
    end loop;
    return Return_Value(1..The_String'Length);
  end String_To_Stream;
  ------------------------
begin
 TTY.Open(Name => "/dev/ttyUSB0");
 TTY.Set (Rate      => GNAT.Serial_Communications.B9600,
          Bits      => GNAT.Serial_Communications.CS8,
          Stop_Bits => GNAT.Serial_Communications.One,
          Parity    => GNAT.Serial_Communications.None,
          Block     => True);
 TTY.Write(Buffer => (String_To_Stream("1"))); -- whatever you'd like
 TTY.Close;
end Serial_Talker;


need -gnat05 to compile

it was on Linux, and on Win
 TTY.Open(Name => "/dev/ttyUSB0");
would be like
 TTY.Open(Name => "COM4");
or perhaps 
 TTY.Open(Name => "COM4:");
or 
 TTY.Open(Name => "\\.\COM4");
or 
 TTY.Open(Name => "\\\\.\\COM4");


But i'm not sure you'd use serial comm though.

I have a velleman k8055
<http://www.velleman.eu/products/view/?country=be&lang=en&id=351346>
which I interfaced with bundled dlls.
No serial comm at all.
It involved looping around the usb devices and finding the card, with
id of manufacturer etc.

I have it on a broken machine, but I might be able to dig it up tomorrow,
if you think it will help
> 
> 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? 
 
yes, as above


/Björn




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

* Re: Hello, and help with GNAT and Windows USB programming
  2014-02-09 21:00 ` björn lundin
@ 2014-02-09 22:18   ` Gumpy
  2014-02-09 23:37     ` Dennis Lee Bieber
  0 siblings, 1 reply; 9+ messages in thread
From: Gumpy @ 2014-02-09 22:18 UTC (permalink / raw)


Thanks for your response. I think I replied directly to you instead of to the thread, so not sure where that went.


> if the card is using serial comm, then you want to by a usb-to-serial converter.
> 
> It will act like a virtual com-port then
> 
> Use it like this (the code spoke with an Arduaino) 
> 
...
> 
> But i'm not sure you'd use serial comm though.
> 

Thank  you for the code snippet. This is along the lines of where I was headed. I will study it in detail. 

What reservations do you have about using Serial Comm?

The thermocouple device I'm using is an Omega UTC-USB: http://www.omega.com/pptst/UTC-USB.html

There is a command reference manual here: ftp://ftp.omega.com/public/DASGroup/products/UTC-USB/UTC_USB-Command_Reference.pdf

The serial communications setup is listed at the beginning of the manual. It's actually a very simple command set consisting of short strings terminated by <cr>. It seems GNAT.Serial_Communications should work well for this but maybe there's a better way? 



> 
> 
> I have a velleman k8055
> 
> <http://www.velleman.eu/products/view/?country=be&lang=en&id=351346>
> 
> which I interfaced with bundled dlls.
> 
> No serial comm at all.
> 
> It involved looping around the usb devices and finding the card, with
> 
> id of manufacturer etc.
> 
> 
> 
> I have it on a broken machine, but I might be able to dig it up tomorrow,
> 
> if you think it will help
> 

If you don't mind, that would be really good. The looping through USB devices is something I was considering if I couldn't find a better way to find and attach a specific device. 

The software that came with the thermocouple interface does contain dll's that were installed for the supplied application. Again, I'm new to PC environment programming, so I don't fully understand the concept of dlls and whether these can be useful to what I'm trying to do. There's a lot for me to learn here. This is one of the reasons I chose this kiln control project. The control part is simple enough, but it requires me to learn some underlying PC concepts in order to get it all working. 

craig

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

* Re: Hello, and help with GNAT and Windows USB programming
  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 23:26 ` Dennis Lee Bieber
  2014-02-10  9:01 ` Dmitry A. Kazakov
  2014-02-12  6:21 ` Per Sandberg
  4 siblings, 0 replies; 9+ messages in thread
From: Dennis Lee Bieber @ 2014-02-09 23:26 UTC (permalink / raw)


On Sun, 9 Feb 2014 11:59:41 -0800 (PST), Gumpy <shepardc@gmail.com>
declaimed the following:

>
>So, to start with, I found a USB based thermocouple interface that will be used to sense the temperature inside the kiln. I'll add a USB based relay board to this, and the control software will tie it all together. 
>
	Adding multiple USB boards could add to the difficulty. Especially if
the boards do NOT appear as serial COMx ports. In that case you may want to
look for a copy of the book "USB Complete" (Jan Axelson).

	If they do appear as serial ports, you may still have the problem that
they may not be on the same COMx port number each time you connect the
boards.

>I've never worked in programming a PC environment, and have no experience with programming USB ports. I'm not finding a lot of information online, but did find some past messages in this forum which alluded to Linux USB stuff. I thought I'd put out a request for some help and see if anyone will respond. 
>
>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. 
>
	You might want to consider something like
http://www.velleman.eu/products/view/?country=be&lang=en&id=351346 which
has a downloaded DLL (as I recall, one can wire up to 4 USB addresses, so
one could access multiple cards if needed) [Hmm, I seem to have hit the
European site]. Discontinued but I found one of these at Radio Shack last
summer.

	You'd have to map the DLL into an Ada interface package...

	Or maybe this one; probably replaced the K8055 (and this is the link to
the preassembled module) http://www.velleman.eu/products/view/?id=369162
(unfortunately, Amazon US says Unavailable; same for the K8061 kit version)

>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). 
>
>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'm sure this probably is easier than I'm making it out, but I'm realizing I've forgotten (archived) a good deal of my Ada knowledge in the past decade of non-use, and so I'm just a bit overwhelmed trying to get up and running. I have  the TDC-GCC-64 compilation system installed on my Vista laptop, and have it functional. My Hello World is working and I have found GNAT.Serial_Communications. That's about it so far. 
>
>Any help that along these lines, including code snippets would be greatly appreciated. 
>
>Craig
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

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

* Re: Hello, and help with GNAT and Windows USB programming
  2014-02-09 22:18   ` Gumpy
@ 2014-02-09 23:37     ` Dennis Lee Bieber
  0 siblings, 0 replies; 9+ messages in thread
From: Dennis Lee Bieber @ 2014-02-09 23:37 UTC (permalink / raw)


On Sun, 9 Feb 2014 14:18:27 -0800 (PST), Gumpy <shepardc@gmail.com>
declaimed the following:


>Thank  you for the code snippet. This is along the lines of where I was headed. I will study it in detail. 
>
>What reservations do you have about using Serial Comm?
>
>The thermocouple device I'm using is an Omega UTC-USB: http://www.omega.com/pptst/UTC-USB.html
>

	Based on the download page, it uses the .NET runtime; has anyone
interfaced GNAT with .NET? {Well -- addendum -- the .NET stuff may only
apply to the supplied demo application}

	It does look like EACH thermocouple will require one of these devices,
so even if they appear as COMx ports, your application will have to be able
to select the appropriate port for each of these devices.

>The serial communications setup is listed at the beginning of the manual. It's actually a very simple command set consisting of short strings terminated by <cr>. It seems GNAT.Serial_Communications should work well for this but maybe there's a better way? 
>
	No -- other than the matter of linking to the correct virtual COMx
port.

>
>The software that came with the thermocouple interface does contain dll's that were installed for the supplied application. Again, I'm new to PC environment programming, so I don't fully understand the concept of dlls and whether these can be useful to what I'm trying to do. There's a lot for me to learn here. This is one of the reasons I chose this kiln control project. The control part is simple enough, but it requires me to learn some underlying PC concepts in order to get it all working. 
>

	M$ DLL (dynamic link library) ~= Linux/UNIX SO (shared object)

but with a bit more overhead I think.

	The question now turns into your control side...

-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/


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

* Re: Hello, and help with GNAT and Windows USB programming
  2014-02-09 19:59 Hello, and help with GNAT and Windows USB programming Gumpy
                   ` (2 preceding siblings ...)
  2014-02-09 23:26 ` Dennis Lee Bieber
@ 2014-02-10  9:01 ` Dmitry A. Kazakov
  2014-02-12  6:21 ` Per Sandberg
  4 siblings, 0 replies; 9+ messages in thread
From: Dmitry A. Kazakov @ 2014-02-10  9:01 UTC (permalink / raw)


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


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

* Re: Hello, and help with GNAT and Windows USB programming
  2014-02-09 19:59 Hello, and help with GNAT and Windows USB programming Gumpy
                   ` (3 preceding siblings ...)
  2014-02-10  9:01 ` Dmitry A. Kazakov
@ 2014-02-12  6:21 ` Per Sandberg
  2014-02-19 17:54   ` Gumpy
  4 siblings, 1 reply; 9+ messages in thread
From: Per Sandberg @ 2014-02-12  6:21 UTC (permalink / raw)


Three small steps on the way.
1) get a decent header file with an interface specified in C K8055D.h
2) g++ -c -fdump-ada-spec K8055D.h
3) look into k8055d_h.ada and use it.
Given that you are using a fairly modern gnat/gcc

/Per

On Sun, 9 Feb 2014 11:59:41 -0800 (PST)
Gumpy <shepardc@gmail.com> wrote:

> First, hello. I'm new here. Forgive me if I'm unfamiliar with this
> and guide me. 
> 
> Next, I've been an embedded software engineer for 25+ years, with 18+
> in Ada, though I have not worked with Ada for nearly a decade. Pretty
> much all of my career has been embedded real-time applications, so
> I've had very little experience with the PC environment, other than
> from a user perspective. 
> 
> I'm also an up and coming potter. It's a hobby I intend to use to
> help support my retirement some day. 
> 
> I have decided that in order to get myself back into Ada and also
> learn something about programming in the PC environment that I am
> going to build a kiln controller to convert my manual electric
> pottery kiln to a fully automatic kiln. I know I could buy an add-on
> controller for a few hundred dollars, but what's the challenge in
> that? I figure I can build a simple system that suits my needs and is
> expandable as I see fit. I can define custom firing schedules that
> other systems don't accommodate. Ultimately, I may set it up to
> control multiple kilns.
> 
> So, to start with, I found a USB based thermocouple interface that
> will be used to sense the temperature inside the kiln. I'll add a USB
> based relay board to this, and the control software will tie it all
> together. 
> 
> I've never worked in programming a PC environment, and have no
> experience with programming USB ports. I'm not finding a lot of
> information online, but did find some past messages in this forum
> which alluded to Linux USB stuff. I thought I'd put out a request for
> some help and see if anyone will respond. 
> 
> 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. 
> 
> 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). 
> 
> 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'm sure this probably is easier than I'm making it out, but I'm
> realizing I've forgotten (archived) a good deal of my Ada knowledge
> in the past decade of non-use, and so I'm just a bit overwhelmed
> trying to get up and running. I have  the TDC-GCC-64 compilation
> system installed on my Vista laptop, and have it functional. My Hello
> World is working and I have found GNAT.Serial_Communications. That's
> about it so far. 
> 
> Any help that along these lines, including code snippets would be
> greatly appreciated. 
> 
> Craig


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

* Re: Hello, and help with GNAT and Windows USB programming
  2014-02-12  6:21 ` Per Sandberg
@ 2014-02-19 17:54   ` Gumpy
  0 siblings, 0 replies; 9+ messages in thread
From: Gumpy @ 2014-02-19 17:54 UTC (permalink / raw)


Thanks for the responses. I have been swapped out for a bit by some other projects, so have not been able to evaluate this yet. 

I'm pretty sure I saw a C driver with the USB Thermocouple device software, so I will look at that in more detail and see if I can decipher it. I've done interfacing to C before, but it's been more than a decade, so will have some (more) re-learning to do. 

Will also try the suggestions for the K8055D.h spec. 



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

end of thread, other threads:[~2014-02-19 17:54 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2014-02-12  6:21 ` Per Sandberg
2014-02-19 17:54   ` Gumpy

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