コード例 #1
0
        /// <summary>
        /// Starts the acquisition.
        /// </summary>
        /// <returns>System.Int16.</returns>
        /// <exception cref="InvalidOperationException">AI_ContScanChannels Fail, error:  " + err</exception>
        public short StartAcq()
        {
            config_para.ai_buf_ready_idx = 0;
            latestEncoderValue           = Double.NaN;
            latestVoltageValue           = Double.NaN;
            short err = DASK.AI_ContScanChannels(GetHandle(), config_para.ai_select_channel, config_para.ai_chnl_range, new ushort[] { config_para.ai_buffer_id[0] }, config_para.ai_all_data_count, config_para.ai_sample_rate, DASK.ASYNCH_OP);

            if (err < 0)
            {
                throw new InvalidOperationException("AI_ContScanChannels Fail, error:  " + err);
            }
            return(err);
        }
コード例 #2
0
        private void DAQConfig()
        {
            err = DASK.AI_9221_Config(cardRegNumber, ConfigCtrl, TrigCtrl, true);
            if (err < 0)
            {
                MessageBox.Show("config");
            }

            /*Set Scan and Sampling Rate*/
            ; err = DASK.AI_9221_CounterInterval(cardRegNumber, ScanIntrv, SampIntrv);
            if (err < 0)
            {
                MessageBox.Show("AI_9222_CounterInterval");
            }

            /*Enable Double Buffer Mode*/
            err = DASK.AI_AsyncDblBufferMode(cardRegNumber, true);
            if (err < 0)
            {
                MessageBox.Show("AI_AsyncDblBufferMode");
            }

            /*Setup Buffer for AI DMA Transfer*/
            err = DASK.AI_ContBufferSetup(cardRegNumber, _ptr[0], AI_TotalReadCount, out _bufferId[0]);
            if (err < 0)
            {
                MessageBox.Show("AI_ContBufferSetup");
            }
            err = DASK.AI_ContBufferSetup(cardRegNumber, _ptr[1], AI_TotalReadCount, out _bufferId[1]);
            if (err < 0)
            {
                MessageBox.Show("AI_ContBufferSetup");
            }

            err = DASK.AI_EventCallBack(cardRegNumber, 1 /*add*/, DASK.DBEvent /*EventType*/, ai_buf_ready_cbdel);
            if (err < 0)
            {
                MessageBox.Show("AI_EventCallBack");
            }

            err = DASK.AI_ContScanChannels(cardRegNumber, (ushort)(Channel - 1), AdRange, _bufferId, AI_TotalReadCount, 0 /*Ignore*/, DASK.ASYNCH_OP);
            if (err < 0)
            {
                MessageBox.Show("AI_ContScanChannels");
            }
        }
