comp.lang.ada
 help / color / mirror / Atom feed
* New to Ada..need some help regarding Binary Conversion??
@ 2002-10-15 16:50 Paula
  2002-10-15 17:23 ` Colin Paul Gloster
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Paula @ 2002-10-15 16:50 UTC (permalink / raw)


Hello all,

I am new to the Ada programming language and have worked through the
wonderful material presented on Adapower.com and I have worked through
the Lovelace tutorial.  I was doing prototyping using File IO and have
worked through most of the problems there. My biggest challenge is now
I must read in a "data signal" (which is in binary, in the form of
16-bit words, can be over more than one word, and isn't in a file),
convert it to decimal and apply the correct scaling data to convert it
to engineering units, and then do the reverse (take in engineering
units, convert to raw bus data). I can do the scaling part...no
problem..it's the reading in (I don't understand how to get the input
if it's not in a file or from the keyboard). A coworker suggested
creating a big table of 16-bit binary arrays, that I could declare a
data-type as binary (??). Any help would be appreciated.

Thanks,

Paula



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

* Re: New to Ada..need some help regarding Binary Conversion??
  2002-10-15 16:50 New to Ada..need some help regarding Binary Conversion?? Paula
@ 2002-10-15 17:23 ` Colin Paul Gloster
  2002-10-16 11:06   ` Paula
  2002-10-15 17:48 ` sk
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 8+ messages in thread
From: Colin Paul Gloster @ 2002-10-15 17:23 UTC (permalink / raw)


Paula wrote:

"Hello all,

