?
Solved

C++Builder3 -putting values into an array

Posted on 2001-06-09
4
Medium Priority
?
1,394 Views
Last Modified: 2008-03-17
Data Acquistion program written using Borlands C++builder3:
 I am using a driver function to return a value which I then intend to plot using TPerformanceGraph. I would like to lable the axis (not an included feature of TPerformanceGraph), particularly the x-axis,which will be time.

void __fastcall TForm1::Button2Click(TObject *Sender)
{


   if (gnNumOfSubdevices == 0)

   DRV_DeviceOpen(DeviceList[gwDevice].dwDeviceNum,
                            (LONG far *)&DriverHandle);
   else

   DRV_DeviceOpen(SubDeviceList[gwSubDevice].dwDeviceNum,
                                       
                               (LONG far *)&DriverHandle);
           

            ptAIVoltageIn.chan = gwChannel;
            ptAIVoltageIn.gain = ptAIConfig.DasGain;
            ptAIVoltageIn.TrigMode = 0; // internal trigger
            ptAIVoltageIn.voltage = (FLOAT far *)&fVoltage;


            DRV_AIVoltageIn(DriverHandle,
                       (LPT_AIVoltageIn)&ptAIVoltageIn);



        for(i=0;i<1000000;i++)
       {
       DRV_AIVoltageIn(DriverHandle,
                         (LPT_AIVoltageIn)&ptAIVoltageIn);
       
        data[i] =?????????????????????????????????


       PerformanceGraph1->DataPoint(clRed,data[i] );
       PerformanceGraph1->Update();
        }

I need to put values returned by DRV_AIVoltageIn() into my data array, but dont know how.
The closest I've come has been with the following code:
data[i] = *(ptAIVoltageIn.voltage);
...which only allows me to compile, but causes a crash because of illegal use of a float blah blah blah. (makes my eyes hurt to read it.
Here's some info on the driver functions:


DRV_AIVoltageIn
status = DRV_AIVoltageIn(DriverHandle, lpAIVoltageIn)

Purpose:
Reads an analog input channel and returns the result scaled to a voltage. (units = volts)
Parameters:
Name            Direction     Type           Description

DriverHandle     Input             long          assigned by
                                             DRV_DeviceOpen

lpVoltageIn   Input/Output  long pointer to    the storage
                             PT_AIVoltageIn    address for                                            chan,gain  
                                              TrigMode and
                                               voltage

Return:  
1) SUCCESS if successful
2) InvalidDriverHandle if DriverHandle = NULL
3) AIConversionFailed if A/D conversion failed
4) DataNotReady if TrigMode=1 and data is not ready
5) AIScale return code


PT_AIVoltageIn
           typedef struct tagPT_AIVoltageIn
       {
     USHORT      chan;
     USHORT      gain;
     USHORT      TrigMode;
     FLOAT far   *voltage;

       } PT_AIVoltageIn, FAR * LPT_AIVoltageIn;

PT_AIVoltageIn is used by DRV_AIVoltageIn function .

Member
Name     Direction     Type          Description
chan     Input         unsignedshort     the sampled channel

gain     Input        unsigned short        gain code

TrigMode  Input         unsigned short     trigger mode

voltage       Output    long pointer
                   to floating-point     measured voltage
                                        returned, scaled
                                        to units of volts


Thanks again for all your help,
Richie.
0
Comment
Question by:RLawless
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 1200 total points
ID: 6171004
>>  Because my values are coming from a for loop the timing may
>> vary if there is other demands on the system (?).
Thsi could be a gigantic effect.  Your app could be suspended for long periods of time, like say a tenth of a second.  That doesn't sound like mutch, but you might be able to collect 1000 data points in that time.  So it has a drastic effect on the data.

Your best bet is to use external hardware to collect the data and provide it to the computer.  Or to use an external device that provides both a data point and a time at which it was collected.

Less good would be to remove the assumption that the values are equally spaced (in time) and collect both the time and the values.  The problem is that you have assume that the program is not suspended between the time the time is obtained and the value is obtained.  There's no way to prevent that.  however increasing the priority fo the thread will help.
0
 

Expert Comment

by:robertmitchell_99
ID: 6181005
Hi RLawless,

Generally, when I encounter this problem I use the following snippet.

memcpy( &( ( *data )[ i] ), (void*)&ptAIVoltageIn.voltage, sizeof( ptAIVoltageIn.voltage) );

I'm posting this as a comment as im not 100% sure that it'll work in your case as there is insufficient code to compile reliably.

You can award some points if it works but let me know either way.

Best of luck


Robert.
0
 
LVL 11

Expert Comment

by:griessh
ID: 6811732
I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days.
Unless there is objection or further activity,  I will suggest to accept "nietod" comment(s) as an answer.

If you think your question was not answered at all, you can post a request in Community support (please include this link) to refund your points.
The link to the Community Support area is: http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt

Please do not accept this comment as an answer!
======
Werner
0
 
LVL 5

Expert Comment

by:Netminder
ID: 6828363
Force/accepted by

Netminder
Community Support Moderator
Experts Exchange
0

Featured Post

Introducing Priority Question

Increase expert visibility of your issues by participating in Priority Question, our latest feature for Premium and Team Account holders. Adjust the priority of your question to get emergent issues in front of subject-matter experts for help when you need it most.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question