111
cjs
2025-06-12 55ae035e05530817bd3b923c3d6b1ec275e47332
ams/Hanhe.iWCS.JingmenGEMTwoProtocol/PLCControl.cs
@@ -29,6 +29,7 @@
using System.Globalization;
using static Hanhe.iWCS.JingmenGEMTwoProtocol.PLCControl;
using Hanhe.iWCS.DeviceDriver;
using System.Data.OleDb;
namespace Hanhe.iWCS.JingmenGEMTwoProtocol
{
@@ -183,7 +184,6 @@
                                                if (trayCode.errCode == 0 && trayCode.result.Length == 95)
                                                {
                                                    //获取托盘码等信息  读取通道 11、12、13的数据作为托盘码   读取其它通道 重量 叠包等信息 所有数据存入MachineInfo表
                                                    string flLoc = "";
                                                    string location = "";
                                                    GetMachineData(pmInfo,ref location, trayCode.result, false, "1");
@@ -731,18 +731,33 @@
        internal static void PickUpFullDoorComplete(string ip, string taskNo)
        {
            var plc = Settings.GetPlcInfo().Where(a => a.ip == ip).FirstOrDefault();
            if (plc != null)
            if (plc != null && !plc.location.Contains("FLZT"))
            {
                //写入包装机--安全门关门指令
                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                if (plc.location.Contains("FLZT"))
                {
                    host = ip,
                    addr = plc.writeAddr + 1,
                    data = 3,
                    port = plc.port
                });
                CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为4.");
                //Console.WriteLine($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为4.");
                    //写入返料站台--取货完成
                    var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                    {
                        host = ip,
                        addr = plc.writeAddr,
                        data = 1,
                        port = plc.port
                    });
                    CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为1.");
                }
                else
                {
                    //写入包装机--安全门关门指令
                    var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                    {
                        host = ip,
                        addr = plc.writeAddr + 1,
                        data = 3,
                        port = plc.port
                    });
                    CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为4.");
                }
            }
            else CMMLog.Debug($"包装下线,4,ip=null!");
        }
