예제 #1
0
 private bool PCI9222Close()
 {
     try
     {
         _Flag_start = false;
         listArray[0].Clear();
         listArray[1].Clear();
         listArray[2].Clear();
         listArray[3].Clear();
         listArray[4].Clear();
         err = DASK.AI_AsyncClear(cardRegNumber, out accesscnt);
         if (err < 0)
         {
             Globals.addList("9222卡AI_AsyncClear失败!", Mycolor.ErrorRed);
             return(false);
         }
         err = DASK.Release_Card(cardRegNumber);
         if (err < 0)
         {
             Globals.addList("9222卡Release_Card失败!", Mycolor.ErrorRed);
             return(false);
         }
         return(true);
     }
     catch { return(false); }
 }
예제 #2
0
        /// <summary>
        ///     Dispose
        /// </summary>
        /// <param name="disposing"></param>
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            //if (disposing)
            //{
            //    //清理托管资源
            //    if (managedResource != null)
            //    {
            //        managedResource.Dispose();
            //        managedResource = null;
            //    }
            //}

            // 清理非托管资源
            foreach (var device in _devices.Values)
            {
                var ret = DASK.Release_Card((ushort)device);
                if (ret != DASK.NoError)
                {
                    throw new DaskException("Unknown error.");
                }
            }
            _disposed = true;
        }
예제 #3
0
        public void Release()
        {
            short ret;

            if (m_dev >= 0)
            {
                ret = DASK.Release_Card((ushort)m_dev);
            }
        }
예제 #4
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            short ret;

            if (m_dev >= 0)
            {
                ret = DASK.Release_Card((ushort)m_dev); /* »Ô´Ãкº I/O */
            }
        }
예제 #5
0
        public static void IOCard7432Close()//释放IO卡
        {
            short ret;
            short m_dev = DASK.Register_Card(DASK.PCI_7432, 0);

            if (m_dev >= 0)
            {
                ret = DASK.Release_Card((ushort)m_dev);
            }
        }
예제 #6
0
        public override bool Close()
        {
            bool ret;

            try
            {
                ret = DASK.Release_Card(usCardNo) == 0 ? true : false;
            }
            catch (Exception)
            {
                return(false);
            }
            return(ret);
        }
예제 #7
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (queue.IsAlive)
     {
         if (false == queue.Join(200))
         {
             queue.Abort();
         }
         err = DASK.Release_Card(cardRegNumber);
         if (err < 0)
         {
             MessageBox.Show("Release_Card");
         }
     }
 }
        public int CloseDevice()
        {
            if (!IsDeviceOpen)
            {
                return((int)ErrorDef.Success);
            }
            if (DASK.Release_Card((ushort)_cardIndex) != 0)
            {
                return((int)ErrorDef.InvokeFailed);
            }
            _dioMD.Close();
            _dioMD = null;

            IsDeviceOpen = false;
            return((int)ErrorDef.Success);
        }
예제 #9
0
        /// <summary>
        /// Releases the card.
        /// </summary>
        /// <returns>System.Int16.</returns>
        public short ReleaseCard()
        {
            short err = DASK.NoError;

            if (card_handle >= 0)
            {
                if (config_para.is_ai_set_buf)
                {
                    // Reset buffer
                    Marshal.FreeHGlobal(config_para.ai_raw_data_buf[0]);
                    Marshal.FreeHGlobal(config_para.ai_raw_data_buf[1]);
                    config_para.is_ai_set_buf = false;
                }
                err         = DASK.Release_Card((ushort)card_handle);
                card_handle = -1;
            }
            return(err);
        }
예제 #10
0
 private void PCI9222_FormClosed(object sender, FormClosedEventArgs e)
 {
     err = DASK.AI_AsyncClear(cardRegNumber, out accesscnt);
     if (err < 0)
     {
         MessageBox.Show("AI_AsyncClear");
     }
     err = DASK.Release_Card(cardRegNumber);
     if (err < 0)
     {
         MessageBox.Show("Release_Card");
     }
     this.timer1.Enabled = false;
     listArray[0].Clear();
     listArray[1].Clear();
     listArray[2].Clear();
     listArray[3].Clear();
     listArray[4].Clear();
 }
