Example #1
0
        public void waveformAiCtrl1_DataReady(object sender, BfdAiEventArgs args)
        {
            try
            {
                //The WaveformAiCtrl has been disposed.
                if (waveformAiCtrl1.State == ControlState.Idle)
                {
                    return;
                }
                if (m_dataScaled.Length < args.Count)
                {
                    m_dataScaled = new double[args.Count];
                }

                ErrorCode err           = ErrorCode.Success;
                int       chanCount     = waveformAiCtrl1.Conversion.ChannelCount;
                int       sectionLength = waveformAiCtrl1.Record.SectionLength;
                err = waveformAiCtrl1.GetData(args.Count, m_dataScaled); //读取数据
                                                                         // Test.emmmm();//在此处调用一个其他类的静态函数来对数据进行处理。
                if (err != ErrorCode.Success && err != ErrorCode.WarningRecordEnd)
                {
                    HandleError(err);
                    return;
                }
                System.Diagnostics.Debug.WriteLine(args.Count.ToString());
            }
            catch (System.Exception) { }
        }
        private void waveformAiCtrl1_DataReady(object sender, BfdAiEventArgs args)
        {
            ErrorCode err = ErrorCode.Success;

            try
            {
                //The WaveformAiCtrl has been disposed.
                if (waveformAiCtrl1.State == ControlState.Idle)
                {
                    return;
                }
                if (m_dataScaled.Length < args.Count)
                {
                    m_dataScaled = new double[args.Count];
                }

                int chanCount     = waveformAiCtrl1.Conversion.ChannelCount;
                int sectionLength = waveformAiCtrl1.Record.SectionLength;
                err = waveformAiCtrl1.GetData(args.Count, m_dataScaled);//读取数据
                //Console.WriteLine("length:" + m_dataScaled.Length);

                DateTime t = DateTime.Now;
                //
                t = t.AddSeconds(-1.0);//采集到的是一秒钟之前的数据,因此需要对当前的时间减去1s
                t.ToString("yyyy-MM-dd hh:mm:ss:fff");
                safetyDelegate mes = new safetyDelegate(systemInfoactive);
                try { Invoke(mes, t.ToString("yyyy-MM-dd hh:mm:ss:fff")); }
                catch { }
                //Console.WriteLine("time:" + t.ToString("yyyy-MM-dd hh:mm:ss:fff"));
                for (int i = 0; i < m_dataScaled.Length; i += 15)
                {
                    Qc    = Math.Round(m_dataScaled[i + 0], 2);
                    Qh    = Math.Round(m_dataScaled[i + 1], 2);
                    Qm    = Math.Round(m_dataScaled[i + 2], 2);
                    Tc    = Math.Round(m_dataScaled[i + 3], 2);
                    Th    = Math.Round(m_dataScaled[i + 4], 2);
                    Tm    = Math.Round(m_dataScaled[i + 5], 2);
                    Pc    = Math.Round(m_dataScaled[i + 6], 2);
                    Ph    = Math.Round(m_dataScaled[i + 7], 2);
                    Pm    = Math.Round(m_dataScaled[i + 8], 2);
                    Qm5   = Math.Round(m_dataScaled[i + 9], 2);
                    Temp1 = Math.Round(m_dataScaled[i + 10], 2);
                    Temp2 = Math.Round(m_dataScaled[i + 11], 2);
                    Temp3 = Math.Round(m_dataScaled[i + 12], 2);
                    Temp4 = Math.Round(m_dataScaled[i + 13], 2);
                    Temp5 = Math.Round(m_dataScaled[i + 14], 2);
                    if (startFlag)
                    {
                        dt.Rows.Add(t.ToString("yyyy-MM-dd hh:mm:ss:fff"),
                                    Qc,
                                    Qh,
                                    Qm,
                                    Tc,
                                    Th,
                                    Tm,
                                    Pc,
                                    Ph,
                                    Pm,
                                    Qm5);
                    }

                    t = t.AddMilliseconds(10.0);
                }

                myDelegate md = new myDelegate(dataReadyUpdateForm);
                this.Invoke(md);

                if (err != ErrorCode.Success && err != ErrorCode.WarningRecordEnd)
                {
                    HandleError(err);
                    return;
                }
                System.Diagnostics.Debug.WriteLine("读取数据长度" + args.Count.ToString());
            }
            catch (System.Exception) { HandleError(err); }
        }
Example #3
0
        private void waveformAiCtrl1_DataReady(object sender, BfdAiEventArgs args)
        {
            ErrorCode err = ErrorCode.Success;

            bpqreturn_value = Math.Round(bpqMR.read_short("8451", 2) / 100.0, 2);
            try
            {
                //The WaveformAiCtrl has been disposed.
                if (waveformAiCtrl1.State == ControlState.Idle)
                {
                    return;
                }
                if (m_dataScaled.Length < args.Count)
                {
                    m_dataScaled = new double[args.Count];
                }

                int chanCount     = waveformAiCtrl1.Conversion.ChannelCount;
                int sectionLength = waveformAiCtrl1.Record.SectionLength;
                err = waveformAiCtrl1.GetData(args.Count, m_dataScaled);//读取数据
                DateTime t = DateTime.Now;
                //
                t = t.AddSeconds(-1);
                t.ToString("yyyy-MM-dd hh:mm:ss:fff");
                for (int i = 0; i < m_dataScaled.Length; i += 4)
                {
                    if (startFlag)
                    {
                        PRESURE = Math.Round(m_dataScaled[i] + (double)Properties.Settings.Default.m压力, 2);
                        dt.Rows.Add(t.ToString("yyyy-MM-dd hh:mm:ss:fff"),
                                    Math.Round(m_dataScaled[i] + (double)Properties.Settings.Default.m压力, 2),
                                    Math.Round(m_dataScaled[i + 1] + (double)Properties.Settings.Default.m冲击力, 2),
                                    Math.Round(m_dataScaled[i + 2] + (double)Properties.Settings.Default.m温度, 2));
                        m_dataScaled[i]     += (double)Properties.Settings.Default.m压力;
                        m_dataScaled[i + 1] += (double)Properties.Settings.Default.m冲击力;
                        m_dataScaled[i + 2] += (double)Properties.Settings.Default.m温度;
                        if (Math.Round(m_dataScaled[i], 2) >= (double)startThreshold.Value)//当压力大于某个数值开始 计按下工件的延时
                        {
                            pushFlag = true;
                        }
                        if (maxPressure < Math.Round(m_dataScaled[i], 2))
                        {
                            maxPressure = Math.Round(m_dataScaled[i], 2);
                        }
                        if (maxHammer < Math.Round(m_dataScaled[i + 1], 2))
                        {
                            maxHammer = Math.Round(m_dataScaled[i + 1], 2);
                        }
                        if (pushedFlag && Math.Round(m_dataScaled[i], 2) <= (double)stopThreshold.Value)//当压力小于等于某个数值,停止向缓冲区写数据
                        {
                            startFlag  = false;
                            pushFlag   = false;
                            pushedFlag = false;
                            exit       = true;
                        }
                    }
                    t = t.AddMilliseconds(1.0);
                }

                myDelegate md = new myDelegate(setText);
                try
                {
                    if (this.IsHandleCreated)
                    {
                        this.Invoke(md, new object[] { m_dataScaled });
                    }
                }
                catch { }
                if (err != ErrorCode.Success && err != ErrorCode.WarningRecordEnd)
                {
                    HandleError(err);
                    return;
                }
                System.Diagnostics.Debug.WriteLine(args.Count.ToString());
            }
            catch (System.Exception) { HandleError(err); }
        }