コード例 #3
0
ファイル: PCI9222.cs プロジェクト: xhyangxianjun/wangliang
        private void PCI9222_Load(object sender, EventArgs e)
        {
            short ret = DASK.Register_Card(DASK.PCI_9222, 0);

            if (ret >= 0)
            {
                cardRegNumber = (ushort)ret;//Register_Card的时候,把卡号给cardRegNumber
            }
            else
            {
                MessageBox.Show("9222卡初始化失败!");
            }


            //ushort ConfigCtrl = DASK.P922x_AI_SingEnded | DASK.P922x_AI_CONVSRC_INT;//?差分在哪区分
            //ushort TrigCtrl = DASK.P922x_AI_TRGMOD_POST | DASK.P922x_AI_TRGSRC_SOFT;//?
            ushort ConfigCtrl     = DASK.P922x_AI_Differential | DASK.P922x_AI_CONVSRC_INT;; //?差分在哪区分
            ushort TrigCtrl       = DASK.P922x_AI_TRGMOD_POST | DASK.P922x_AI_TRGSRC_SOFT;;  //?
            uint   ReTriggerCount = 0;                                                       /*Ignore in Non-Retrigger*/


            bufindex = 0;//是用来两个交替读吗?
            //Channel = 4; /*AI Channel Number to be read*/
            //uint SampIntrv = 8000; /*Sampling Rate: P922X_TIMEBASE/320 = 250K Hz*/  //这个设置,如果要快一点,怎么设置,变小?
            //P922X_TIMEBASE  时钟,80000000,  intrv=80000000/5000=16000;5000为每秒5000个数据,每个通道1000个数据/s
            uint SampIntrv = 16000; /*Sampling Rate: P922X_TIMEBASE/320 = 250K Hz*/   //采样率=80 000000/500=160000,每个通道100个数据,有5个通道
            //AI_ReadCount设置为500,
            //建议每秒钟采集10次-50次,这样不会丢数据。如果采集20次,怎么设置了?
            //目标:1S1000个数据,1ms一个  intrv=80000000/5000=16000;5000为每秒5000个数据,每个通道1000个数据/s  SampIntrv = 16000,
            //AI_ReadCount=5000,则1S采集一次,如果设置成500,则0.1S采集一次,一次100个数据每通道、如果设置成250,则0.05采集一次,1次50个数据
            uint ScanIntrv = (uint)(SampIntrv * (Channel + 1)); /*Scan Rate: P922X_TIMEBASE/320 = 250K Hz*/

            ushort AdRange = DASK.AD_B_10_V;                    /*AI range*/

            ai_buf_ready_cbdel = new CallbackDelegate(ai_buf_ready_cbfunc);
            _ptr[0]            = Marshal.AllocHGlobal((sizeof(ushort) * ((Int32)AI_ReadCount)));//5000
            _ptr[1]            = Marshal.AllocHGlobal((sizeof(ushort) * ((Int32)AI_ReadCount)));
            VBuffer[0]         = Marshal.AllocHGlobal((sizeof(double) * ((Int32)AI_ReadCount)));
            /*Configure AI*/


            err = DASK.AI_9222_Config(cardRegNumber, ConfigCtrl, TrigCtrl, ReTriggerCount, true);
            if (err < 0)
            {
                MessageBox.Show("config");
            }

            /*Set Scan and Sampling Rate*/
            err = DASK.AI_9222_CounterInterval(cardRegNumber, ScanIntrv, SampIntrv);
            if (err < 0)
            {
                MessageBox.Show("AI_9222_CounterInterval");
            }

            /*Enable Double Buffer Mode*/
            err = DASK.AI_AsyncDblBufferMode(cardRegNumber, true);
            if (err < 0)
            {
                MessageBox.Show("AI_AsyncDblBufferMode");
            }

            /*Setup Buffer for AI DMA Transfer*/
            err = DASK.AI_ContBufferSetup(cardRegNumber, _ptr[0], AI_ReadCount, out _bufferId[0]);
            if (err < 0)
            {
                MessageBox.Show("AI_ContBufferSetup");
            }
            err = DASK.AI_ContBufferSetup(cardRegNumber, _ptr[1], AI_ReadCount, out _bufferId[1]);
            if (err < 0)
            {
                MessageBox.Show("AI_ContBufferSetup");
            }

            err = DASK.AI_EventCallBack(cardRegNumber, 1 /*add*/, DASK.DBEvent /*EventType*/, ai_buf_ready_cbdel);//????????????????????
            if (err < 0)
            {
                MessageBox.Show("AI_EventCallBack");
            }

            err = DASK.AI_ContScanChannels(cardRegNumber, Channel, AdRange, _bufferId, AI_ReadCount, 0 /*Ignore*/, DASK.ASYNCH_OP);////??????????
            if (err < 0)
            {
                MessageBox.Show("AI_ContScanChannels");
            }
            this.timer1.Enabled = true;
        }
