LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Memory is Corrupt with WriteAnalog

Hello

 

I have a strange issue with Dynamic Memory being corrupt during execution of my program. I have two functions below, both in the same file. The InitializePanels function gets executed as soon as I execute my main panel program. The cls_damper command gets called from some other routine during processing. The taskInletDamper and taskOutletDampers are only used in the file below.

 

ISSUE 1: The Dynamic Memory Corrupt error shows up the first time the system tries to do a DAQmxWriteAnalogScalarF64 in the cls_damper routine - the system points to that line number on the pop up message, and interestingly the column number is always located on the last NULL argument passed there.

 

ISSUE 2: In the .h file declaration, if I include the NIDAQ.h file before the PC_Equates file, then the system gives me an error during compilation, saying there is a redefination of TRUE and FALSE in the PC_Equates file. The PC_Equates file basically has a couple of lines #defining TRUE as 1 and FALSE as 0. If, as shown below, I change the order of PC_Equates and NIDAQ.h, then the error goes away.

 

Any inputs will be greatly appreciated.


Thanks

 

#include <userint.h>
#include <utility.h> 
#include <DAQmxIOctrl.h>
#include <NIDAQmx.h>
#include "PC_Equates.h"

 

#define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
#define MSG_OPN_DAMPERS "17-pr_opn_dampers"
#define MSG_CLS_DAMPERS "17-pr_cls_dampers"
#define PR_CHK_PS           4
#define PR_MES_END          18  

void pr_cls_dampers(void);    
void pr_opn_dampers(void); 
extern void AddScrollLine (char *msg);


int         error=0;
TaskHandle  taskInletDamper   = 0;
TaskHandle  taskExhaustDamper = 0;
TaskHandle  taskDIOHandle     = 0;

char        chanInlet[128]   = "PXI1Slot5/ao0";
char        chanExhaust[128] = "PXI1Slot5/ao1";
char        chanDigital[128] = "PXI1Slot5/port0/line4:5";
double      min = 0.0, max = 10.0;
float64     data;
uInt8       dioData[2];
int i;
char        errBuff[2048]={'\0'};
extern int teststep, step_iter; 
extern int testTickCtr;

 

void InitializeDamperControls(void)
{
    static int iWritten;
 
  #if(USE_NI_IO == 1)

    //--- Create and start the Inlet Damper task ---------------
    DAQmxErrChk (DAQmxCreateTask ("", &taskInletDamper));
    DAQmxErrChk (DAQmxCreateAOVoltageChan (taskInletDamper, chanInlet, "", min, max, DAQmx_Val_Volts, ""));
    DAQmxErrChk (DAQmxStartTask(taskInletDamper));

    //--- Create and start the Exhaust Damper task ------------- 
    DAQmxErrChk (DAQmxCreateTask ("", &taskExhaustDamper));    
    DAQmxErrChk (DAQmxCreateAOVoltageChan (taskExhaustDamper, chanExhaust, "", min, max, DAQmx_Val_Volts, ""));
    DAQmxErrChk (DAQmxStartTask(taskExhaustDamper));
   
    //--- Create and start the digital on/off Damper task ------
    DAQmxErrChk (DAQmxCreateTask ("", &taskDIOHandle));
    DAQmxErrChk (DAQmxCreateDOChan (taskDIOHandle, chanDigital,"",DAQmx_Val_ChanForAllLines));
    DAQmxErrChk (DAQmxStartTask(taskDIOHandle));

 for (i=0; i<2; i++) {
  dioData[i] = 1;
 }

    //--- Enable both damper motors ---------------------------- 
    DAQmxErrChk (DAQmxWriteDigitalLines (taskDIOHandle, 1, 1, 10.0, DAQmx_Val_GroupByChannel, dioData, &iWritten, NULL));
    //----------------------------------------------------------
  Error:
    if (DAQmxFailed(error)) {
        DAQmxGetExtendedErrorInfo(errBuff,2048);
        MessagePopup("DAQmx Error",errBuff);
    }
    if (taskInletDamper!=0 ) {
        DAQmxStopTask(taskInletDamper);
        DAQmxClearTask(taskInletDamper);
    }
    if (taskExhaustDamper!=0 ) {
        DAQmxStopTask(taskExhaustDamper);
        DAQmxClearTask(taskExhaustDamper);
    }
    if (taskDIOHandle!=0 ) {
        DAQmxStopTask(taskDIOHandle);
        DAQmxClearTask(taskDIOHandle);
    }
   
#endif
   
}

 

void pr_cls_dampers(void)       // System activates and closes dampers.
{
 float64 damper_voltage = 10.0;
 
    if(USE_NI_IO == 1) {
  if ( taskInletDamper == 0 ) {
   AddScrollLine("Inlet Damper Task Not Available\n");
  }
  else {
   DAQmxWriteAnalogScalarF64 (taskInletDamper, 1, 10.0, damper_voltage, NULL);
  }
  if (taskExhaustDamper == 0) {
   AddScrollLine("Exhaust Damper Task Not Available\n");
  }
  else {
         DAQmxWriteAnalogScalarF64 (taskExhaustDamper, 1, 10.0, damper_voltage, NULL);
  }
 }

 AddScrollLine (MSG_CLS_DAMPERS);

    testTickCtr = 10;                        // Test rate to 1 sec rate.
    step_iter = 0; teststep = PR_CHK_PS;
}

0 Kudos
Message 1 of 2
(3,290 Views)

Issue 1 : If I read correctly your post the error handlers stopping and clearing your DAQmx tasks are always executed. (They should be included in the block beginning with if( DAQmxFailed(error) )

 

Issue 2 :I'm not sure to understand what files in which order show the problem, but I can imagine that you have perhaps forgotten to 'protect' your definition with :

#ifndef TRUE
   #define TRUE            (1L)
#endif

ifndef FALSE
 #define FALSE           (0L)
#endif...

 

Regards,

Nicolas

0 Kudos
Message 2 of 2
(3,272 Views)