Ejemplo n.º 1
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            short  err;
            ushort i;
            int    nBufSize;

            ushort[] ChanArray = new ushort[wSelectedChans];
            ushort[] GainArray = new ushort[wSelectedChans];

            dwDataNum = Convert.ToUInt32(TXT_DATACOUNT.Text);

            nBufSize       = sizeof(short) * Convert.ToInt32(dwDataNum) * wSelectedChans;
            m_data_buffer  = Marshal.AllocHGlobal(nBufSize);
            m_data_buffer2 = Marshal.AllocHGlobal(nBufSize);


            // Configure AI Channel
            err = USBDASK.UD_AI_Channel_Config((ushort)Module_Num1, USBDASK.UD_AI_Differential, USBDASK.UD_AI_Differential, USBDASK.UD_AI_Differential, USBDASK.UD_AI_Differential);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_Channel_Config error = " + err.ToString());
                Close();
                return;
            }
            err = USBDASK.UD_AI_Channel_Config((ushort)Module_Num2, USBDASK.UD_AI_Differential, USBDASK.UD_AI_Differential, USBDASK.UD_AI_Differential, USBDASK.UD_AI_Differential);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_Channel_Config error = :" + err.ToString());
                Close();
                return;
            }

            err = USBDASK.UD_AI_Trigger_Config((ushort)Module_Num1, USBDASK.UD_AI_CONVSRC_EXT, USBDASK.UD_AI_TRGMOD_POST, USBDASK.UD_AI_TRGSRC_SOFT, 0, 0, 0, 0);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_Trigger_Config error = " + err.ToString());
                Close();
                return;
            }
            err = USBDASK.UD_AI_Trigger_Config((ushort)Module_Num2, USBDASK.UD_AI_CONVSRC_EXT, USBDASK.UD_AI_TRGMOD_POST, USBDASK.UD_AI_TRGSRC_SOFT, 0, 0, 0, 0);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_Trigger_Config error = :" + err.ToString());
                Close();
                return;
            }

            // Disable double-buffer
            err = USBDASK.UD_AI_AsyncDblBufferMode((ushort)Module_Num1, false);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_AsyncDblBufferMode error = " + err.ToString());
                Close();
                return;
            }
            err = USBDASK.UD_AI_AsyncDblBufferMode((ushort)Module_Num2, false);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_AsyncDblBufferMode error = :" + err.ToString());
                Close();
                return;
            }

            err = USBDASK.UD_AI_EventCallBack_x64((ushort)Module_Num1, 1, USBDASK.AIEnd, m_delegate);
            if (err < 0)
            {
                MessageBox.Show("UD_AI_EventCallBack error = " + err.ToString());
                Close();
                return;
            }

            // Prepare the Channel Gain Queue
            for (i = 0; i < wSelectedChans; i++)
            {
                ChanArray[i] = i;
                GainArray[i] = USBDASK.AD_B_10_V;
            }

            dSamplerate = Convert.ToDouble(TXT_SAMPLERATE.Text);

            err = USBDASK.UD_AI_ContReadMultiChannels((ushort)Module_Num1, wSelectedChans, ChanArray, GainArray, m_data_buffer, dwDataNum * wSelectedChans, dSamplerate, USBDASK.ASYNCH_OP);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_ContReadMultiChannels error = " + err.ToString());
                Close();
                return;
            }
            err = USBDASK.UD_AI_ContReadMultiChannels((ushort)Module_Num2, wSelectedChans, ChanArray, GainArray, m_data_buffer2, dwDataNum * wSelectedChans, dSamplerate, USBDASK.ASYNCH_OP);
            if (err != USBDASK.NoError)
            {
                MessageBox.Show("UD_AI_ContReadMultiChannels error = " + err.ToString());
                Close();
                return;
            }

            GPO0Clk();
        }