예제 #1
0
 public void Start(LCard502Pars _pars, L502Ch[] _channels)
 {
     if (IsStarted)
     {
         return;
     }
     LoadSettings(_pars, _channels);
     LFATAL("LCard502::Start: не смогли стартовать: ", hnd.StreamsStart());
     IsStarted = true;
 }
예제 #2
0
파일: MainForm.cs 프로젝트: res2001/x502api
        /* Функция синхронного сбора данных. Выполняется в отдельном потоке */
        private void threadFunc()
        {
            reqStop = false;
            /* запускаем синхронные потоки ввода-вывода*/
            lpcie.Errs err = hnd.StreamsStart();
            if (err == lpcie.Errs.OK)
            {
                /* выполняем прием пока не произойдет ошибка или
                 *  не будет запроса на останов от основного приложения */
                while (!reqStop && (err == lpcie.Errs.OK))
                {
                    /* принимаем данные синхронного ввода */
                    Int32 rcv_size = hnd.Recv(rcv_buf, RECV_BUF_SIZE, RECV_TOUT);
                    /* значение меньше нуля означает ошибку... */
                    if (rcv_size < 0)
                    {
                        err = (lpcie.Errs)rcv_size;
                    }
                    else if (rcv_size > 0)
                    {
                        /* если больше нуля - значит приняли новые данные */
                        dinSize = RECV_BUF_SIZE;
                        adcSize = RECV_BUF_SIZE;

                        /* получаем номер лог. какнала, соответствующий первому
                         *  отсчету АЦП, так как до этого могли обработать
                         *  некратное количество кадров */
                        firstLch = hnd.NextExpectedLchNum;

                        /* разбираем данные на синхронный ввод и отсчеты АЦП и
                         *  переводим АЦП в Вольты */
                        err = hnd.ProcessData(rcv_buf, (uint)rcv_size, X502.ProcFlags.VOLT,
                                              adcData, ref adcSize, dinData, ref dinSize);

                        if (err == lpcie.Errs.OK)
                        {
                            /* обновляем значения элементов управления */
                            UpdateData();
                        }
                    }
                }

                /* по выходу из цикла отсанавливаем поток.
                 * Чтобы не сбросить код ошибки (если вышли по ошибке)
                 * результат останова сохраняем в отдельную переменную */
                lpcie.Errs stop_err = hnd.StreamsStop();
                if (err == lpcie.Errs.OK)
                {
                    err = stop_err;
                }
            }

            /* завершаем поток */
            finishThread(err);
        }
예제 #3
0
        private void button18_Click(object sender, EventArgs e)
        {
            if (imp_mode == false)
            {
                UInt32   imp_length_val = Convert.ToUInt32(imp_length.Text, 10), period, delay;
                UInt32[] imp_array = new UInt32[imp_length_val];
                if (imp_state1.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period1.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay1.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 1;
                    }
                }
                if (imp_state2.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period2.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay2.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 2;
                    }
                }
                if (imp_state3.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period3.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay3.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 4;
                    }
                }
                if (imp_state4.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period4.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay4.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 8;
                    }
                }
                if (imp_state5.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period5.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay5.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 16;
                    }
                }
                if (imp_state6.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period6.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay6.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 32;
                    }
                }
                if (imp_state7.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period7.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay7.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 64;
                    }
                }
                if (imp_state8.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period8.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay8.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 128;
                    }
                }
                if (imp_state9.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period9.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay9.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 256;
                    }
                }
                if (imp_state10.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period10.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay10.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 512;
                    }
                }
                if (imp_state11.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period11.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay11.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 1024;
                    }
                }
                if (imp_state12.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period12.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay12.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 2048;
                    }
                }
                if (imp_state13.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period13.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay13.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 4096;
                    }
                }
                if (imp_state14.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period14.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay14.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 8192;
                    }
                }
                if (imp_state15.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period15.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay15.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 16384;
                    }
                }
                if (imp_state16.CheckState == CheckState.Checked)
                {
                    period = Convert.ToUInt32(imp_period16.Text, 10);
                    delay  = Convert.ToUInt32(imp_delay16.Text, 10);
                    for (UInt32 j = delay; j < period + delay; j++)
                    {
                        imp_array[j] = imp_array[j] + 32768;
                    }
                }

                imp_mode = true;
                //запись в буфер платы (постоянный режим)
                if (imp_single.CheckState == CheckState.Checked)
                {
                    hnd.StreamsEnable(X502.Streams.DOUT);
                    hnd.PreloadStart();
                    hnd.PrepareData(null, null, imp_array, imp_length_val, X502.DacOutFlags.VOLT, null);
                    hnd.Send(imp_array, imp_length_val, 10);
                    hnd.StreamsStart();
                }
                else if (imp_single.CheckState == CheckState.Unchecked)
                {
                    hnd.StreamsEnable(X502.Streams.DOUT);
                    hnd.OutCycleLoadStart(imp_length_val);
                    hnd.Send(imp_array, imp_length_val, 10);
                    hnd.OutCycleSetup(X502.OutCycleFlags.FORCE);
                    hnd.StreamsStart();
                    updateControls();
                }
            }
            else
            {
                hnd.StreamsStop();
                hnd.AsyncOutDig(0, 0);
                imp_mode = false;
                updateControls();


                imp_state1.CheckState  = CheckState.Unchecked;
                imp_state2.CheckState  = CheckState.Unchecked;
                imp_state3.CheckState  = CheckState.Unchecked;
                imp_state4.CheckState  = CheckState.Unchecked;
                imp_state5.CheckState  = CheckState.Unchecked;
                imp_state6.CheckState  = CheckState.Unchecked;
                imp_state7.CheckState  = CheckState.Unchecked;
                imp_state8.CheckState  = CheckState.Unchecked;
                imp_state9.CheckState  = CheckState.Unchecked;
                imp_state10.CheckState = CheckState.Unchecked;
                imp_state11.CheckState = CheckState.Unchecked;
                imp_state12.CheckState = CheckState.Unchecked;
                imp_state13.CheckState = CheckState.Unchecked;
                imp_state14.CheckState = CheckState.Unchecked;
                imp_state15.CheckState = CheckState.Unchecked;
                imp_state16.CheckState = CheckState.Unchecked;
            }
        }