Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

NI USB 6008: expected constant expression

I am using NI USB 6008 device. Looking at NI-DAQ\Examples\DAQmx ANSI C\Analog In\Measure Voltage\Acq-Int Clk\

So I want to modify the line that has
DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByChannel,data,1000,&read,NULL));

as
    DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,numsamps,TimeouT,DAQmx_Val_GroupByChannel,data,numsamps,&read,NULL));

where the corresponding variables have been defined before like:
  Int_t xx=2;
  const Int_t numsamps = const_cast<Int_t&>(xx);
    int32       error=0;
    TaskHandle  taskHandle=0;
    int32       read;
    float64     data[numsamps];
    float64 RatE = float64(raTE);
    float64 TimeouT = float64(numsamps)/RatE;

But when I try to compile I get this error message:
$ nmake -f makefile.mak

Microsoft (R) Program Maintenance Utility Version 8.00.50727.42
Copyright (C) Microsoft Corporation.  All rights reserved.

        cl  -D_MT -D_DLL -MDd -EHsc  -nologo -G5 -GR -MD -DWIN32  -DVISUAL_CPLUS
PLUS -D_WINDOWS -IC:\ROOT/include -O2 -c SNatInDAQ.cpp
cl : Command line warning D9025 : overriding '/MDd' with '/MD'
cl : Command line warning D9002 : ignoring unknown option '-G5'
SNatInDAQ.cpp
SNatInDAQ.cpp(261) : error C2057: expected constant expression
SNatInDAQ.cpp(261) : error C2466: cannot allocate an array of constant size 0
SNatInDAQ.cpp(261) : error C2133: 'data' : unknown size
NMAKE : fatal error U1077: '"c:\Program Files\Microsoft Visual Studio 8\VC\BIN\c
l.EXE"' : return code '0x2'
Stop.

What does it mean 'expected constant expression'? How can I get around this?

What I want to do is pass the size of that data array from another function.
0 Kudos
Message 1 of 4
(8,018 Views)
Hi novaiscool,

I think the issue is that you are declaring numsamps as a constant and the DAQmxReadAnalogF64 function wnats a non constant parameter.  Have you tried calling the function with a regular int or a value?  Give that a try and see if you get the same error. 

You will also need to initialize numsamps to something since you are allocating an array using that variable. 

Give those things a try and let me know how it works.
Thank You,

Nick F.
Applications Engineer
0 Kudos
Message 2 of 4
(8,004 Views)
Hi Nick,

Actually the problem was a C++ slip.

I should've
float64 data = new float64[numsamps]; //and this worked with numsamps being a const

what I had before was
float64 data[numsamps] //which is wrong

Thank you!

0 Kudos
Message 3 of 4
(8,001 Views)
Sorry, the correct version should read
float64 *data = new float64[numsamps]; //and this worked with numsamps being a const
0 Kudos
Message 4 of 4
(8,000 Views)