Example #1
0
        public void SetupTimedSample(LoggerState settings)
        {
            /*
             * //resolution (works) (12/16bit)
             * aio.GetAiResolution(id, out AiResolution);
             * maxbytes = Math.Pow(2, AiResolution);
             *
             * //Doesn't work on 1664LAX
             * aio.SetAiRangeAll(1,CaioConst.P025)
             *
             * //Doesn't work (reads 1)
             * short nC1;
             * aio.GetAiChannels(id, out nC1);
             *
             * //is this a mapping?
             * string map = "";
             * AiChannelSeq = new short[nChannel];
             * for (short i = 0; i < nChannel; i++)
             * {
             *  aio.GetAiChannelSequence(id, i, out AiChannelSeq[i]);
             *  map += AiChannelSeq[i].ToString() + ",";
             * }
             */

            //Setting the
            foreach (DEVICEID id in devices)
            {
                HANDLE_RETURN_VALUES = aio.SetAiChannels(id, settings.n_channels);
                HANDLE_RETURN_VALUES = aio.SetAiSamplingClock(id, settings.timer_interval); //default usec (2000 for)
                HANDLE_RETURN_VALUES = aio.SetAiStopTimes(id, settings.n_samples);
                HANDLE_RETURN_VALUES = aio.SetAiEventSamplingTimes(id, DATA_RECEIVE_EVENT); //#samples until data retrieve event

                HANDLE_RETURN_VALUES = aio.SetAiTransferMode(id, 0);                        //Device buffered 1=sent to user memory
                HANDLE_RETURN_VALUES = aio.SetAiMemoryType(id, 0);                          //FIFO 1=Ring

                if (settings.external_control)
                {
                    HANDLE_RETURN_VALUES = aio.SetAiStartTrigger(id, 1);                //1 by External trigger rising edge
                }
                else
                {
                    HANDLE_RETURN_VALUES = aio.SetAiStartTrigger(id, 0);                //0 by Software
                }

                if (settings.external_control)
                {
                    HANDLE_RETURN_VALUES = aio.SetAiClockType(id, 1);                   //external
                }
                else
                {
                    HANDLE_RETURN_VALUES = aio.SetAiClockType(id, 0);                   //internal
                }

                HANDLE_RETURN_VALUES = aio.SetAiStopTrigger(id, 0);                     //0 means by time
            }
        }
Example #2
0
        //ロガーの設定
        private void setLogger()
        {
            //入力方式
            int aioInputMethod = aio.SetAiInputMethod(devId, 0);    //シングルエンド

            if (aioInputMethod != 0)
            {
                statusMsg(aioInputMethod, null);
                return;
            }

            //使用チャネル数
            int aioCh = aio.SetAiChannels(devId, 2);    //2ch

            if (aioCh != 0)
            {
                statusMsg(aioCh, null);
                return;
            }

            //計測レンジ指定
            int aioRange = aio.SetAiRangeAll(devId, (short)CaioConst.PM5); //±5V

            if (aioRange != 0)
            {
                //1664LAXでは±10V固定
                statusMsg(aioRange, null);
                aioRange = aio.SetAiRangeAll(devId, (short)CaioConst.PM10); //±10V
                if (aioRange != 0)
                {
                    statusMsg(aioCh, null);
                    return;
                }
                statusMsg(1, "レンジが変更できないデバイスなので±10V固定で動作します");
            }

            //転送方式
            int aioMemTrans = aio.SetAiTransferMode(devId, 0);  //デバイスバッファ

            if (aioMemTrans != 0)
            {
                statusMsg(aioMemTrans, null);
                return;
            }

            //メモリ格納形式
            int aioMem = aio.SetAiMemoryType(devId, 0); //FIFO

            if (aioMem != 0)
            {
                statusMsg(aioMem, null);
                return;
            }

            //クロック
            int aioClk = aio.SetAiClockType(devId, 0);  //内部クロック

            if (aioClk != 0)
            {
                statusMsg(aioClk, null);
                return;
            }

            //変換速度
            int aioSpd = aio.SetAiSamplingClock(devId, 1000);   //1000us

            if (aioSpd != 0)
            {
                statusMsg(aioSpd, null);
                return;
            }
            float clock = 0;

            aio.GetAiSamplingClock(devId, out clock);
            convSpeed.Text = clock.ToString() + "μs";

            //開始条件
            int aioStartTrg = aio.SetAiStartTrigger(devId, 0);  //ソフトウェア

            if (aioStartTrg != 0)
            {
                statusMsg(aioStartTrg, null);
                return;
            }

            //停止条件
            int aioStopTrg = aio.SetAiStopTrigger(devId, 4);    //コマンド

            if (aioStopTrg != 0)
            {
                statusMsg(aioStopTrg, null);
                return;
            }

            /*
             * 停止条件 = 0とリピート回数 = 0でDEMO DEVICEにて実行するとこのプログラムではBSoDが発生しWindowsが停止する。
             * 恐らく想定外入力によって引き起こされるドライバのバグだと思われる。
             */

            //イベント駆動
            int aioEvent = aio.SetAiEvent(devId, (uint)this.Handle, (int)CaioConst.AIE_DATA_NUM |                          //指定回数格納
                                          (int)CaioConst.AIE_OFERR | (int)CaioConst.AIE_SCERR | (int)CaioConst.AIE_ADERR); //オーバーフロー、クロックエラー、AD変換エラー

            if (aioEvent != 0)
            {
                statusMsg(aioEvent, null);
                return;
            }

            //イベント発生サンプリング回数設定
            int aioSamplingTimes = aio.SetAiEventSamplingTimes(devId, 1000);    //1000回だと画像データ取得時刻にかなりの確率で間に合わない

            if (aioSamplingTimes != 0)
            {
                statusMsg(aioSamplingTimes, null);
                return;
            }
        }