Thread: Function Call

  1. #1
    Registered User
    Join Date
    Jun 2017
    Posts
    14

    Function Call

    Hello,

    I am integrating one of the features of a DAQ device into my multi-feature program. For this feature of interest, I am given a sample code. In this sample code, the main function calls two additional functions as shown below.

    However, in my multi-feature code, my main function calls the main function of the sample code which calls its two additional functions.
    The modifications are shown on the code (the ones implemented when I integrated the sample code into my code)

    When I faced the same problem before, I was able to solve it here. In that case, the main function in the sample code did not call any additional functions and it was easily integrated by commenting "return 0" out. This was necessary because the main function in my code calls a bunch of other functions and cannot return 0.

    When I compile my current code on gcc, I get the following error:

    c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot open output file Main2.exe: Permission denied
    collect2.exe: error: ld returned 1 exit status


    My code is below:


    Code:
    #include <stdio.h>
    #include <NIDAQmx.h>
    
    
    #define DAQmxErrChk(functionCall) if( DAQmxFailed(error=(functionCall)) ) goto Error; else
    
    
    int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData);
    int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData);
    
    
    
    //int main(void) ---sample code
    void DAQSetup()  --- my code
    {
        int32       error=0;
        TaskHandle  taskHandle=0;
        char        errBuff[2048]={'\0'};
    
    
        /*********************************************/
         // DAQmx Configure Code
        /*********************************************/
        DAQmxErrChk (DAQmxCreateTask("",&taskHandle)); // creates a task
        
        DAQmxErrChk (DAQmxCreateAIVoltageChan(taskHandle,"Dev1/ai0","",DAQmx_Val_Cfg_Default,-10.0,10.0,DAQmx_Val_Volts,NULL));
            
        DAQmxErrChk (DAQmxCfgSampClkTiming(taskHandle,"",10000.0,DAQmx_Val_Rising,DAQmx_Val_ContSamps,1000));
        
    
    
        DAQmxErrChk (DAQmxRegisterEveryNSamplesEvent(taskHandle,DAQmx_Val_Acquired_Into_Buffer,1000,0,EveryNCallback,NULL));
        
        
        DAQmxErrChk (DAQmxRegisterDoneEvent(taskHandle,0,DoneCallback,NULL));
        
        
        /*********************************************/
        // DAQmx Start Code
        /*********************************************/
        DAQmxErrChk (DAQmxStartTask(taskHandle));
    
    
    
    
        printf("Acquiring samples continuously. Press Enter to interrupt\n");
        getchar();
    
    
    Error:
        if( DAQmxFailed(error) )
            DAQmxGetExtendedErrorInfo(errBuff,2048);
        if( taskHandle!=0 ) {
            /*********************************************/
            // DAQmx Stop Code
            /*********************************************/
            DAQmxStopTask(taskHandle);
            DAQmxClearTask(taskHandle);
        }
        if( DAQmxFailed(error) )
            printf("DAQmx Error: %s\n",errBuff);
        printf("End of program, press Enter key to quit\n");
        getchar();
        //return 0; commented out for my code
    }
    
    
    
    
    int32 CVICALLBACK EveryNCallback(TaskHandle taskHandle, int32 everyNsamplesEventType, uInt32 nSamples, void *callbackData) 
    
    
    {
        int32       error=0;
        char        errBuff[2048]={'\0'};
        static int  totalRead=0;
        int32       read=0;
        float64     data[1000];
    
    
        /*********************************************/
        // DAQmx Read Code
        /*********************************************/
        DAQmxErrChk (DAQmxReadAnalogF64(taskHandle,1000,10.0,DAQmx_Val_GroupByScanNumber,data,1000,&read,NULL));
        
        if( read>0 ) {
            printf("Acquired %d samples. Total %d\r",(int)read,(int)(totalRead+=read));
            fflush(stdout);
        }
    
    
    Error:
        if( DAQmxFailed(error) ) {
            DAQmxGetExtendedErrorInfo(errBuff,2048);
            /*********************************************/
            // DAQmx Stop Code
            /*********************************************/
            DAQmxStopTask(taskHandle);
            DAQmxClearTask(taskHandle);
            printf("DAQmx Error: %s\n",errBuff);
        }
        return 0;
    }
    
    
    int32 CVICALLBACK DoneCallback(TaskHandle taskHandle, int32 status, void *callbackData)
    {
        int32   error=0;
        char    errBuff[2048]={'\0'};
    
    
        DAQmxErrChk (status);
    
    
    Error:
        if( DAQmxFailed(error) ) {
            DAQmxGetExtendedErrorInfo(errBuff,2048);
            DAQmxClearTask(taskHandle);
            printf("DAQmx Error: %s\n",errBuff);
        }
        return 0;
    }
    Last edited by cyln; 08-20-2017 at 11:49 AM.

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,793
    c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot open output file Main2.exe: Permission denied

    Seems to me this error has nothing to do with the code. More likely - your exe is still in the memory (still running or being debugged)
    Try to delete Main2.exe before trying to compile to see if this is the reason.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jun 2017
    Posts
    14
    Thanks vart, yea, that was the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Function call Overhead and Function Call Stack
    By Alam Khan in forum C++ Programming
    Replies: 2
    Last Post: 04-26-2014, 08:28 AM
  2. Function Prototype, Function Call, and Function definition
    By dmcarpenter in forum C Programming
    Replies: 9
    Last Post: 04-09-2013, 03:29 AM
  3. Replies: 3
    Last Post: 09-22-2011, 09:59 PM
  4. Replies: 8
    Last Post: 07-08-2011, 01:16 PM
  5. Replies: 5
    Last Post: 10-17-2006, 08:54 AM

Tags for this Thread