I am new to the Ada programming language and have worked through the
wonderful material presented on Adapower.com and I have worked through
the Lovelace tutorial.  I was doing prototyping using File IO and have
worked through most of the problems there. My biggest challenge is now
I must read in a "data signal" (which is in binary, in the form of
16-bit words, can be over more than one word, and isn't in a file),
convert it to decimal and apply the correct scaling data to convert it
to engineering units, and then do the reverse (take in engineering
units, convert to raw bus data). I can do the scaling part...no
problem..it's the reading in (I don't understand how to get the input
if it's not in a file or from the keyboard). A coworker suggested
creating a big table of 16-bit binary arrays, that I could declare a
data-type as binary (??). Any help would be appreciated.

Thanks,

Paula"

Hello Paula.

Where exactly is the data signal coming from? You may need to write a
custom
device driver to get at the hardware, and maybe an interrupt service
routine too.
For example mouse drivers are interrupt driven. You may find it helpful
to read
about representation clauses, such as address clauses for interrupts.




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

* Re: New to Ada..need some help regarding Binary Conversion??
  2002-10-15 16:50 New to Ada..need some help regarding Binary Conversion?? Paula
  2002-10-15 17:23 ` Colin Paul Gloster
@ 2002-10-15 17:48 ` sk
  2002-10-16 11:09   ` Paula
  2002-10-15 18:36 ` Jeffrey Carter
  2002-10-15 18:53 ` Larry Hazel
  3 siblings, 1 reply; 8+ messages in thread
From: sk @ 2002-10-15 17:48 UTC (permalink / raw)


Hi,

Pipes ? 

-----------------------
 Test file (hello-txt)
-----------------------
Hello (contents of piped test file).

------------
 Ada source 
------------
with Ada.Text_Io;

procedure Print_Pipe is

    package TIO renames Ada.Text_Io;

    Char : Character;

begin
    loop
        -- Explicit mention of "Standard_Input" and
        -- "Standard_Output" to document ...

        exit when TIO.End_Of_File (TIO.Standard_Input);

        TIO.Get (TIO.Standard_Input, Char);

        TIO.Put (TIO.Standard_Output, Char);

    end loop;

end Print_Pipe;

--------------------------
-- Command line (Linux) --
--------------------------

$ cat hello-txt | print_pipe 
Hello (contents of piped test file).


For your particular criteria (16-bit data), define
your 16-bit data type, use Ada.Text_Io.Text_Streams
to convert Standard_Input to a stream (or use the 
Interfaces.C.Streams <<check package name>> directly)
and do 'Reads or 'Inputs on the stream

   ...
   type My_16_Bits is mod 2**16;


   My_16 : My_16_Bits;
   ...

   In_Stream := Stream (TIO.Standard_Input);

   ...

   My_Value := My_16_Bits'Read (In_Stream);
   
   ...

-- 
-------------------------------------
-- Merge vertically for real address
-------------------------------------
s n p @ t . o
 k i e k c c m
-------------------------------------



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

* Re: New to Ada..need some help regarding Binary Conversion??
  2002-10-15 16:50 New to Ada..need some help regarding Binary Conversion?? Paula
  2002-10-15 17:23 ` Colin Paul Gloster
  2002-10-15 17:48 ` sk
@ 2002-10-15 18:36 ` Jeffrey Carter
  2002-10-15 18:53 ` Larry Hazel
  3 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Carter @ 2002-10-15 18:36 UTC (permalink / raw)


Paula wrote:
> ... My biggest challenge is now
> I must read in a "data signal" (which is in binary ...

> problem..it's the reading in (I don't understand how to get the input
> if it's not in a file or from the keyboard).

If you're not obtaining data from a file, you have to know where you're 
getting it from and how that data source works. If you don't know that, 
we can't help you.

The keyboard is a file called Standard_Input in Ada, so it's not 
necessary to distinguish between files and the keyboard unless you're 
discussing some of the subtle distinctions in how they are used.

-- 
Jeff Carter
"If I could find a sheriff who so offends the citizens of Rock
Ridge that his very appearance would drive them out of town ...
but where would I find such a man? Why am I asking you?"
Blazing Saddles




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

* Re: New to Ada..need some help regarding Binary Conversion??
  2002-10-15 16:50 New to Ada..need some help regarding Binary Conversion?? Paula
                   ` (2 preceding siblings ...)
  2002-10-15 18:36 ` Jeffrey Carter
@ 2002-10-15 18:53 ` Larry Hazel
  3 siblings, 0 replies; 8+ messages in thread
From: Larry Hazel @ 2002-10-15 18:53 UTC (permalink / raw)


Paula wrote:
> Hello all,
> 
> I am new to the Ada programming language and have worked through the
> wonderful material presented on Adapower.com and I have worked through
> the Lovelace tutorial.  I was doing prototyping using File IO and have
> worked through most of the problems there. My biggest challenge is now
> I must read in a "data signal" (which is in binary, in the form of
> 16-bit words, can be over more than one word, and isn't in a file),
> convert it to decimal and apply the correct scaling data to convert it
> to engineering units, and then do the reverse (take in engineering
> units, convert to raw bus data). I can do the scaling part...no
> problem..it's the reading in (I don't understand how to get the input
> if it's not in a file or from the keyboard). A coworker suggested
> creating a big table of 16-bit binary arrays, that I could declare a
> data-type as binary (??). Any help would be appreciated.
> 
> Thanks,
> 
> Paula

This sounds like analog to digital and digital to analog converters.  You have 
to have documentation for how to input/output to these devices.  Then (depending 
on the operating system) you need device drivers, representation clauses to map 
variables to device ports, or assembly level input/output instructions to talk 
to them.

Larry




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

* Re: New to Ada..need some help regarding Binary Conversion??
  2002-10-15 17:23 ` Colin Paul Gloster
@ 2002-10-16 11:06   ` Paula
  2002-10-16 12:27     ` Marin David Condic
  0 siblings, 1 reply; 8+ messages in thread
From: Paula @ 2002-10-16 11:06 UTC (permalink / raw)


Colin Paul Gloster <Colin_Paul_Gloster@ACM.org> wrote in message news:<3DAC4F21.60B7A90D@ACM.org>...
> Paula wrote:
> 
> "Hello all,
> 
> My biggest challenge is now
> I must read in a "data signal" (which is in binary, in the form of
> 16-bit words, can be over more than one word, and isn't in a file),
> convert it to decimal and apply the correct scaling data to convert it
> to engineering units, and then do the reverse (take in engineering
> units, convert to raw bus data). I can do the scaling part...no
> problem..it's the reading in (I don't understand how to get the input
> if it's not in a file or from the keyboard). A coworker suggested
> creating a big table of 16-bit binary arrays, that I could declare a
> data-type as binary (??). Any help would be appreciated.
> 
> Thanks,
> 
> Paula"
> 
> Hello Paula.
> 
> Where exactly is the data signal coming from? You may need to write a
> custom
> device driver to get at the hardware, and maybe an interrupt service
> routine too.
> For example mouse drivers are interrupt driven. You may find it helpful
> to read
> about representation clauses, such as address clauses for interrupts.

The data (from what I understand) is coming from a vme card along a
bus. It will either be MIL-STD-1553, ARINC429, or HW signals. I am
using the Aonix ObjectAda compiler and I'm running it on Win 2000
professional platform.

Paula



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

* Re: New to Ada..need some help regarding Binary Conversion??
  2002-10-15 17:48 ` sk
@ 2002-10-16 11:09   ` Paula
  0 siblings, 0 replies; 8+ messages in thread
From: Paula @ 2002-10-16 11:09 UTC (permalink / raw)


sk <noname@myob.com> wrote in message news:<mailman.1034704382.5852.comp.lang.ada@ada.eu.org>...
> Hi,
> 
> Pipes ? 
> 
> -----------------------
>  Test file (hello-txt)
> -----------------------
> Hello (contents of piped test file).
> 
> ------------
>  Ada source 
> ------------
> with Ada.Text_Io;
> 
> procedure Print_Pipe is
> 
>     package TIO renames Ada.Text_Io;
> 
>     Char : Character;
> 
> begin
>     loop
>         -- Explicit mention of "Standard_Input" and
>         -- "Standard_Output" to document ...
> 
>         exit when TIO.End_Of_File (TIO.Standard_Input);
> 
>         TIO.Get (TIO.Standard_Input, Char);
> 
>         TIO.Put (TIO.Standard_Output, Char);
> 
>     end loop;
> 
> end Print_Pipe;
> 
> --------------------------
> -- Command line (Linux) --
> --------------------------
> 
> $ cat hello-txt | print_pipe 
> Hello (contents of piped test file).
> 
> 
> For your particular criteria (16-bit data), define
> your 16-bit data type, use Ada.Text_Io.Text_Streams
> to convert Standard_Input to a stream (or use the 
> Interfaces.C.Streams <<check package name>> directly)
> and do 'Reads or 'Inputs on the stream
> 
>    ...
>    type My_16_Bits is mod 2**16;
> 
> 
>    My_16 : My_16_Bits;
>    ...
> 
>    In_Stream := Stream (TIO.Standard_Input);
> 
>    ...
> 
>    My_Value := My_16_Bits'Read (In_Stream);
>    
>    ...


Hmmm, ok....this looks more promising. I'll try it. Thanks ;-)

Paula



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

* Re: New to Ada..need some help regarding Binary Conversion??
  2002-10-16 11:06   ` Paula
@ 2002-10-16 12:27     ` Marin David Condic
  0 siblings, 0 replies; 8+ messages in thread
From: Marin David Condic @ 2002-10-16 12:27 UTC (permalink / raw)


This is a pretty broad range of sources. All of this is going to be really
hardware specific and isn't really an Ada question. I'm presuming that you
are doing something embedded with no OS? You'll have to get the hardware
reference materials out and find out specifically how to use these devices.
If you do have an OS, then there is probably some means of getting the data
through the OS and you'll have to look at the documentation for that. Once
you figure out how to read the device, the best thing from there is to use
Ada's fixed point types for the values. This was why they were invented so
any scaled integer business you want to do should start with a clear
understanding of how that works.

MDC
--
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

    "I'd trade it all for just a little more"
        --  Charles Montgomery Burns, [4F10]
======================================================================
Paula <romans_paula@hotmail.com> wrote in message
news:4ee1d187.0210160306.18667d1b@posting.google.com...
>
> The data (from what I understand) is coming from a vme card along a
> bus. It will either be MIL-STD-1553, ARINC429, or HW signals. I am
> using the Aonix ObjectAda compiler and I'm running it on Win 2000
> professional platform.
>
> Paula





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

end of thread, other threads:[~2002-10-16 12:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-15 16:50 New to Ada..need some help regarding Binary Conversion?? Paula
2002-10-15 17:23 ` Colin Paul Gloster
2002-10-16 11:06   ` Paula
2002-10-16 12:27     ` Marin David Condic
2002-10-15 17:48 ` sk
2002-10-16 11:09   ` Paula
2002-10-15 18:36 ` Jeffrey Carter
2002-10-15 18:53 ` Larry Hazel

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