Example #1
0
        /// <summary>
        /// 清空控制字
        /// </summary>
        /// <param name="lineName"></param>
        /// <param name="station"></param>
        /// <param name="step"></param>
        public static void ClearControl(string lineName, string station, int step)
        {
            #region 变量
            Recipe_Bll.WriteCacheStationInfo(station, "Step", step.ToString());
            var lineObj    = XML_Tool.xml.LINE.Single(n => n.Name == lineName);
            var stationObj = lineObj.STATION.Single(n => n.Name == station);
            Crafts_Recipe_Modle crafts_Recipe_Modle = GetSingleRecipe(station, step);
            #endregion

            #region 配方为空
            if (crafts_Recipe_Modle == null)
            {
                recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:" + step + " ,Formula not found!", 1, true);
                return;
            }
            #endregion

            #region 拧紧
            if (crafts_Recipe_Modle.OperationType == "拧紧" || crafts_Recipe_Modle.OperationType == "Tighten")
            {
                var    opcObj      = stationObj.Opcitem.Single(n => n.Name == "拧紧记录");
                string backAddr    = opcObj.BackAddr;
                var    dataitemObj = opcObj.Tag.Single(n => n.Name == "拧紧下发").Dataitem;
                foreach (var data in dataitemObj)
                {
                    string sn = Recipe_Bll.GetCacheStationInfo(station, "SN");
                    if (data.ColmnName == "SN")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, "", data.AddrType, int.Parse(data.AddrLength)))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,SN:" + data.Addr + " , Write value :null"
                                                + " ,Successfully written!", 0, false);
                        }
                    }
                    if (data.ColmnName == "BlotNumber")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, "0", data.AddrType, 0))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,BlotNumber:" + data.Addr + " , Write value :0"
                                                + " ,Successfully written!", 0, false);
                        }
                    }
                    if (data.ColmnName == "SleeveNo")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, "0", data.AddrType, 0))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,SleeveNo:" + data.Addr + " , Write value :0"
                                                + " ,Successfully written!", 0, false);
                        }
                    }
                    if (data.ColmnName == "ProgramNo")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, "0", data.AddrType, 0))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,ProgramNo:" + data.Addr + " , Write value :0"
                                                + " ,Successfully written!", 0, false);
                        }
                    }
                }
                if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], backAddr, "0", opcObj.AddrType, 0))
                {
                    recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                        + step + " ,Send tightening address:" + backAddr + " , Write value :"
                                        + " 0,Successfully written!", 0, false);
                }
                else
                {
                    recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                        + step + " ,Send tightening address:" + backAddr + " , Write value :"
                                        + " 0,Write failure!", 0, false);
                }
            }
            #endregion

            #region 测量
            if (crafts_Recipe_Modle.OperationType == "测量" || crafts_Recipe_Modle.OperationType == "Measuring")
            {
                var    opcObj      = stationObj.Opcitem.Single(n => n.Name.Contains("测量记录") && GetTestType(crafts_Recipe_Modle.ComponentName).Contains(n.OperationDesc));
                string backAddr    = opcObj.BackAddr;
                var    dataitemObj = opcObj.Tag.Single(n => n.Name == "测量下发").Dataitem;
                if (dataitemObj.Count == 0)//无需下发程序号
                {
                    if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], backAddr, "0", opcObj.AddrType, 0))
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 0,Successfully written!", 0, true);
                    }
                    else
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 0,Write failure!", 0, true);
                    }
                }
                else
                {
                    foreach (var data in dataitemObj)
                    {
                        if (data.Name == "ProgramNo")
                        {
                            if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, crafts_Recipe_Modle.ProgramNo.ToString(), data.AddrType, 0))
                            {
                                recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                    + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                                    + crafts_Recipe_Modle.ProgramNo.ToString() + " ,Successfully written!", 0, true);
                            }
                        }
                    }
                    if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], backAddr, "0", opcObj.AddrType, 0))
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 0,Successfully written!", 0, true);
                    }
                    else
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 0,Write failure!", 0, true);
                    }
                }
            }
            #endregion
        }
