Esempio n. 1
0
        /// <summary>
        /// Polling a voltage data.
        /// </summary>
        /// <returns>System.Double.</returns>
        /// <exception cref="InvalidOperationException">
        /// AI_ReadChannel32 Fail, error:  " + err
        /// or
        /// AI_VoltScale32 Fail, error:  " + err
        /// </exception>
        public double VoltagePolling()
        {
            double volt;
            uint   value;
            short  err = DASK.AI_ReadChannel32(GetHandle(), config_para.ai_select_channel, config_para.ai_chnl_range, out value);

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

            err = DASK.AI_VoltScale32(GetHandle(), config_para.ai_chnl_range, (int)value, out volt);
            if (err < 0)
            {
                throw new InvalidOperationException("AI_VoltScale32 Fail, error:  " + err);
            }
            return(volt);
        }
Esempio n. 2
0
        /// <summary>
        /// Transfers the buffer.
        /// This function mark the buffer is transfered during double buffer operation.
        /// Check the double buffer overrun to make sure data is not lost.
        /// </summary>
        /// <param name="dataArray">The data array.</param>
        /// <returns>System.Int16.</returns>
        /// <exception cref="InvalidOperationException">Double buffer overrun</exception>
        public short TransferBuffer(Int32[] dataArray)
        {
            short  err         = DASK.NoError;
            ushort overrunFlag = 0;
            IntPtr latestIndex = config_para.ai_raw_data_buf[(config_para.ai_buf_ready_idx + 1) % 2];

            Marshal.Copy(config_para.ai_raw_data_buf[config_para.ai_buf_ready_idx], dataArray, 0, (int)GetSampleCountsPerChannel());
            DASK.AI_VoltScale32(GetHandle(), config_para.ai_chnl_range, dataArray[GetSampleCountsPerChannel() - 2], out latestVoltageValue);
            latestEncoderValue            = Math.Abs((dataArray[GetSampleCountsPerChannel() - 1] * 256) / 256);
            config_para.ai_buf_ready_idx += 1;
            config_para.ai_buf_ready_idx %= 2;

            err = DASK.AI_AsyncDblBufferHandled(GetHandle());
            err = DASK.AI_AsyncDblBufferOverrun(GetHandle(), 0, out overrunFlag);
            if (overrunFlag != 0)
            {
                throw new InvalidOperationException("Double buffer overrun");
            }
            return(err);
        }