Ejemplo n.º 1
0
        private void DAQConfig()
        {
            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_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");
            }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        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卡初始化失败!");
                }
            }
        }