From: "björn lundin" <b.f.lundin@gmail.com>
Subject: Re: Hello, and help with GNAT and Windows USB programming
Date: Sun, 9 Feb 2014 13:00:29 -0800 (PST)
Date: 2014-02-09T13:00:29-08:00 [thread overview]
Message-ID: <6d8fc500-b333-42d6-a7bc-e95df93df28c@googlegroups.com> (raw)
In-Reply-To: <da704cfc-3bda-4c39-8a2f-358bb171df37@googlegroups.com>
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
next prev parent reply other threads:[~2014-02-09 21:00 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 [this message]
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
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox