Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for NI-DAQmx #6

Open
neuromusic opened this issue Jun 27, 2013 · 4 comments
Open

add support for NI-DAQmx #6

neuromusic opened this issue Jun 27, 2013 · 4 comments

Comments

@neuromusic
Copy link
Member

via PyDAQmx

@neuromusic
Copy link
Member Author

this should be implemented as an "interface": pyoperant/interfaces/pydaqmx_.py

to start, we should have _boolean_read() & _boolean_write(value=True) methods & use the callback feature to setup _boolean_poll(until_value=True)

@neuromusic
Copy link
Member Author

change detection in nidaqmx: http://www.ni.com/white-paper/4102/en/

@neuromusic
Copy link
Member Author

more references:

on DAQmx events: http://www.ni.com/white-paper/5384/en/

Configure Timing --> Configure Change Detection --> Start Task --> Read --> Clear Task --> Error Check
/via http://forums.ni.com/t5/Digital-I-O/Change-Detection-Interrupts-NI-6509/td-p/190597

example c code:

int CVICALLBACK StartCallback(int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
    int32       error=0;
    TaskHandle  taskHandle=0;
    char        chan[256];
    char        risingEdgeChan[256];
    char        fallingEdgeChan[256];
    int32       samplesPerRead;
    int32       numRead;
    uInt8       *data=NULL;
    char        errBuff[2048]={'\0'};
    int         i,j;
    int         numLines;
    int32       bytesPerSamp;

    if( event==EVENT_COMMIT ) {
        GetCtrlVal(panel,PANEL_CHANNEL,chan);
        GetCtrlVal(panel,PANEL_RISING_EDGE_CHANNEL,risingEdgeChan);
        GetCtrlVal(panel,PANEL_FALLING_EDGE_CHANNEL,fallingEdgeChan);
        GetCtrlVal(panel,PANEL_SAMPLES_PER_READ,&samplesPerRead);

        /*********************************************/
        /*/ DAQmx Configure Code
        /*********************************************/
        DAQmxErrChk (DAQmxCreateTask("",&taskHandle));
        DAQmxErrChk (DAQmxCreateDIChan(taskHandle,chan,"",DAQmx_Val_ChanPerLine));
        DAQmxErrChk (DAQmxCfgChangeDetectionTiming(taskHandle,risingEdgeChan,fallingEdgeChan,DAQmx_Val_ContSamps,samplesPerRead));
        DAQmxErrChk (DAQmxGetTaskAttribute(taskHandle,DAQmx_Task_NumChans,&numLines));

        if( (data=malloc(samplesPerRead*numLines))==NULL ) {
            MessagePopup("Error","Not enough memory");
            goto Error;
        }
        SetCtrlAttribute(panel,PANEL_STRIPCHART,ATTR_NUM_TRACES,numLines);

        /*********************************************/
        /*/ DAQmx Start Code
        /*********************************************/
        DAQmxErrChk (DAQmxStartTask(taskHandle));

        gRunning = 1;
        while( gRunning ) {
            /*********************************************/
            /*/ DAQmx Read Code
            /*********************************************/
            DAQmxReadDigitalLines (taskHandle,samplesPerRead,10.0,DAQmx_Val_GroupByScanNumber,data,samplesPerRead*numLines,&numRead,&bytesPerSamp,NULL);

            /* Separate the traces vertically by adding the line number */
            /* to each individual data point.  In most cases, this is   */
            /* the desired behavior.  To show traces bunched together,  */
            /* remove the for loops below.                              */
            for(i=0;i<numRead;i++)
                for(j=0;j<numLines;j++)
                    data[i*numLines+j] += j * 2;
            if( numRead>0 )
                PlotStripChart(panel,PANEL_STRIPCHART,data,numRead*numLines,0,0,VAL_UNSIGNED_CHAR);
            ProcessSystemEvents();
        }
    }

@neuromusic
Copy link
Member Author

@neuromusic neuromusic changed the title add support for NIDAQmx add support for NI-DAQmx Jul 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant