11
cjs
4 天以前 daca75da47c4ba7e2927bd07d59d4316a4e6ac6d
ams/Hanhe.iWCS.JingmenGLMNorthProtocol/PLCControl.cs
@@ -201,13 +201,21 @@
                                                                if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
                                                                CMMLog.Debug($"包装下线流程-{pmInfo.location}:叠托层数为0,不允许生成任务");
                                                            }
                                                            else if (tray.trayCode != "0" && !string.IsNullOrEmpty(tray.trayCode))
                                                            if (string.IsNullOrEmpty(tray.lotNo))
                                                            {
                                                                 MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo", RemoveFlags.None);
                                                                 if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
                                                                 CMMLog.Debug($"包装下线流程-{pmInfo.location}:批次号为空,不允许生成任务");
                                                            }
                                                            if (tray.trayCode != "0" && !string.IsNullOrEmpty(tray.trayCode))
                                                            {
                                                                string timeStamp = ProcessHelper.GetTimeStamp(31, 1, 1);
                                                                HHAmsExecuteResult req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3楼包装取料", 0, tray.trayCode, timeStamp);
                                                                if (req.success)
                                                                {
                                                                    string weight = (double.Parse(tray.oneTrayWeight1) / 100).ToString();
                                                                    //CMMLog.Debug("北区测试数据:包装下线重量:"+(decimal.Parse(tray.oneTrayWeight1) / 100).ToString("F2"));
                                                                    //int weight = int.Parse(tray.oneTrayWeight) / 100;
                                                                    ERPService.packageInfo(tray.machineNo, tray.trayCode, tray.lotNo, weight,1);
                                                                }
@@ -402,7 +410,14 @@
                                                            if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
                                                            CMMLog.Debug($"包装下线流程-{pmInfo.location}:叠托层数为0,不允许生成任务");
                                                        }
                                                        else if (tray.trayCode != "0" && !string.IsNullOrEmpty(tray.trayCode))
                                                        if (string.IsNullOrEmpty(tray.lotNo))
                                                        {
                                                            MongoDBSingleton.Instance.Remove<MachineInfo>(Query.EQ("machineNo", pmInfo.location), "MachineInfo", RemoveFlags.None);
                                                            if (ERPService.ERPSwitch01 == "0") MongoDBSingleton.Instance.Remove<MachineInfoTwo>(Query.EQ("machineNo", pmInfo.location), "MachineInfoTwo", RemoveFlags.None);
                                                            CMMLog.Debug($"包装下线流程-{pmInfo.location}:批次号为空,不允许生成任务");
                                                        }
                                                        if (tray.trayCode != "0" && !string.IsNullOrEmpty(tray.trayCode))
                                                        {
                                                            string timeStamp = ProcessHelper.GetTimeStamp(31, 1, 1);
                                                            HHAmsExecuteResult req = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), pmInfo.location, PlcBit02, "3楼包装取料", 0, tray.trayCode, timeStamp);
@@ -1153,14 +1168,12 @@
                            {
                                CMMLog.Info($"SecondWeightActionOne: machine:{query.machineNo},trayCode:{query.trayCode},weight:{query.weight}");
                                //读取复称平台的重量
                                //Convert.ToInt32(Completion(result[8]) + Completion(result[9]), 2).ToString()
                                //(decimal.Parse(tray.oneTrayWeight1) / 100).ToString("F2");
                                string weight = (decimal.Parse(Convert.ToInt32(Completion(result.result[6]) + Completion(result.result[7]), 2).ToString()) / 100).ToString("F2");
                                //string weight = ((result.result[3] * 65536 + result.result[4]) / 100).ToString();
                                string weight = ((double)Convert.ToInt32(Completion(result.result[3]) + Completion(result.result[4]), 2) / 100).ToString();
                                //CMMLog.Debug("北区测试数据:复称重量:" + ((double)Convert.ToInt32(Completion(result.result[3]) + Completion(result.result[4]), 2) / 100).ToString());
                                CMMLog.Debug($"SecondWeightActionOne: 读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 7}里面数据为{result.result[6]}.");
                                CMMLog.Debug($"SecondWeightActionOne: 读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 8}里面数据为{result.result[7]}.");
                                //double x = (double)Convert.ToInt32(Completion(result[8]) + Completion(result[9]), 2) / 100;
                                //CMMLog.Info($"SecondWeightActionOne: 读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 4}里面数据为{result.result[3]}.");
                                CMMLog.Info($"SecondWeightActionOne: 读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 4}里面数据为{result.result[3]}.");
                                CMMLog.Info($"SecondWeightActionOne: 读取设备{plc.location},ip:{plc.ip}通道{plc.readAddr + 5}里面数据为{result.result[4]}.");
                                CMMLog.Info($"SecondWeightActionOne: weight:{weight}");
                                //重量差值
@@ -1174,8 +1187,6 @@
                        }
                        else CMMLog.Info($"SecondWeightActionOne: packageInfoModel未找到数据,machineNo:{model.machince},trayCode:{model.ext2}");
                        #endregion
                        string PlcBit02 = Settings.GetPlcInfo().Where(a => a.deviceType == "2").FirstOrDefault().location;
                        UpdateBuilder update = Update.Set("ng", result.result[2]);