Example #2
0
        /// <summary>
        /// deal with siemens plc event
        /// </summary>
        /// <param name="state"></param>
        public void DealABPLCEvent(object state)
        {
            try
            {
                var para       = (ABPLCParameter)state;
                var MA         = para.ma;
                var itemValue  = para.itemValue;
                var type       = MA.Parameter["type"];
                var LineName   = MA.Parameter["line"];
                var STName     = MA.Parameter["station"];
                var OPCName    = MA.Parameter["name"];
                var BackAddr   = MA.Parameter["backaddr"];
                var lineObj    = XML_Tool.xml.LINE.Single(n => n.Name == LineName);
                var stationObj = XML_Tool.xml.StationConfig.Single(n => n.Name == STName);

                #region 总成绑定
                if (type == "DataRecord" && OPCName == "总成绑定" && itemValue == "1")
                {
                    try
                    {
                        #region 读取plc地址里的值
                        timeAddFlag = true;
                        int       stepNo  = 1;
                        string    sn      = string.Empty;
                        Stopwatch sw      = new Stopwatch();
                        var       stObj   = lineObj.STATION.Single(n => n.Name == STName);
                        var       opcitem = stObj.Opcitem.SingleOrDefault(n => n.Name == OPCName);
                        var       tag     = opcitem.Tag.SingleOrDefault(n => n.Tag == int.Parse(itemValue));
                        if (tag == null)
                        {
                            return;
                        }
                        recodePLCStationMessage(LineName + STName, " Start assembly binding", 0, true);
                        var dataList = tag.Dataitem;
                        sw.Start();
                        string dbColumnStr = string.Empty, dbValueStr = string.Empty, logInfo = string.Empty;
                        foreach (var item in dataList)
                        {
                            dbColumnStr += "[" + item.ColmnName + "]" + ",";
                            dbValueStr  += ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + "','";
                            logInfo     += item.ColmnName + " : " + ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + " , ";
                            if (item.ColmnName == "SN")
                            {
                                sn = ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)).ToString();
                            }
                        }
                        sw.Stop();
                        sw.Reset();
                        #endregion

                        #region 总成号为空,报警
                        if (string.IsNullOrEmpty(sn))
                        {
                            recodePLCStationMessage(LineName + STName, " The assembly number is empty and the verification fails.!", 0, true);
                            ABWrite(abPlc[lineObj.Index], BackAddr, "2", "int", 0);//fail
                            return;
                        }
                        #endregion

                        #region 获取配方,数据写入缓存
                        DataTable productionDt = crafts_Production_Bll.Select_All_Production_Table();
                        bool      loadFlag     = false;
                        for (int i = 0; i < productionDt.Rows.Count; i++)
                        {
                            if (sn.Contains(productionDt.Rows[i]["ProductionRule"].ToString()))
                            {
                                loadFlag = Recipe_Bll.LoadRecipes(productionDt.Rows[i]["ProductionName"].ToString(), STName);
                            }
                        }
                        if (!loadFlag)
                        {
                            recodePLCStationMessage(LineName + STName, "SN:" + sn + " , Can't recruit the product corresponding to the assembly, please check the formula!", 0, true);
                            ABWrite(abPlc[lineObj.Index], BackAddr, "12", opcitem.AddrType, 0);//fail
                            return;
                        }
                        Recipe_Bll.WriteCacheStationInfo(STName, "Step", "1");
                        Recipe_Bll.WriteCacheStationInfo(STName, "SN", sn);
                        #endregion

                        #region 处理数据
                        if (stationObj.Index != 1)
                        {
                            int    proIndex      = XML_Tool.xml.StationConfig.Single(n => n.Name == STName).Index - 1;
                            string stationStatus = trace_StationStatus_Bll.Select_State__CurStationInfo_Table(XML_Tool.xml.StationConfig.Single(n => n.Index == proIndex).Name, sn);
                            if (stationStatus == "1")
                            {
                                recodePLCStationMessage(LineName + STName, "SN:" + sn + " , Verification pass!", 0, true);
                                ABWrite(abPlc[lineObj.Index], BackAddr, "11", opcitem.AddrType, 0);//success
                                Recipe_Bll.Business(LineName, STName, stepNo + 1);
                            }
                            else
                            {
                                recodePLCStationMessage(LineName + STName, "SN:" + sn + " , Verification failed!", 0, true);
                                ABWrite(abPlc[lineObj.Index], BackAddr, "12", opcitem.AddrType, 0);//fail
                                #region 清空缓存
                                Recipe_Bll.ResetCacheStationInfo(STName);
                                Recipe_Bll.ResetCacheStationRecipeInfo(STName);
                                #endregion
                            }
                        }
                        else
                        {
                            recodePLCStationMessage(LineName + STName, "SN:" + sn + " , First station verification passed!", 0, true);
                            ABWrite(abPlc[lineObj.Index], BackAddr, "11", opcitem.AddrType, 0);//success
                            Recipe_Bll.Business(LineName, STName, stepNo + 1);
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        recodePLCStationMessage(LineName + STName, " There is a problem with the assembly binding, exception information:" + ex.Message, 1, true);
                    }
                }
                #endregion

                #region 物料追溯
                if (type == "DataRecord" && OPCName == "物料记录" && itemValue == "1")
                {
                    try
                    {
                        int    stepNo = Convert.ToInt32(Recipe_Bll.GetCacheStationInfo(STName, "Step"));
                        string sn     = Recipe_Bll.GetCacheStationInfo(STName, "SN");
                        Crafts_Recipe_Modle crafts_Recipe_Modle = Recipe_Bll.GetSingleRecipe(STName, stepNo);

                        #region 读取plc地址里的值
                        Stopwatch sw      = new Stopwatch();
                        var       stObj   = lineObj.STATION.Single(n => n.Name == STName);
                        var       opcitem = stObj.Opcitem.SingleOrDefault(n => n.Name == OPCName);
                        var       tag     = opcitem.Tag.SingleOrDefault(n => n.Tag == int.Parse(itemValue));
                        if (tag == null)
                        {
                            return;
                        }
                        recodePLCStationMessage(LineName + STName, " SN:" + sn + ",Start material data record", 0, true);
                        var dataList = tag.Dataitem;
                        sw.Start();
                        string dbColumnStr = string.Empty, dbValueStr = string.Empty, logInfo = string.Empty, barCode = string.Empty;
                        foreach (var item in dataList)
                        {
                            dbColumnStr += "[" + item.ColmnName + "]" + ",";
                            dbValueStr  += ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + "','";
                            logInfo     += item.ColmnName + " : " + ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + " , ";
                            if (item.ColmnName == "SN")
                            {
                                barCode = ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)).ToString();
                            }
                        }
                        sw.Stop();
                        sw.Reset();
                        #endregion

                        #region 校验扫描条码是否正确
                        if (crafts_Recipe_Modle.IsCheck == 1)
                        {
                            if (!barCode.Contains(crafts_Recipe_Modle.CheckRule))
                            {
                                recodePLCStationMessage(LineName + STName, " SN:" + sn + " , Material barcode:" + barCode + " , Verification rule:" + crafts_Recipe_Modle.CheckRule + " ,Verification failed!", 0, true);
                                ABWrite(abPlc[lineObj.Index], BackAddr, "2", "int", 0);//fail
                                return;
                            }
                        }
                        #endregion

                        #region 追溯数据处理
                        if (crafts_Recipe_Modle.Istrace == 1)
                        {
                            string count = trace_Keypart_Bll.Select_Count__Material_Table(STName, sn, barCode);
                            if (count != "0")
                            {
                                trace_Keypart_Bll.Delete_Con_Material_Table(STName, sn, barCode);
                                recodePLCStationMessage(LineName + STName, " Data:" + logInfo + " existed," + "Incomplete data cleared!", 0, true);
                            }
                            trace_Keypart_Modle.ComponentName    = crafts_Recipe_Modle.ComponentName;
                            trace_Keypart_Modle.ComponentBarcode = barCode;
                            trace_Keypart_Modle.RecordTime       = DateTime.Now.ToString();
                            trace_Keypart_Modle.SN      = sn;
                            trace_Keypart_Modle.Station = STName;
                            if (trace_Keypart_Bll.Insert_Condition_Material_Table(trace_Keypart_Modle) > 0)
                            {
                                ABWrite(abPlc[lineObj.Index], BackAddr, "1", "int", 0);//success
                            }
                            else
                            {
                                ABWrite(abPlc[lineObj.Index], BackAddr, "2", "int", 0);//fail
                            }
                            recodePLCStationMessage(LineName + STName, logInfo + " Material data record completed!", 0, true);
                            Recipe_Bll.Business(LineName, STName, stepNo + 1);
                        }
                        else
                        {
                            recodePLCStationMessage(LineName + STName, logInfo + " ,No traceback required!", 0, true);
                            ABWrite(abPlc[lineObj.Index], BackAddr, "1", "int", 0);//success
                            Recipe_Bll.Business(LineName, STName, stepNo + 1);
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        recodePLCStationMessage(LineName + STName, " Material traceability problems, abnormal information:" + ex.Message, 1, true);
                    }
                }
                #endregion

                #region 拧紧追溯
                if (type == "DataRecord" && OPCName == "拧紧记录" && itemValue == "1" || itemValue == "5" || itemValue == "22")
                {
                    try
                    {
                        var stObj   = lineObj.STATION.Single(n => n.Name == STName);
                        var opcitem = stObj.Opcitem.SingleOrDefault(n => n.Name == OPCName);

                        #region 重新给使能
                        if (itemValue == "5")
                        {
                            ABWrite(abPlc[lineObj.Index], BackAddr, "21", opcitem.AddrType, 0);
                            return;
                        }
                        if (itemValue == "0")
                        {
                            return;
                        }
                        #endregion

                        string st = Recipe_Bll.GetCacheStationInfo(STName, "Step");
                        if (string.IsNullOrEmpty(st))
                        {
                            return;
                        }
                        int    stepNo = Convert.ToInt32(Recipe_Bll.GetCacheStationInfo(STName, "Step"));
                        string sn     = Recipe_Bll.GetCacheStationInfo(STName, "SN");
                        Crafts_Recipe_Modle crafts_Recipe_Modle = Recipe_Bll.GetSingleRecipe(STName, stepNo);

                        #region 进入下一步
                        if (itemValue == "22")
                        {
                            Recipe_Bll.Business(LineName, STName, stepNo + 1);
                            return;
                        }
                        #endregion

                        #region 无需追溯,直接通过
                        if (crafts_Recipe_Modle.Istrace == 0)
                        {
                            if (boltCurNumber < crafts_Recipe_Modle.BlotNumber)
                            {
                                recodePLCStationMessage(LineName + STName, "SN:" + sn + ",Formula number " + stepNo + " ," + boltCurNumber + "No bolts are traced!", 0, true);
                                return;
                            }
                            else
                            {
                                boltCurNumber = 0;
                                recodePLCStationMessage(LineName + STName, "SN:" + sn + ",Formula number " + stepNo + " ," + boltCurNumber + "No bolts are traced!进入下一步", 0, true);
                                Recipe_Bll.Business(LineName, STName, stepNo + 1);
                                return;
                            }
                        }
                        #endregion

                        #region 读取plc地址里的值
                        Stopwatch sw  = new Stopwatch();
                        var       tag = opcitem.Tag.SingleOrDefault(n => n.Tag == int.Parse(itemValue));
                        if (tag == null)
                        {
                            return;
                        }
                        recodePLCStationMessage(LineName + STName, "SN:" + sn + ",Start tightening the data record", 0, true);
                        var dataList = tag.Dataitem;
                        sw.Start();
                        string dbColumnStr = string.Empty, dbValueStr = string.Empty, logInfo = string.Empty;
                        string result = string.Empty, torgue = string.Empty, angle = string.Empty;
                        foreach (var item in dataList)
                        {
                            dbColumnStr += "[" + item.ColmnName + "]" + ",";
                            dbValueStr  += ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + "','";
                            logInfo     += item.ColmnName + " : " + ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + " , ";
                            if (item.ColmnName == "Result")
                            {
                                result = ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)).ToString();
                            }
                            if (item.ColmnName == "BoltValue")
                            {
                                torgue = ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)).ToString();
                            }
                            if (item.ColmnName == "BoltAngle")
                            {
                                angle = ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)).ToString();
                            }
                        }
                        dbColumnStr = dbColumnStr + "[BoltName]" + "," + "[BoltNo]" + "," + "[SN]" + ",";
                        dbValueStr  = dbValueStr + crafts_Recipe_Modle.ComponentName + "','" + boltCurNumber + "','" + sn + "','";
                        sw.Stop();
                        sw.Reset();
                        #endregion

                        #region 处理追溯数据
                        if (result != "2")
                        {
                            boltCurNumber++;//螺栓数量自加1
                            string count = trace_Bolt_Bll.Select_Count__Bolt_Table(STName, sn, boltCurNumber);
                            if (count != "0")
                            {
                                trace_Bolt_Bll.Delete_Con_Bolt_Table(STName, sn, boltCurNumber);
                                recodePLCStationMessage(LineName + STName, "Data:" + logInfo + "Already exists, incomplete data has been cleared!", 0, true);
                            }
                        }
                        if (trace_Bolt_Bll.Insert_Condition_Bolt_Table(tag.TableName, dbColumnStr, dbValueStr, STName) > 0)
                        {
                            ABWrite(abPlc[lineObj.Index], BackAddr, "11", opcitem.AddrType, 0);//success
                            recodePLCStationMessage(LineName + STName, " Tighten back success!", 0, true);
                        }
                        else
                        {
                            ABWrite(abPlc[lineObj.Index], BackAddr, "12", opcitem.AddrType, 0);//fail
                        }
                        recodePLCStationMessage(LineName + STName, logInfo + " Tighten the data record to complete!", 0, true);

                        //最后一颗螺栓进入下一步
                        if (boltCurNumber - 1 == crafts_Recipe_Modle.BlotNumber)
                        {
                            boltCurNumber = 0;
                            recodePLCStationMessage(LineName + STName, "SN:" + sn + ",Formula number " + stepNo + " ," + boltCurNumber + " bolt are traced back!", 0, true);
                            Recipe_Bll.Business(LineName, STName, stepNo + 1);
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        recodePLCStationMessage(LineName + STName, "Tighten back to the problem, abnormal information:" + ex.Message, 1, true);
                    }
                }
                #endregion

                #region 测量追溯
                if (type == "DataRecord" && OPCName.Contains("测量记录") && itemValue == "1")
                {
                    try
                    {
                        #region 局部变量
                        string st = Recipe_Bll.GetCacheStationInfo(STName, "Step");
                        if (string.IsNullOrEmpty(st))
                        {
                            return;
                        }
                        int    stepNo = Convert.ToInt32(Recipe_Bll.GetCacheStationInfo(STName, "Step"));
                        string sn     = Recipe_Bll.GetCacheStationInfo(STName, "SN");
                        Crafts_Recipe_Modle crafts_Recipe_Modle = Recipe_Bll.GetSingleRecipe(STName, stepNo);
                        #endregion

                        #region 无需追溯,直接通过
                        if (crafts_Recipe_Modle.Istrace == 0)
                        {
                            recodePLCStationMessage(LineName + STName, "SN:" + sn + ",Step:" + stepNo + ",Formula number " + stepNo + " ," + boltCurNumber + " No bolts are traced back!", 0, false);
                            Recipe_Bll.Business(LineName, STName, stepNo + 1);
                            return;
                        }
                        #endregion

                        #region 读取plc地址里的值
                        Thread.Sleep(3000);
                        string    testName = Recipe_Bll.GetTestType(crafts_Recipe_Modle.ComponentName);
                        Stopwatch sw       = new Stopwatch();
                        var       stObj    = lineObj.STATION.Single(n => n.Name == STName);
                        var       opcitem  = stObj.Opcitem.SingleOrDefault(n => n.Name == OPCName);
                        var       tag      = opcitem.Tag.SingleOrDefault(n => n.Tag == int.Parse(itemValue));
                        if (tag == null)
                        {
                            return;
                        }
                        recodePLCStationMessage(LineName + STName, "SN:" + sn + ",Start measuring data records", 0, false);
                        var dataList = tag.Dataitem;
                        sw.Start();
                        string dbColumnStr = string.Empty, dbValueStr = string.Empty, logInfo = string.Empty, result = string.Empty;
                        foreach (var item in dataList)
                        {
                            dbColumnStr += "[" + item.ColmnName + "]" + ",";
                            dbValueStr  += ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + "','";
                            logInfo     += item.ColmnName + " : " + ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)) + " , ";
                            if (item.ColmnName == "MeasureResult")
                            {
                                result = ABRead(abPlc[lineObj.Index], item.Addr, item.AddrType, ushort.Parse(item.AddrLength)).ToString();
                                recodePLCStationMessage(LineName + STName, "Measure name :" + testName + ",Step:" + stepNo + ", Result:" + result, 0, true);
                            }
                        }
                        sw.Stop();
                        sw.Reset();
                        #endregion

                        #region 检测星云插入到数据库的数据
                        string count = Trace_Measure_Bll.Select_Count_Measure_Table(STName, sn, opcitem.OperationDesc);
                        if (int.Parse(count) == 0)
                        {
                            recodePLCStationMessage(LineName + STName, "SN:" + sn + ",Step:" + stepNo + ",test name " + testName + " , need tace: " + XML_Tool.xml.TestDBConfig.Count + ",really trace :" + count + " failed!", 1, false);
                            ABWrite(abPlc[lineObj.Index], BackAddr, "12", opcitem.AddrType, 0);
                            return;
                        }
                        #endregion

                        #region 处理追溯结果
                        if (result == "1")
                        {
                            ABWrite(abPlc[lineObj.Index], BackAddr, "11", opcitem.AddrType, 0);//success
                            recodePLCStationMessage(LineName + STName, "Measure name :" + testName + ",Step:" + stepNo + ", Measurement data recording completed!", 0, false);
                            Recipe_Bll.Business(LineName, STName, stepNo + 1);
                        }
                        else
                        {
                            ABWrite(abPlc[lineObj.Index], BackAddr, "11", opcitem.AddrType, 0);//fail
                            recodePLCStationMessage(LineName + STName, "Measure name :" + testName + ",Step:" + stepNo + ", Measurement data recording completed!The result is NG!", 0, true);
                        }
                        #endregion
                    }
                    catch (Exception ex)
                    {
                        recodePLCStationMessage(LineName + STName, "Measurement traceability problems, abnormal information :" + ex.Message, 0, true);
                    }
                }
                #endregion

                #region 报警处理
                if ((type == "Alarm" && OPCName == "模块故障" && itemValue != "0") ||
                    (type == "Alarm" && OPCName != "模块故障" && itemValue == "true"))
                {
                    var dateTime    = DateTime.Now;
                    var dateTimeInt = long.Parse(dateTime.ToString("yyMMddHHmmss"));
                    Line_StationAlarm_Bll.Insert(dateTimeInt, dateTime.ToString(), "", MA.Parameter["addr"], STName, "DeviceCheck_Alarm", OPCName);
                }
                #endregion
            }
            catch (Exception ex)
            {
                recodePLCStationMessage(string.Empty, " PLC business processing problems, abnormal information:" + ex.Message, 0, true);
            }
        }