예제 #11
0
 public static void Close(out short code, out string message)
 {
     if (m_device >= 0)
     {
         code    = DASK.Release_Card((ushort)m_device);
         message = "";
         logText = "Close dio: OK";
         log.AppendText(logText);
         System.Diagnostics.Debug.WriteLine(logText);
     }
     else
     {
         code    = -1;
         message = "Release_Card error!";
         logText = "Close dio: " + message;
         log.AppendText(logText);
         System.Diagnostics.Debug.WriteLine(logText);
     }
 }
예제 #12
0
        static void Main(string[] args)
        {
            short  err;
            ushort card_num = 0;
            short  card;
            uint   ReadCount    = 60;
            ushort Group        = 0; // Load Cell Channel Group
            ushort XMode        = DASK.P9524_AI_XFER_DMA;
            ushort ADC_Range    = 0;
            ushort ADC_SampRate = DASK.P9524_ADC_60_SPS;
            ushort ConfigCtrl   = DASK.P9524_VEX_Range_10V | DASK.P9524_AI_BufAutoReset;
            ushort TrigCtrl     = 0;
            uint   dwTrigValue  = 0;
            ushort GCtr0        = DASK.P9524_CTR_QD0;
            ushort Mode         = DASK.P9524_x4_AB_Phase_Decoder;
            ushort Channel      = DASK.P9524_AI_LC_CH0;
            byte   Stopped      = 0;
            byte   HalfReady    = 0;
            uint   AccessCnt;
            int    viewidx     = 0;
            ushort overrunFlag = 0;
            double ActualRate;
            IntPtr BufPtr1;
            ushort BufID1;
            IntPtr BufPtr2;
            ushort BufID2;

            double[]     voltageArray    = new double[ReadCount];
            ushort       DFStage         = 2;
            uint         SPKRejThreshold = 16;
            StreamWriter sw = new StreamWriter("acq.csv");

            BufPtr1 = Marshal.AllocHGlobal((int)(sizeof(uint) * (ReadCount)));
            BufPtr2 = Marshal.AllocHGlobal((int)(sizeof(uint) * (ReadCount)));

            card = DASK.Register_Card(DASK.PCI_9524, card_num);
            if (card < 0)
            {
                throw new InvalidOperationException("DSA_Register_Card Fail, error:  " + card);
            }

            //Enable Decoder0
            err = DASK.GPTC_Clear((ushort)card, GCtr0);
            if (err < 0)
            {
                throw new InvalidOperationException("GPTC_Clear Fail, error:  " + err);
            }

            err = DASK.GPTC_Setup((ushort)card, GCtr0, Mode, 0, 0, 0, 0);
            if (err < 0)
            {
                throw new InvalidOperationException("GPTC_Setup Fail, error:  " + err);
            }

            //apply parameter 4 to "2" to combine data to AI
            err = DASK.GPTC_Control((ushort)card, GCtr0, DASK.P9524_CTR_Enable, 2);
            if (err < 0)
            {
                throw new InvalidOperationException("GPTC_Control Fail, error:  " + err);
            }

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

            /*In Double Buffer Mode, you should setup two buffers*/
            err = DASK.AI_ContBufferSetup((ushort)card, BufPtr1, ReadCount, out BufID1);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_ContBufferSetup Fail, error:  " + err);
            }

            err = DASK.AI_ContBufferSetup((ushort)card, BufPtr2, ReadCount, out BufID2);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_ContBufferSetup Fail, error:  " + err);
            }

            /*Load Cell Group*/
            /*Set DSP - it is necessary fot Load Cell Group*/
            err = DASK.AI_9524_SetDSP((ushort)card, Channel, DASK.P9524_SPIKE_REJ_ENABLE, DFStage, (ushort)SPKRejThreshold);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_9524_SetDSP Fail, error:  " + err);
            }

            err = DASK.AI_9524_Config((ushort)card, Group, XMode, ConfigCtrl, TrigCtrl, (ushort)dwTrigValue);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_9524_Config Fail, error:  " + err);
            }


            Console.WriteLine("\nPress any key to start AI Infinite Acquisition\n");
            Console.ReadKey(true);
            Console.WriteLine("\nYou can press any key to stop...\n\n");

            err = DASK.AI_ContReadChannel((ushort)card, Channel, ADC_Range, new ushort[] { BufID1 }, ReadCount, ADC_SampRate, DASK.ASYNCH_OP);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_ContReadChannel Fail, error:  " + err);
            }


            do
            {
                err = DASK.AI_AsyncDblBufferHalfReady((ushort)card, out HalfReady, out Stopped);
                if (err < 0)
                {
                    throw new InvalidOperationException("AI_AsyncDblBufferHalfReady Fail, error:  " + err);
                }
                System.Threading.Thread.Sleep(1);
                if (HalfReady == 1)
                {
                    if (viewidx == 0)
                    {
                        Console.WriteLine("Buffer 1 HalfReady, Process the data of Buffer 1\n");
                        /*Process buffer 1 data*/
                        DASK.AI_ContVScale((ushort)card, ADC_Range, BufPtr1, voltageArray, (int)ReadCount);
                        for (int j = 0; j < ReadCount; j = j + 2)
                        {
                            //fprintf(fin, "AI0:,%13.9f,2's Complement Decoder Valuse:, %d\n", voltageArray[i], (int)(Buffer1[i + 1] * 256) / 256);
                            sw.WriteLine(voltageArray[j] + "," + (int)(((uint *)(void *)BufPtr1)[j + 1] * 256) / 256);
                        }

                        viewidx = 1;
                        /*Tell the driver you complete the buffer 1 process*/
                        err = DASK.AI_AsyncDblBufferHandled((ushort)card);
                        if (err < 0)
                        {
                            throw new InvalidOperationException("AI_AsyncDblBufferHandled Fail, error:  " + err);
                        }
                    }

                    else
                    {
                        Console.WriteLine("Buffer 2 HalfReady, Process the data of Buffer 2\n");
                        /*Process buffer 2 data*/
                        DASK.AI_ContVScale((ushort)card, ADC_Range, BufPtr2, voltageArray, (int)ReadCount);
                        for (int j = 0; j < ReadCount; j = j + 2)
                        {
                            //fprintf(fin, "AI0:,%13.9f,2's Complement Decoder Valuse:, %d\n", voltageArray[i], (int)(Buffer1[i + 1] * 256) / 256);
                            sw.WriteLine(voltageArray[j] + "," + (int)(((uint *)(void *)BufPtr2)[j + 1] * 256) / 256);
                        }

                        viewidx = 0;
                        /*Tell the driver you complete the buffer 2 process*/
                        err = DASK.AI_AsyncDblBufferHandled((ushort)card);
                        if (err < 0)
                        {
                            throw new InvalidOperationException("AI_AsyncDblBufferHandled Fail, error:  " + err);
                        }
                    }

                    // This function can check if the overrun occurs. If the
                    // function is called, AI_AsyncDblBufferHandled() should
                    // be called to let driver to know user buffer is processed
                    // completely
                    err = DASK.AI_AsyncDblBufferOverrun((ushort)card, 0, out overrunFlag);
                    if (err < 0)
                    {
                        throw new InvalidOperationException("AI_AsyncDblBufferOverrun Fail, error:  " + err);
                    }
                    if (overrunFlag != 0)
                    {
                        Console.WriteLine("OVERRUN:\n" + overrunFlag);
                        DASK.AI_AsyncDblBufferOverrun((ushort)card, 1, out overrunFlag);
                    }
                }
            } while ((Stopped == 0) && (Console.KeyAvailable == false));

            DASK.GetActualRate_9524((ushort)card, Group, ADC_SampRate, out ActualRate);
            Console.WriteLine("\n\nGeneral Purpose Channel 0 Acquisition Done in " + ActualRate + "Hz");
            Console.WriteLine("The acquired data stored in acq.dat\n");

            /*Clear AI setting while existing*/
            err = DASK.AI_AsyncClear((ushort)card, out AccessCnt);
            if (err < 0)
            {
                Console.WriteLine("AI_AsyncClear Error:" + err + "\n");
                DASK.AI_ContBufferReset((ushort)card);
                DASK.Release_Card((ushort)card);
            }


            if ((ConfigCtrl & DASK.P9524_AI_BufAutoReset) == 0)
            {
                err = DASK.AI_ContBufferReset((ushort)card);
                if (err < 0)
                {
                    throw new InvalidOperationException("AI_ContBufferReset Fail, error:  " + err);
                }
            }

            DASK.GPTC_Clear((ushort)card, GCtr0);

            DASK.Release_Card((ushort)card);

            Console.Write("Press any key to save data . . .");
            sw.Close();
            Console.ReadKey(true);
        }