@@ -2251,7 +2266,6 @@
                                //可生成任务
                                var CBInfo = Settings.GetConnectingbitsList().Where(a => a.enable == 1).ToList();
                                if (CBInfo != null && timecuo != null)
                                //if (CBInfo != null)
                                {
                                    string timeStamp = timecuo.data.First().timeStamp.ToString();
                                    foreach (var a in CBInfo)
@@ -4478,6 +4492,272 @@
            CMMLog.Info($"在通道{plc.writeAddr + 2}中写入{JsonConvert.SerializeObject(num)},ip:{plc.ip},端口:{plc.port}");
        }
        /// <summary>
        /// 四钴A(洗板烘干机组)设备上空下满
        /// </summary>
        /// <param name="plc"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void AMachine(Settings.PlcInfo plc)
        {
            if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
            {
                try
                {
                    var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                    {
                        dataNum = 1,
                        addr = plc.readAddr,
                        host = plc.ip,
                        port = plc.port
                    });
                    if (result != null && result.errCode == 0)
                    {
                        if (result.result[0] == 1)
                        {
                            //送空
                            bool req = WMSHelper.WMSOut(plc.location, "", "");
                            if (req) CMMLog.Debug($"四钴A设备 调用WMS获取空托出库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
                            else CMMLog.Debug($"四钴A设备 调用WMS获取空托出库生成任务失败!");
                        }
                        if (result.result[0] == 2)
                        {
                            //取满
                            string wmstaskno = "";
                            string traycode = "";
                            bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
                            if (req) CMMLog.Debug($"四钴A设备 调用WMS获取满托入库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
                            else CMMLog.Debug($"四钴A设备 调用WMS获取满托入库生成任务失败!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    CMMLog.Info($"四钴A设备 err:{ex.Message}");
                }
            }
        }
        /// <summary>
        /// 四钴C(钴板剪切机组)设备上满下空
        /// </summary>
        /// <param name="a"></param>
        /// <exception cref="NotImplementedException"></exception>
        internal static void CMachine(Settings.PlcInfo plc)
        {
            if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
            {
                try
                {
                    var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                    {
                        dataNum = 1,
                        addr = plc.readAddr,
                        host = plc.ip,
                        port = plc.port
                    });
                    if (result != null && result.errCode == 0)
                    {
                        if (result.result[0] == 1)
                        {
                            //送满
                            bool req = WMSHelper.WMSOut(plc.location, "", "");
                            if (req) CMMLog.Debug($"四钴C设备 调用WMS获取满托出库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
                            else CMMLog.Debug($"四钴C设备 调用WMS获取满托出库生成任务失败!");
                        }
                        if (result.result[0] == 2)
                        {
                            //取空
                            string wmstaskno = "";
                            string traycode = "";
                            bool req = WMSHelper.WMSIn(plc.location, "", ref wmstaskno, ref traycode);
                            if (req) CMMLog.Debug($"四钴C设备 调用WMS获取空托入库生成任务成功!");//现在任务由WMS自己下发,AMS做拦截处理(查询ext1里面对应的任务类型,并更改任务类型)
                            else CMMLog.Debug($"四钴C设备 调用WMS获取空托入库生成任务失败!");
                        }
                    }
                }
                catch (Exception ex)
                {
                    CMMLog.Info($"四钴C设备 err:{ex.Message}");
                }
            }
        }
        internal static void DGMachine(Settings.PlcInfo plc, string taskNo, bool action)
        {
            if (action)
            {
                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                {
                    host = plc.ip,
                    addr = plc.writeAddr + 2,
                    data = 1,
                    port = plc.port
                });
                CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为1.");
                var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                {
                    dataNum = 1,
                    addr = plc.readAddr + 2,
                    host = plc.ip,
                    port = plc.port
                });
                CMMLog.Debug($"查询设备{plc.location}通道{plc.readAddr + 2}里面数据为{JsonConvert.SerializeObject(result)}.");
                if (result != null && result.errCode == 0)
                {
                    if (result.result[0] == 1)
                    {
                        //推送小车进入
                        TSHelper.GoToAGV(taskNo, 10, 3);
                        writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                        {
                            host = plc.ip,
                            addr = plc.writeAddr + 2,
                            data = 0,
                            port = plc.port
                        });
                        CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 2}里面数据为0.");
                    }
                }
            }
            else
            {
                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                {
                    host = plc.ip,
                    addr = plc.writeAddr + 3,
                    data = 1,
                    port = plc.port
                });
                CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 3}里面数据为1.");
            }
        }
        internal static void DGMachineTwo(Settings.PlcInfo plc, string taskNo, bool action)
        {
            if (action)
            {
                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                {
                    host = plc.ip,
                    addr = plc.writeAddr,
                    data = 1,
                    port = plc.port
                });
                CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为1.");
                var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                {
                    dataNum = 1,
                    addr = plc.readAddr + 1,
                    host = plc.ip,
                    port = plc.port
                });
                CMMLog.Debug($"查询设备{plc.location}通道{plc.readAddr + 1}里面数据为{JsonConvert.SerializeObject(result)}.");
                if (result != null && result.errCode == 0)
                {
                    if (result.result[0] == 1)
                    {
                        //推送小车进入
                        TSHelper.GoToAGV(taskNo, 10, 3);
                        writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                        {
                            host = plc.ip,
                            addr = plc.writeAddr,
                            data = 0,
                            port = plc.port
                        });
                        CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr}里面数据为0.");
                    }
                }
            }
            else
            {
                var writeRes = OITcpHelper.RegisterWriteOutPut(new OITcpHelper.RegisterWriteOutPutModel
                {
                    host = plc.ip,
                    addr = plc.writeAddr + 1,
                    data = 1,
                    port = plc.port
                });
                CMMLog.Debug($"写入设备{plc.location}通道{plc.writeAddr + 1}里面数据为1.");
            }
        }
        internal static void DMachine(Settings.PlcInfo plc)
        {
            if (PickUpStartFree(plc.location) && PickUpEndFree(plc.location))
            {
                try
                {
                    var result = OITcpHelper.RegisterReadOutPut(new OITcpHelper.RegisterReadOutPutModel
                    {
                        dataNum = 1,
                        addr = plc.readAddr,
                        host = plc.ip,
                        port = plc.port
                    });
                    if (result != null && result.errCode == 0)
                    {
                        if (result.result[0] == 1)
                        {
                            //成品下线任务生成到接驳平台
                            string traycode = DateTime.Now.ToString("yyyy-MM-dd").Replace("-", "");
                            //可生成任务
                            var CBInfo = Settings.GetConnectingbitsList().Where(a => a.enable == 1).ToList();
                            if (CBInfo != null)
                            {
                                //string timeStamp = timecuo.data.First().timeStamp.ToString();
                                string timeStamp = "";
                                foreach (var a in CBInfo)
                                {
                                    if (!string.IsNullOrEmpty(a.locCode))
                                    {
                                        //在中间表中查找点位
                                        var CBTable = MongoDBSingleton.Instance.FindOne<ConnectingBits>(Query.EQ("Bit", a.locCode), "ConnectingBits");
                                        if (CBTable != null)
                                        {
                                            if (string.IsNullOrEmpty(CBTable.trayCode))
                                            {
                                                //生成任务,并且将点位写入中间表
                                                var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "包装机满托下线", 0, traycode);
                                                if (amsResult.success)
                                                {
                                                    CMMLog.Debug($"包装机满托下线:AMS调用API成功!");
                                                    MongoDBSingleton.Instance.Update<ConnectingBits>(Query.EQ("Bit", a.locCode), Update.Set("trayCode", traycode).Set("timeCuo", timeStamp), UpdateFlags.None);
                                                    break;
                                                }
                                                else CMMLog.Debug($"包装机满托下线:AMS调用API失败,开始重新调用!");
                                            }
                                        }
                                        else
                                        {
                                            //生成任务,并且将点位写入中间表
                                            var amsResult = AMSHelper.CreateTask(DateTime.Now.Ticks.ToString(), plc.location, a.locCode, "包装机满托下线", 0, traycode);
                                            if (amsResult.success)
                                            {
                                                CMMLog.Debug($"包装机满托下线:AMS调用API成功!");
                                                //打包下线任务生成成功,向中间表插入数据
                                                MongoDBSingleton.Instance.Insert<ConnectingBits>(new ConnectingBits { Bit = a.locCode, trayCode = traycode, state = "0", timeCuo = timeStamp });
                                                break;
                                            }
                                            else CMMLog.Debug($"包装机满托下线:AMS调用API失败,开始重新调用!");
                                        }
                                    }
                                    else CMMLog.Debug("打包下线口接驳位点位未配置");
                                }
                            }
                            else CMMLog.Debug("打包下线口接驳位未配置");
                        }
                    }
                }
                catch (Exception ex)
                {
                    CMMLog.Info($"四钴C设备 err:{ex.Message}");
                }
            }
        }
        #endregion
        public class WMS_STOCK_VIEW