@@ -1199,7 +1210,7 @@
            if (infoTwo != null)
            {
                //var newWeight = (Convert.ToInt32(Completion(result[6]) + Completion(result[7]), 2) / 100).ToString();
                var newWeight =  result[6] + "," + result[7];
                var newWeight =  result[5] + "," + result[6];
                //更新数据
                CMMLog.Info($"从复称平台获取的物料重量:{newWeight}");
@@ -1419,7 +1430,7 @@
                //读取通道1里面参数是否为1,判断叠盘机是否需要上料
                var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                {
                    dataNum = 1,
                    dataNum = 3,
                    addr = pmInfo.readAddr + 1,
                    host = pmInfo.ip,
                    port = pmInfo.port
@@ -1429,14 +1440,20 @@
                    //参数1表示叠托点申请入料
                    if (result.result[0] == 1)
                    {
                        CMMLog.Debug($"获取碟盘机信号:{JsonConvert.SerializeObject(result)}");
                        var tasks = MongoDBSingleton.Instance.Find<TN_I_TASK_MST>(Query.EQ("CN_S_END_BIT", pmInfo.location), "TN_I_TASK_MST");
                        //判断一下当前叠托点是否有任务占用
                        if (ProcessHelper.CheckEndFree(pmInfo.location) && tasks.Count == 0)
                        {
                            //可以生成任务,调WMS接口获取任务信息
                            bool req = WMSHelper.WMSOut(pmInfo.location, "");
                            if (req) CMMLog.Debug($"调用WMS获取碟盘出库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
                            else CMMLog.Debug($"调用WMS获取碟盘出库生成任务失败!");
                            string trayType = result.result[2] == 1 ? "田字托" : result.result[2] == 2 ? "川字托" : "";
                            if (result.result[2] >= 1 && result.result[2] <= 2)
                            {
                                //可以生成任务,调WMS接口获取任务信息
                                bool req = WMSHelper.WMSOut(pmInfo.location, "",trayType);
                                if (req) CMMLog.Debug($"调用WMS获取碟盘出库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
                                else CMMLog.Debug($"调用WMS获取碟盘出库生成任务失败!");
                            }
                        }
                        else CMMLog.Debug($"检查当前叠托点是否有任务占用,或者MST主表中有缓存架入叠盘机的任务!");
                    }
@@ -1574,6 +1591,7 @@
                    host = plc.ip,
                    port = plc.port
                });
                CMMLog.Debug($"缓存架入叠托,读取叠包口信号:{JsonConvert.SerializeObject(readres)}");
                if (readres != null)
                {
                    var taskInfo = MongoDBSingleton.Instance.FindOne<TN_I_TASK_MST>(Query.EQ("CN_S_TASK_NO", taskNo), "TN_I_TASK_MST");
@@ -1994,7 +2012,7 @@
                //RegisterReadInPut 读取输入寄存器还是输出寄存器待定,读取通道1的数据
                var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                {
                    dataNum = 1,
                    dataNum = 2,
                    addr = plc.readAddr+1,
                    host = plc.ip,
                    port = plc.port
@@ -2009,7 +2027,10 @@
                        {
                            string wmstaskno = "";
                            string traycode = "";
                            bool req = WMSHelper.WMSEmptyOut(plc.location, "", ref wmstaskno, ref traycode);
                            string trayType = "";
                            if (result.result[1] == 1) trayType = "田字托";
                            else trayType = "川字托";
                            bool req = WMSHelper.WMSEmptyOut(plc.location, "",trayType, ref wmstaskno, ref traycode);
                            if (req) CMMLog.Debug($"调用WMS获取三楼拆盘机生成任务成功!");
                            else CMMLog.Debug($"调用WMS获取三楼拆盘机生成任务失败!");
                        }
@@ -3001,7 +3022,7 @@
                    info.productWeight = Convert.ToInt32(Completion(result[4]) + Completion(result[5]), 2).ToString();
                    info.oneTrayWeight1 = Convert.ToInt32(Completion(result[6]) + Completion(result[7]), 2).ToString();
                    info.oneTrayWeight = Convert.ToInt32(Completion(result[8]) + Completion(result[9]), 2).ToString();
                    //info.oneTrayWeight = Convert.ToInt32(Completion(result[10]) + Completion(result[11]), 2).ToString();
                    info.trayType = Convert.ToInt32(Completion(result[10]), 2).ToString();
                    info.addState = Convert.ToInt32(Completion(result[11]), 2);
                    info.packageCode = Convert.ToInt32(Completion(result[12]), 2).ToString();
@@ -3013,7 +3034,7 @@
                    
                    CMMLog.Info($"数据处理流程:获取MODBUS转换后的数据信息:location:{info.location},trayCode:{info.trayCode},productWeight:{info.productWeight}" +
                        $",oneTrayWeight1:{info.oneTrayWeight1},oneTrayWeight:{info.oneTrayWeight} "+
                        $",oneTrayWeight1:{info.oneTrayWeight1},oneTrayWeight:{info.oneTrayWeight},trayType:{info.trayType} "+
                        $"addState:{info.addState},packageCode:{info.packageCode}");
                    #endregion
@@ -3069,7 +3090,7 @@
                    var query1 = Query.And(Query.EQ("machineNo", location), Query.EQ("trayCode", "0"));
                    UpdateBuilder updateBuider = Update.Set("location", info.location).
                        Set("trayCode", info.trayCode).Set("productWeight", info.productWeight).
                        Set("oneTrayWeight", info.oneTrayWeight).Set("oneTrayWeight1", info.oneTrayWeight1).
                        Set("oneTrayWeight", info.oneTrayWeight).Set("oneTrayWeight1", info.oneTrayWeight1).Set("trayType", info.trayType).
                        Set("addWeight", info.addWeight).Set("packNg", info.packNg).Set("secondNg", info.secondNg).Set("addState", info.addState).
                        Set("packageCode", info.packageCode).Set("jsonData", json).Set("modify", DateTime.Now);
                    MongoDBSingleton.Instance.Update<MachineInfo>(query1, updateBuider, "MachineInfo", UpdateFlags.None);
@@ -3087,7 +3108,7 @@
                    {
                        UpdateBuilder updateBuider = Update.Set("location", info.location).
                        Set("trayCode", info.trayCode).Set("productWeight", info.productWeight).
                        Set("oneTrayWeight", info.oneTrayWeight).Set("oneTrayWeight1", info.oneTrayWeight1).
                        Set("oneTrayWeight", info.oneTrayWeight).Set("oneTrayWeight1", info.oneTrayWeight1).Set("trayType", info.trayType).
                        Set("addWeight", info.addWeight).Set("packNg", info.packNg).Set("secondNg", info.secondNg).Set("addState", info.addState).
                        Set("packageCode", info.packageCode).Set("jsonData", json).Set("modify", DateTime.Now);
                        MongoDBSingleton.Instance.Update<MachineInfo>(query2, updateBuider, "MachineInfo", UpdateFlags.None);
@@ -3456,7 +3477,7 @@
                num[b] = Convert.ToInt32(Convert.ToString(int.Parse(machine.oneTrayWeight), 2).PadLeft(32, '0').ToString().Substring(k, 16), 2);
            }
            //for (int b = 10; b <= 11; b++) num[b] = 0;// 叠包后实际重量 && 复称结果 默认:0
            num[10] = string.IsNullOrEmpty(machine.palletLayers) ? 0 : int.Parse(machine.palletLayers);  //是否需要叠托盘
            num[10] = int.Parse(machineInfoTwo.trayType);  //托盘类型
            num[11] = machine.addState; //是否需要叠包
            num[12] = int.Parse(machine.packageCode);  //袋号
            //员工编号