Exemplo n.º 1
0
        //1.读取参数 -- 根据程序号读取模式
        //2.根据模式。选择对应的枚举。将枚举中所有的字段值去匹配List中功能号。。。
        //串口发送modbus

        /// <summary>
        ///
        /// </summary>
        /// <param name="port">串口对象</param>
        /// <param name="list">功能集合</param>
        /// <param name="node">程序号(不用减一)</param>
        internal void ReadATQToINI(SerialPort port, string node)
        {
            pps = PortServcie.Install();
            // 第一步 选择程序号
            ModBusTools modbustool = new ModBusTools();

            CodeIndex = node;
            pps.WriteByte(port, modbustool.GetSoftwareID(node));
            string ReadmodeCode = "FF0320150001";

            ReadmodeCode           = ReadmodeCode + modbustool.CRC(ReadmodeCode);
            PortServcie.IsReadMode = true;
            pps.WriteByte(port, ReadmodeCode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 实时状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Real_Tick(object sender, EventArgs e)
        {
            //启动
            mx.GetDevice("M385", out data);
            if (data == 1)
            {
                AddInformation("爆破机台启动");
                mx.SetDevice("M385", 0);
                StartTest();
            }



            if (queueReal.Count > 0) //实时结果
            {
                RealTimeData rData   = queueReal.Dequeue();
                double       Nowtime = m_StopWatch.ElapsedMilliseconds / 1000.0;
                cshow.AddData(queueData, Nowtime, Convert.ToDouble(rData.PressureValue));
                cshow.ShowChart(View_Burst, queueData);
                for (int i = 0; i < listConReal.Count; i++)
                {
                    string[]     realString = listConReal[i].Name.Split('_');
                    Type         tp         = rData.GetType();
                    PropertyInfo p          = tp.GetProperty(realString[1]);
                    string       value      = p.GetValue(rData, null).ToString();

                    listConReal[i].Text = value;
                }
            }

            if (queueLast.Count > 0) //最终结果
            {
                FinalResult finalResult = queueLast.Dequeue();


                for (int i = 0; i < listConLast.Count; i++)
                {
                    string[]     lastString = listConLast[i].Name.Split('_');
                    Type         tp         = finalResult.GetType();
                    PropertyInfo p          = tp.GetProperty(lastString[1]);
                    string       value      = p.GetValue(finalResult, null).ToString();
                    listConLast[i].Text = value;
                }
                Last_LValueAndUnit.Text = finalResult.LeakValue + finalResult.LeakUnit;
                Last_PValueAndUnit.Text = finalResult.PressureValue + finalResult.PressureUnit;
                ExcelUtil excelUtil = ExcelUtil.Instance();
                finalResult.Product = tb_product.Text;
                excelUtil.SaveData(finalResult);

                switch (finalResult.Result)
                {
                case "OK":
                    mx.SetDevice("M386", 1);
                    in_OK++;
                    break;

                case "NG":
                    mx.SetDevice("M387", 1);
                    in_NG++;
                    break;
                }
                ShowToDayYield();
            }

            if (isClear) //清空
            {
                isClear = false;
                ClearGBReal();
            }

            if (PortServcie.queueParaBuff.Count > 0) //暂存区有数据 =》 发送 =》 解析数据设置到INI文件
            {
                PortServcie.paraBuff = PortServcie.queueParaBuff.Dequeue();
                SetIndex++;
                ProcessBarDisplay(SetIndex);
                string address  = PortServcie.paraBuff.Read;
                string readword = PortServcie.paraBuff.ReadWord;
                string temp1    = "FF03" + address + readword;
                PortServcie.IsReadMode = false;
                m_PortParaServcie.WriteByte(port, temp1 + mbtool.CRC(temp1));

                if (PortServcie.queueParaBuff.Count == 0)
                {
                    SetIndex = 0;
                    ProcessBarDisplay(progressBar_Setting.Maximum + 1);
                }
            }

            if (isRefresh) //刷新仪器参数
            {
                isRefresh = false;
                ParaService.Install().LoadParaToGroupBox(gb_Software, Pattern, cb_Software.Text.Trim(), true);
            }
        }