Esempio n. 1
0
        /// <summary>
        /// Gonfigs the GPTC setting.
        /// </summary>
        /// <returns>System.Int16.</returns>
        /// <exception cref="InvalidOperationException">
        /// GPTC_Clear Fail, error:  " + err
        /// or
        /// GPTC_Setup Fail, error:  " + err
        /// or
        /// GPTC_Control Fail, error:  " + err
        /// or
        /// GPTC_9524_SetCombineEcdData Fail, error:  " + err
        /// </exception>
        private short GonfigGPTC()
        {
            short err = DASK.NoError;

            // GPTC Setup
            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.GPTC_Setup(GetHandle(), gptcCtrl.GCtr[i], gptcCtrl.Mode, 0, 0, 0, 0);
                if (err < 0)
                {
                    throw new InvalidOperationException("GPTC_Setup Fail, error:  " + err);
                }


                err = DASK.GPTC_Control(GetHandle(), gptcCtrl.GCtr[i], gptcCtrl.GPTC_Ctrl_ParmeID[i], 1);
                if (err < 0)
                {
                    throw new InvalidOperationException("GPTC_Control Fail, error:  " + err);
                }
            }

            if (gptcCtrl.SetCombined)
            {
                err = DASK.GPTC_9524_SetCombineEcdData(GetHandle(), true);
                if (err < 0)
                {
                    throw new InvalidOperationException("GPTC_9524_SetCombineEcdData Fail, error:  " + err);
                }
            }
            return(err);
        }
Esempio n. 2
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);
        }