LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Stripchart from generated DAQmx code: can't be resized?

I'm trying to use a stripchart with DAQmx. 

I created the DAQmx tasks as part of my Project.

The DAQmx task has each channel as "continuous samples", "samples to read: 10k, rate 10k". Terminal configuration RSE, no custom scaling.

I auto-generated code as per "Using the DAQ assistant" (http://zone.ni.com/devzone/cda/tut/p/id/4650).

I can't figure out how to modify the size of the chart from the example code.  I can easily change the chart type to stripchart, change colors, etc. but ATTR_WIDTH has no effect on the generated code. It is always approximately 400 pixels wide by 300 pixels tall.

I've modified DAQTaskInProjectExampleCode.c (attached; the UI function is copied below) and created a stub main() file, copied from the above URL also (copied below also)
The only other .c or .h files in the project were auto-generated and untouched by me. (DAQTaskInProject.c , .h, and .mxb; DAQTaskInProjectExpampleCode.h)

I'm sure it's something basic I'm overlooking. Suggestions?

//my main .c

#include <NIDAQmx.h>
#include <cvirte.h>
#include "DAQTaskInProject.h"
/* Header File for Example Code */
#include "DAQTaskInProjectExampleCode.h"

static int32 samplesPerChan;
static float64 data[1000];
static TaskHandle daqTask;

int main (int argc, char *argv[])
{
      if (InitCVIRTE (0, argv, 0) == 0)
         return -1;    /* out of memory */
 
      CreateDAQTaskInProject(&daqTask);
      /* Function Call to Run the Task */ 
      RunDAQTaskInProject (daqTask);
      return 0;
}

// user-interface function from DAQTaskInProjectExampleCode.c
//**************************************************************************
//* The following functions build and manage the user interface.           *
//**************************************************************************
static int32 BuildStartReadWfmLoopStopUI(TaskHandle taskIn, StartReadWfmLoopStopInfo *info,
    int32 *panel)
{
    int32 DAQmxError = DAQmxSuccess;
    float64    max, min, highestMax = 0, lowestMin = 0;
    int32 panelTemp, doneCtrl, chartCtrl, timerCtrl, startCtrl, stopCtrl;
    uInt32 numChannels;
    char **channelNames = NULL;
    unsigned int i;

    DAQmxErrChk(DAQmxGetTaskAttribute (taskIn, DAQmx_Task_NumChans, &numChannels));

    panelTemp = NewPanel (0, "DAQmx Experiment", 0, 0, 10, 10);   // height, width
    SetPanelAttribute (panelTemp, ATTR_CONFORM_TO_SYSTEM, TRUE);
    SetPanelAttribute (panelTemp, ATTR_CAN_MAXIMIZE, FALSE);
    SetPanelAttribute (panelTemp, ATTR_SIZABLE, TRUE);
    SetPanelAttribute (panelTemp, ATTR_WIDTH, 1000);                  // no effect.
    SetPanelAttribute (panelTemp, ATTR_HEIGHT, 1000);
    //SetPanelAttribute (panelTemp,  ATTR_SCALE_CONTENTS_ON_RESIZE, TRUE);
   
    chartCtrl = NewCtrl (panelTemp, CTRL_STRIP_CHART, "", 10, 10); // left, top
    SetCtrlAttribute (panelTemp, chartCtrl, ATTR_NUM_TRACES, numChannels);

    SetCtrlAttribute (panelTemp, chartCtrl, ATTR_SCROLL_MODE, VAL_BLOCK);       // was VAL_SWEEP
    SetCtrlAttribute (panelTemp, chartCtrl, ATTR_XDIVISIONS, 1);
    SetCtrlAttribute (panelTemp, chartCtrl, ATTR_PLOT_BGCOLOR, VAL_BLACK);

   
    startCtrl = NewCtrl (panelTemp, CTRL_SQUARE_COMMAND_BUTTON, kStart, 10, 10);

    stopCtrl = NewCtrl (panelTemp, CTRL_SQUARE_COMMAND_BUTTON, kStop, 10, 10);

    doneCtrl = NewCtrl (panelTemp, CTRL_SQUARE_COMMAND_BUTTON, kDone, 10, 10);
    SetPanelAttribute (panelTemp, ATTR_CLOSE_CTRL, doneCtrl);

    timerCtrl = NewCtrl (panelTemp, CTRL_TIMER, "", 0, 0);

    // Obtain maximum and minimum values across all channels.
    DAQmxErrChk(GetChannelNames (taskIn, numChannels, &channelNames));
    for (i = 0; i < numChannels; i++)
    {
        DAQmxErrChk(DAQmxGetChanAttribute (taskIn, channelNames[i], DAQmx_AI_Min, &min));
        if (i == 0 || min < lowestMin)
            lowestMin = min;
        DAQmxErrChk(DAQmxGetChanAttribute (taskIn, channelNames[i], DAQmx_AI_Max, &max));
        if (i == 0 || max > highestMax)
            highestMax = max;
    }
    SetAxisScalingMode (panelTemp, chartCtrl, VAL_LEFT_YAXIS, VAL_MANUAL, lowestMin, highestMax);

    info->task = taskIn;
    info->startCtrl = startCtrl;
    info->stopCtrl = stopCtrl;
    info->chartCtrl = chartCtrl;
    info->timerCtrl = timerCtrl;
    info->running = 0;

    SetCtrlAttribute (panelTemp, timerCtrl, ATTR_INTERVAL, 0.0);
    SetCtrlAttribute (panelTemp, timerCtrl, ATTR_ENABLED, 0);

    InstallCtrlCallback (panelTemp, startCtrl, StartCB_StartReadWfmLoopStop, info);
    InstallCtrlCallback (panelTemp, doneCtrl, DoneCB_StartReadWfmLoopStop, info);
    InstallCtrlCallback (panelTemp, stopCtrl, StopCB_StartReadWfmLoopStop, info);
    InstallCtrlCallback (panelTemp, timerCtrl, TimerCB_StartReadWfmLoopStop, info);

    PositionControlsOnPanel (panelTemp, 0, chartCtrl, startCtrl, stopCtrl, doneCtrl, 0);

    *panel = panelTemp;

Error:
    if (channelNames)
        FreeChannelNames (channelNames, numChannels);
    return DAQmxError;
}



0 Kudos
Message 1 of 3
(2,836 Views)
Hello drallen,
 
I'm not completely sure whether you are trying to change just the chart width, or the width of the entire panel.
 
If you are just trying to change the chart width, adding a line like this, somewhere below the chartCtrl = NewCtrl (...) line, should work:
 
SetCtrlAttribute (panelTemp, chartCtrl, ATTR_WIDTH, 600);
If you are trying to change the width of the entire panel, keep in mind that in this generated code, the panel width is going to be reset inside the PositionControlsOnPanel function. So if you are trying to set its width beforehand, that won't work, since it will be overriden later.
 
Luis
0 Kudos
Message 2 of 3
(2,830 Views)
Oh- I was setting the panel attribute instead of the control attribute.  Obvious in hindsight. Ugh. 

But thanks!
0 Kudos
Message 3 of 3
(2,825 Views)