Example #3
0
        /// <summary>
        /// 更新步序和下发类别
        /// </summary>
        /// <param name="line"></param>
        /// <param name="station"></param>
        /// <param name="packPn"></param>
        /// <param name="step"></param>
        public static void Business(string lineName, string station, int step)
        {
            #region 检查当前步是否大于总步数
            //string ss = Recipe_Bll.GetCacheStationInfo(station, "TotalStep");
            //int totalStep = int.Parse(Recipe_Bll.GetCacheStationInfo(station, "TotalStep"));
            //if (step > totalStep)
            //{
            //    recodeRecipeMessage(lineName + station, "Current step can not more than the total Step, Current step:" + step + " , total step:" + totalStep, 1, true);
            //    return;
            //}
            #endregion

            #region 变量
            Recipe_Bll.WriteCacheStationInfo(station, "Step", step.ToString());
            var lineObj    = XML_Tool.xml.LINE.Single(n => n.Name == lineName);
            var stationObj = lineObj.STATION.Single(n => n.Name == station);
            Crafts_Recipe_Modle crafts_Recipe_Modle = GetSingleRecipe(station, step);
            #endregion

            #region 配方为空
            if (crafts_Recipe_Modle == null)
            {
                recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:" + step + " ,Formula not found!", 1, true);
                return;
            }
            #endregion

            #region 扫描
            if (crafts_Recipe_Modle.OperationType == "扫描" || crafts_Recipe_Modle.OperationType == "Scanning")
            {
                var    opcObj   = stationObj.Opcitem.Single(n => n.Name == "物料记录");
                string backAddr = opcObj.BackAddr;
                if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], backAddr, "21", opcObj.AddrType, 0))
                {
                    recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                        + step + " ,Send scan address:" + backAddr + " , Write value :21 ,Successfully written!", 0, true);
                }
                else
                {
                    recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                        + step + " ,Send scan address:" + backAddr + " , Write value :21 ,Write failure!", 0, true);
                }
            }
            #endregion

            #region 拧紧
            if (crafts_Recipe_Modle.OperationType == "拧紧" || crafts_Recipe_Modle.OperationType == "Tighten")
            {
                var    opcObj      = stationObj.Opcitem.Single(n => n.Name == "拧紧记录");
                string backAddr    = opcObj.BackAddr;
                var    dataitemObj = opcObj.Tag.Single(n => n.Name == "拧紧下发").Dataitem;
                foreach (var data in dataitemObj)
                {
                    string sn = Recipe_Bll.GetCacheStationInfo(station, "SN");
                    if (data.ColmnName == "SN")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, sn, data.AddrType, 0))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,SN:" + data.Addr + " , Write value :"
                                                + sn + " ,Successfully written!", 0, false);
                        }
                    }
                    if (data.ColmnName == "BlotNumber")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, crafts_Recipe_Modle.BlotNumber.ToString(), data.AddrType, 0))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,BlotNumber:" + data.Addr + " , Write value :"
                                                + crafts_Recipe_Modle.BlotNumber.ToString() + " ,Successfully written!", 0, true);
                        }
                    }
                    if (data.ColmnName == "SleeveNo")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, crafts_Recipe_Modle.SleeveNo.ToString(), data.AddrType, 0))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,SleeveNo:" + data.Addr + " , Write value :"
                                                + crafts_Recipe_Modle.SleeveNo.ToString() + " ,Successfully written!", 0, true);
                        }
                    }
                    if (data.ColmnName == "ProgramNo")
                    {
                        if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, crafts_Recipe_Modle.ProgramNo.ToString(), data.AddrType, 0))
                        {
                            recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                + step + " ,ProgramNo:" + data.Addr + " , Write value :"
                                                + crafts_Recipe_Modle.ProgramNo.ToString() + " ,Successfully written!", 0, true);
                        }
                    }
                }
                if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], backAddr, "21", opcObj.AddrType, 0))
                {
                    recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                        + step + " ,Send tightening address:" + backAddr + " , Write value :"
                                        + " 21,Successfully written!", 0, true);
                }
                else
                {
                    recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                        + step + " ,Send tightening address:" + backAddr + " , Write value :"
                                        + " 21,Write failure!", 0, true);
                }
            }
            #endregion

            #region 测量
            if (crafts_Recipe_Modle.OperationType == "测量" || crafts_Recipe_Modle.OperationType == "Measuring")
            {
                var    opcObj      = stationObj.Opcitem.Single(n => n.Name.Contains("测量记录"));
                string backAddr    = opcObj.BackAddr;
                var    dataitemObj = opcObj.Tag.Single(n => n.Name == "测量下发").Dataitem;
                if (dataitemObj.Count == 0)//无需下发程序号
                {
                    if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], backAddr, "21", opcObj.AddrType, 0))
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 21,Successfully written!", 0, true);
                    }
                    else
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 21,Write failure!", 0, true);
                    }
                }
                else
                {
                    foreach (var data in dataitemObj)
                    {
                        if (data.Name == "ProgramNo")
                        {
                            if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], data.Addr, crafts_Recipe_Modle.ProgramNo.ToString(), data.AddrType, 0))
                            {
                                recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                                    + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                                    + crafts_Recipe_Modle.ProgramNo.ToString() + " ,Successfully written!", 0, true);
                            }
                        }
                    }
                    if (PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], backAddr, "21", opcObj.AddrType, 0))
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 21,Successfully written!", 0, true);
                    }
                    else
                    {
                        recodeRecipeMessage(lineName + station, "Station:" + station + " , Step:"
                                            + step + " ,Send measuring address:" + backAddr + " , Write value :"
                                            + " 21,Write failure!", 0, true);
                    }
                }
            }
            #endregion

            #region 结束
            if (crafts_Recipe_Modle.OperationType == "结束" || crafts_Recipe_Modle.OperationType == "End")
            {
                string sn     = Recipe_Bll.GetCacheStationInfo(station, "SN");
                var    opcObj = stationObj.Opcitem.Single(n => n.Name == "总成绑定");
                PLC_Bll.ABWrite(PLC_Bll.abPlc[lineObj.Index], opcObj.BackAddr, "0", opcObj.AddrType, 0);

                #region 获取工位结果以及工单号
                int    result    = 1;
                string workOrder = Crafts_CurPlan_Bll.Select_workOrder_Table();
                #endregion

                #region 数据转移
                Trace_StationStatus_Bll.TraceData_Transfer(station, sn);
                #endregion

                #region 添加工位状态
                trace_StationStatus_Modle.RecordTime    = DateTime.Now.ToString();
                trace_StationStatus_Modle.SN            = sn;
                trace_StationStatus_Modle.Station       = station;
                trace_StationStatus_Modle.StationBeat   = PLC_Bll.timeAdd.ToString();
                trace_StationStatus_Modle.StationStatue = result;
                trace_StationStatus_Modle.WorkOrder     = workOrder;
                if (XML_Tool.xml.StationConfig.Single(n => n.Name == station).IsEnd == "1" ||
                    XML_Tool.xml.StationConfig.Single(n => n.Name == station).IsOutLine == "1")
                {
                    trace_StationStatus_Bll.Insert_Condition_CurStationInfo_Table(trace_StationStatus_Modle, true);
                }
                else
                {
                    trace_StationStatus_Bll.Insert_Condition_CurStationInfo_Table(trace_StationStatus_Modle, false);
                }
                PLC_Bll.timeAddFlag = false;
                #endregion

                #region 清除数据缓存
                ResetCacheStationInfo(station);
                ResetCacheStationRecipeInfo(station);
                #endregion

                recodeRecipeMessage(lineName + station, "Station:" + station + " , SN :" + sn + " Go offline!", 0, true);
            }
            #endregion
        }