コード例 #4
0
ファイル: DAQ.cs プロジェクト: xhyangxianjun/wangliang
        public void PCI922Init()
        {
            short ret = DASK.Register_Card(DASK.PCI_9222, 0);

            if (ret >= 0)
            {
                cardRegNumber = (ushort)ret;//Register_Card的时候,把卡号给cardRegNumber
                Globals.addList("9222卡初始化成功!", Mycolor.None);
                #region PCI9222设置
                //ushort ConfigCtrl = DASK.P922x_AI_SingEnded | DASK.P922x_AI_CONVSRC_INT;//?差分在哪区分
                //ushort TrigCtrl = DASK.P922x_AI_TRGMOD_POST | DASK.P922x_AI_TRGSRC_SOFT;//?
                ushort ConfigCtrl     = DASK.P922x_AI_Differential; //?差分在哪区分
                ushort TrigCtrl       = DASK.P922x_AI_TRGMOD_POST;  //?
                uint   ReTriggerCount = 0;                          /*Ignore in Non-Retrigger*/


                bufindex = 0;//是用来两个交替读吗?
                //Channel = 4; /*AI Channel Number to be read*/
                //uint SampIntrv = 8000; /*Sampling Rate: P922X_TIMEBASE/320 = 250K Hz*/  //这个设置,如果要快一点,怎么设置,变小?
                //AI_ReadCount设置为500,
                //建议每秒钟采集10次-50次,这样不会丢数据。如果采集20次,怎么设置了?
                //目标:1S1000个数据,1ms一个  intrv=80000000/5000=16000;5000为每秒5000个数据,每个通道1000个数据/s  SampIntrv = 16000,
                //AI_ReadCount=5000,则1S采集一次,如果设置成500,则0.1S采集一次,一次100个数据每通道、如果设置成250,则0.05采集一次,1次50个数据
                uint SampIntrv = 16000;                             /*Sampling Rate: P922X_TIMEBASE/320 = 250K Hz*/
                uint ScanIntrv = (uint)(SampIntrv * (Channel + 1)); /*Scan Rate: P922X_TIMEBASE/320 = 250K Hz*/

                ushort AdRange = DASK.AD_B_10_V;                    /*AI range*/

                ai_buf_ready_cbdel = new CallbackDelegate(ai_buf_ready_cbfunc);
                _ptr[0]            = Marshal.AllocHGlobal((sizeof(ushort) * ((Int32)AI_ReadCount)));//5000
                _ptr[1]            = Marshal.AllocHGlobal((sizeof(ushort) * ((Int32)AI_ReadCount)));
                VBuffer[0]         = Marshal.AllocHGlobal((sizeof(double) * ((Int32)AI_ReadCount)));
                /*Configure AI*/


                err = DASK.AI_9222_Config(cardRegNumber, ConfigCtrl, TrigCtrl, ReTriggerCount, true);
                if (err < 0)
                {
                    Globals.addList("9222卡config失败!", Mycolor.ErrorRed);
                }

                /*Set Scan and Sampling Rate*/
                err = DASK.AI_9222_CounterInterval(cardRegNumber, ScanIntrv, SampIntrv);
                if (err < 0)
                {
                    Globals.addList("9222卡AI_9222_CounterInterval设置失败!", Mycolor.ErrorRed);
                }

                /*Enable Double Buffer Mode*/
                err = DASK.AI_AsyncDblBufferMode(cardRegNumber, true);
                if (err < 0)
                {
                    Globals.addList("9222卡AI_AsyncDblBufferMode设置失败!", Mycolor.ErrorRed);
                }

                /*Setup Buffer for AI DMA Transfer*/
                err = DASK.AI_ContBufferSetup(cardRegNumber, _ptr[0], AI_ReadCount, out _bufferId[0]);
                if (err < 0)
                {
                    Globals.addList("9222卡AI_ContBufferSetup设置失败!", Mycolor.ErrorRed);
                }
                err = DASK.AI_ContBufferSetup(cardRegNumber, _ptr[1], AI_ReadCount, out _bufferId[1]);
                if (err < 0)
                {
                    Globals.addList("9222卡AI_ContBufferSetup设置失败!", Mycolor.ErrorRed);
                }

                err = DASK.AI_EventCallBack(cardRegNumber, 1 /*add*/, DASK.DBEvent /*EventType*/, ai_buf_ready_cbdel);//????????????????????
                if (err < 0)
                {
                    Globals.addList("9222卡AI_EventCallBack设置失败!", Mycolor.ErrorRed);
                }

                err = DASK.AI_ContScanChannels(cardRegNumber, Channel, AdRange, _bufferId, AI_ReadCount, 0 /*Ignore*/, DASK.ASYNCH_OP);////??????????
                if (err < 0)
                {
                    Globals.addList("9222卡AI_ContScanChannels设置失败!", Mycolor.ErrorRed);
                }
                #endregion
            }
            else
            {
                Globals.PostAlarmMachine(XAlarmLevel.STOP, (int)AlarmCode.凌华PCI9222板卡异常, AlarmCategory.SYSTEM.ToString(), "凌华PCI9222板卡异常");
                if (ShowList != null)
                {
                    ShowList("9222卡初始化失败!");
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Gets the load cell offset.
        /// Use this function to get an average of offset when load cell is in steady status
        /// </summary>
        /// <returns>System.Double.</returns>
        /// <exception cref="InvalidOperationException">
        /// AI_AsyncDblBufferMode Fail, error:  " + err
        /// or
        /// AI_ContBufferSetup Fail, error:  " + err
        /// or
        /// GetLoadCellOffset SetDSP Fail, error:  " + err
        /// or
        /// AI_ContScanChannels Fail, error:  " + err
        /// </exception>
        public double GetLoadCellOffset()
        {
            double offset = 0.0;
            short  err    = -1;
            IntPtr OffsetCalBf;

            double[] OffsetVolbuf;
            uint     calSampleNum = 512;
            ushort   BufID;

            OffsetCalBf  = Marshal.AllocHGlobal((int)(sizeof(uint) * calSampleNum));
            OffsetVolbuf = new double[((int)calSampleNum)];

            ///////Disable fun of AI data combined with enconder, otherwise the caculated offset is going to BOOM

            err = DASK.GPTC_9524_SetCombineEcdData(GetHandle(), false);
            if (err < 0)
            {
                throw new InvalidOperationException("GPTC_9524_SetCombineEcdData Fail, error:  " + err);
            }


            for (int i = 0; i < gptcCtrl.GPTCNum; i++)
            {
                err = DASK.GPTC_Clear(GetHandle(), gptcCtrl.GCtr[i]);
                if (err < 0)
                {
                    throw new InvalidOperationException("GPTC_Clear Fail, error:  " + err);
                }
            }
            ///////

            err = DASK.AI_AsyncDblBufferMode((ushort)GetHandle(), false);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_AsyncDblBufferMode Fail, error:  " + err);
            }

            err = DASK.AI_ContBufferSetup((ushort)GetHandle(), OffsetCalBf, calSampleNum, out BufID);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_ContBufferSetup Fail, error:  " + err);
            }

            err = SetDSP();
            if (err < 0)
            {
                throw new InvalidOperationException("GetLoadCellOffset SetDSP Fail, error:  " + err);
            }


            // Start Acquisition. The acquired raw data will be stored in the set buffer.
            //ushort ADC_SampRate = DASK.P9524_ADC_2K_SPS;
            err = DASK.AI_ContScanChannels((ushort)GetHandle(), config_para.ai_select_channel, config_para.ai_chnl_range, new ushort[] { BufID }, calSampleNum, config_para.ai_sample_rate, DASK.SYNCH_OP);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_ContScanChannels Fail, error:  " + err);
            }

            DASK.AI_ContVScale(GetHandle(), config_para.ai_chnl_range, OffsetCalBf, OffsetVolbuf, (int)calSampleNum);

            for (int i = 0; i < calSampleNum; i++)
            {
                offset = offset + OffsetVolbuf[i];
            }
            offset = offset / calSampleNum;
            DASK.AI_ContBufferReset(GetHandle());

            uint ai_access_cnt;

            DASK.AI_AsyncClear(GetHandle(), out ai_access_cnt);
            return(offset);
        }