From febcd0c73b51b17f484ff9a9a189b1f85130c2f7 Mon Sep 17 00:00:00 2001
From: wangxinhui <wangxinhui@hnkhzn.com>
Date: 星期二, 17 三月 2026 13:52:06 +0800
Subject: [PATCH] 更新自动门,新增切卷卷绕缓存架

---
 wcs-server-hbf/WIDESEA_WCS/Jobs/RGV/AluminumCaseJob.cs |  498 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 495 insertions(+), 3 deletions(-)

diff --git a/wcs-server-hbf/WIDESEA_WCS/Jobs/RGV/AluminumCaseJob.cs b/wcs-server-hbf/WIDESEA_WCS/Jobs/RGV/AluminumCaseJob.cs
index bd8839f..78278e6 100644
--- a/wcs-server-hbf/WIDESEA_WCS/Jobs/RGV/AluminumCaseJob.cs
+++ b/wcs-server-hbf/WIDESEA_WCS/Jobs/RGV/AluminumCaseJob.cs
@@ -21,6 +21,12 @@
 using HslCommunication;
 using SqlSugar;
 using WIDESEA_Core.Extensions;
+using static System.Collections.Specialized.BitVector32;
+using WIDESEA_WCS.WCSClient.Modbus;
+using static FreeSql.Internal.GlobalFilter;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
+using System.Reflection.Metadata;
+using Dm;
 
 namespace WIDESEA_WCS
 {
@@ -32,6 +38,7 @@
     {
         FreeDB freeDB = new FreeDB();
         static List<HCJCenterEqDB> centerEqDBList;
+        static List<HCJCenterEqDB> centerJRDBList;
         private static object createTaskObj = new object();
         public Task Execute(IJobExecutionContext context)
         {
@@ -54,8 +61,321 @@
                 client.Connect();
                 return;
             }
-            //閾濆3缂撳瓨鏋朵笟鍔′綔涓�
-            LKHCJdispatch();
+            if (client.PLCName.Contains("閾濆3"))
+            {
+                //閾濆3缂撳瓨鏋朵笟鍔′綔涓�
+                LKHCJdispatch();
+            }
+            else
+            {
+                //鍗风粫缂撳瓨鏋朵笟鍔′綔涓�
+                JRHCJdispatch();
+            }
+            
+        }
+        /// <summary>
+        /// 鍗风粫缂撳瓨鏋朵笟鍔′綔涓�
+        /// </summary>
+        private void JRHCJdispatch()
+        {
+
+            //閾濆3缂撳瓨鏋舵惉杩�
+            PLCClient pLCClientJR = WCSService.Clients.Find(V => V.PLCName==PLCConst.PLCNameJR);
+            if (pLCClientJR != null)
+            {
+                string tsjJson = File.ReadAllText(AppContext.BaseDirectory + "/Config/鍗风粫缂撳瓨鏋�.json", Encoding.UTF8);
+                centerJRDBList = JsonConvert.DeserializeObject<List<HCJCenterEqDB>>(tsjJson);
+                if (centerJRDBList == null)
+                {
+                    return;
+                }
+                PLCClient agvzzplc = WCSService.Clients.Find(v => v.PLCName == "缁勮AGV璋冨害");
+                UpdateJRHCJ(pLCClientJR);
+                #region 鍗风粫鍙枡
+                List<base_ware_location> locations = freeDB.Select<base_ware_location>()
+                .Where(x => (x.tpgd == 0 && x.gd1 == 0 && x.gd2 == 0 && x.gd3 == 0 && x.gd4 == 0 && x.status == 1 && x.task == 2 && x.logic_layer == "1" && x.location_state == "LocationState_Empty") && (x.upper_code.Contains("QJHCJ10") || x.upper_code.Contains("QJHCJ11")))
+                .ToList();
+                foreach (var item in locations)
+                {
+                    if (item.geartype == "鏆傛棤")
+                    {
+                        WriteLog.GetLog().Write($"{item.upper_code}{item.geartype}---{DateTime.Now}", $"鍗风粫涓婃枡璇锋眰澶辫触");
+                        continue;
+                    }
+                    List<base_routing_table> routing_table = freeDB.Select<base_routing_table>()
+                .Where(v => v.route_end == item.upper_code).ToList();
+                    if (routing_table.Count > 0)//鏃犳枡鎵嶈兘鐢熸垚浠诲姟&& location_QJ.tpgd==0
+                    {
+                        List<string> route_begans = routing_table.Select(x => x.route_began).ToList();
+                        base_ware_location ware_Location = freeDB.Select<base_ware_location>()
+                .Where(d => route_begans.Contains(d.upper_code) && d.location_state == "LocationState_Stored" && d.logic_col == 1 && d.tpgd == 1 && d.status == 1 && d.task == 2 && d.geartype == item.geartype).OrderBy(d => d.update_time).First();
+                        if (ware_Location != null)
+                        {
+                            base_ware_location jkloction = ware_Location;
+                            #region 璁板綍涓婃枡璇锋眰淇″彿
+                            WriteLog.GetLog().Write($"{item.upper_code}涓婃枡璇锋眰---{DateTime.Now}", $"鍗风粫涓婃枡璇锋眰");
+                            #endregion
+                            //鍐嶆鍒ゆ柇鏄惁鏈変换鍔″瓨鍦�
+                            dt_agvtask agvtaskOld = freeDB.Select<dt_agvtask>().Where(x => x.agv_toaddress == item.upper_code).First();
+                            if (agvtaskOld != null && item.task == 2)
+                            {
+                                item.logic_col = 1;//璁剧疆鑹搧鐗╂枡
+                                item.task = 1;//璁剧疆浠诲姟鐢熸垚1
+                                var locationOffOld1 = freeDB.Update(item).UpdateColumns(t => new
+                                {
+                                    t.logic_col,
+                                    t.task
+                                }).ExecuteAffrows();
+                                continue;
+                            }
+                            dt_agvtask agvtask = new dt_agvtask()
+                            {
+                                agv_id = Guid.NewGuid(),
+                                agv_tasknum = "KH-" + IdenxManager.GetTaskNo(),
+                                agv_fromaddress = jkloction.upper_code,
+                                agv_toaddress = item.upper_code,
+                                agv_code = "缁勮AGV璋冨害",
+                                agv_remark = "鍒囧嵎涓婃枡鍛煎彨",
+                                agv_taskstate = AGVTaskStateEnum.Create.ToString(),
+                                agv_tasktype = AGVTaskTypeEnum.TaskType_Outbound.ToString(),
+                                agv_worktype = 1,//宸ヤ綔绫诲瀷
+                                agv_materielid = "",
+                                agv_qty = 1,
+                                agv_createtime = DateTime.Now,
+                                agv_grade = 0,//浠诲姟浼樺厛绾�
+                                agv_userid = "WCS",
+                                agv_barcode = ""
+                            };
+                            item.logic_col = 1;//璁剧疆鑹搧鐗╂枡
+                            item.task = 1;//璁剧疆浠诲姟鐢熸垚1
+                            var locationOff1 = freeDB.Update(item).UpdateColumns(t => new
+                            {
+                                t.logic_col,
+                                t.task
+                            }).ExecuteAffrows();
+                            jkloction.logic_col = 1;//璁剧疆鑹搧鐗╂枡
+                            jkloction.task = 1;//璁剧疆浠诲姟鐢熸垚1
+                            var locationOff2 = freeDB.Update(jkloction).UpdateColumns(t => new
+                            {
+                                t.logic_col,
+                                t.task
+                            }).ExecuteAffrows();
+                            freeDB.Add(agvtask);
+                        }
+                        else
+                        {
+                            WriteLog.GetLog().Write($"{item.upper_code}鏈壘鍒版弧瓒抽�佸線鍒囧嵎鐨勬瀬搴撴枡---{DateTime.Now}", $"鍗风粫涓婃枡璇锋眰澶辫触");
+                        }
+                    }
+                }
+                #endregion
+            }
+        }
+        private void UpdateJRHCJ(PLCClient client)
+        {
+            ModbusTcpNet ModbusPLCClient = client.ModbusPLCClient.ModbusTcpNetClient;
+            var stationList = centerJRDBList.FirstOrDefault(t => client.PLCName.Contains(t.HCJCenterName));
+            foreach (var item in stationList.stationInfos)
+            {
+                base_ware_location location = freeDB.Select<base_ware_location>()
+                .Where(x => x.upper_code == item.HCJCode)
+                .First();
+                ////Console.WriteLine($"{station.stationCode}------{DateTime.Now}");
+                if (location == null)
+                {
+                    continue;
+                }
+                string wlgd1DB = item.RPLCDB[0];//鐗╂枡鍏夌數1鐘舵�佷俊鍙风偣浣�
+                string wlgd2DB = item.RPLCDB[1];//鐗╂枡鍏夌數2鐘舵�佷俊鍙风偣浣�
+                string wlgd3DB = item.RPLCDB[2];//鐗╂枡鍏夌數3鐘舵�佷俊鍙风偣浣�
+                string wlgd4DB = item.RPLCDB[3];//鐗╂枡鍏夌數4鐘舵�佷俊鍙风偣浣�
+                string tpgdDB = item.RPLCDB[4];//鎵樼洏鍏夌數鐘舵�佷俊鍙风偣浣�
+                string buttonDB = item.RPLCDB[5];//鎸夐挳鐘舵�佷俊鍙风偣浣�
+
+                ////纭鎸夐挳(缁胯壊)
+                OperateResult<bool> R_TBR_XT1 = ModbusPLCClient.ReadBool(buttonDB);
+                OperateResult<bool> R_TBR_XT2 = ModbusPLCClient.ReadBool(buttonDB);
+                WriteLog.GetLog().Write($"{item.HCJName}缂撳瓨鏋�,杩炴帴{R_TBR_XT1.IsSuccess}{R_TBR_XT2.IsSuccess}", "鍗风粫缂撳瓨鏋�");
+                if (!R_TBR_XT1.IsSuccess && !R_TBR_XT2.IsSuccess)
+                {
+                    //Console.WriteLine($"-{ModbusPLCClient.IpAddress}---{station.stationCode}----{ButtonEnsureDB}--------false--{R_TBR_XT.Message}----------------");
+                    location.location_state = LocationStateEnum.LocationState_Close.ToString();
+                    location.tpgd = -1;
+                    location.update_time = DateTime.Now;
+                    location.wireless_time = DateTime.Now;
+                    var locationOff = freeDB.Update(location).UpdateColumns(t => new
+                    {
+                        t.location_state,
+                        t.tpgd,
+                        t.update_time,
+                        t.wireless_time
+                    }).ExecuteAffrows();
+                    continue;
+                }
+                OperateResult<bool> ButtonEnsure1 = ModbusPLCClient.ReadBool(buttonDB);
+                OperateResult<bool> ButtonEnsure2 = ModbusPLCClient.ReadBool(buttonDB);
+                //鎵樼洏鍏夌數鐘舵��
+                OperateResult<bool> tpgdstate1 = ModbusPLCClient.ReadBool(tpgdDB);
+                OperateResult<bool> tpgdstate2 = ModbusPLCClient.ReadBool(tpgdDB);
+                //鐗╂枡鍏夌數1鐘舵��
+                OperateResult<bool> wlgd1state1 = ModbusPLCClient.ReadBool(wlgd1DB);
+                OperateResult<bool> wlgd1state2 = ModbusPLCClient.ReadBool(wlgd1DB);
+                //鐗╂枡鍏夌數2鐘舵��
+                OperateResult<bool> wlgd2state1 = ModbusPLCClient.ReadBool(wlgd2DB);
+                OperateResult<bool> wlgd2state2 = ModbusPLCClient.ReadBool(wlgd2DB);
+                //鐗╂枡鍏夌數3鐘舵��
+                OperateResult<bool> wlgd3state1 = ModbusPLCClient.ReadBool(wlgd3DB);
+                OperateResult<bool> wlgd3state2 = ModbusPLCClient.ReadBool(wlgd3DB);
+                //鐗╂枡鍏夌數4鐘舵��
+                OperateResult<bool> wlgd4state1 = ModbusPLCClient.ReadBool(wlgd4DB);
+                OperateResult<bool> wlgd4state2 = ModbusPLCClient.ReadBool(wlgd4DB);
+                //鏍规嵁璇诲埌鐨凱LC淇℃伅锛岃疆璇㈡洿鏂版暟鎹簱淇℃伅
+                location.update_time = DateTime.Now;
+                location.wireless_time = DateTime.Now;
+                if (ButtonEnsure1.IsSuccess)
+                {
+                    location.logic_layer = ButtonEnsure1.Content ? "1" : "0";
+                }
+                if (ButtonEnsure2.IsSuccess)
+                {
+                    location.logic_layer = ButtonEnsure2.Content ? "1" : "0";
+                }
+                if (tpgdstate1.IsSuccess)
+                {
+                    location.tpgd = !tpgdstate1.Content ? 1 : 0;
+                }
+                if (tpgdstate2.IsSuccess)
+                {
+                    location.tpgd = !tpgdstate2.Content ? 1 : 0;
+                }
+                #region 鐗╂枡鍏夌數1
+                if (wlgd1state1.IsSuccess)
+                {
+                    location.gd1 = !wlgd1state1.Content ? 1 : 0; ;
+                }
+                if (wlgd1state2.IsSuccess)
+                {
+                    location.gd1 = !wlgd1state2.Content ? 1 : 0; ;
+                }
+                #endregion
+                #region 鐗╂枡鍏夌數2
+                if (wlgd2state1.IsSuccess)
+                {
+                    location.gd2 = !wlgd2state1.Content ? 1 : 0; ;
+                }
+                if (wlgd2state2.IsSuccess)
+                {
+                    location.gd2 = !wlgd2state2.Content ? 1 : 0; ;
+                }
+                #endregion
+                #region 鐗╂枡鍏夌數3
+                if (wlgd3state1.IsSuccess)
+                {
+                    location.gd3 = !wlgd3state1.Content ? 1 : 0; ;
+                }
+                if (wlgd3state2.IsSuccess)
+                {
+                    location.gd3 = !wlgd3state2.Content ? 1 : 0; ;
+                }
+                #endregion
+                #region 鐗╂枡鍏夌數4
+                if (wlgd4state1.IsSuccess)
+                {
+                    location.gd4 = !wlgd4state1.Content ? 1 : 0; ;
+                }
+                if (wlgd4state2.IsSuccess)
+                {
+                    location.gd4 = !wlgd4state2.Content ? 1 : 0; ;
+                }
+                #endregion
+                string LampYellowDB = item.WPLCDB[0];//榛勭伅淇″彿鐐逛綅
+                string LampGreenDB = item.WPLCDB[1];//缁跨伅淇″彿鐐逛綅
+                string LampRedDB = item.WPLCDB[2];//绾㈢伅淇″彿鐐逛綅
+
+                //璐ф灦瀛樺湪浠诲姟浠诲姟鏃�
+                if (location.tpgd == 1)
+                {
+                    location.location_state = LocationStateEnum.LocationState_Stored.ToString();
+                    OperateResult<bool> Yellow1 = ModbusPLCClient.ReadBool(LampYellowDB);
+                    OperateResult<bool> Yellow2 = ModbusPLCClient.ReadBool(LampYellowDB);
+                    if (location.logic_col == 2)
+                    {
+                        ModbusPLCClient.Write(LampRedDB, true); //绾㈢伅
+                        ModbusPLCClient.Write(LampRedDB, true); //绾㈢伅
+                    }
+                    if (location.task == 1 && (Yellow1.Content || Yellow2.Content))
+                    {
+                        //ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        //ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                        ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                    }
+                    else if(location.task == 1 && (!Yellow1.Content || !Yellow2.Content))
+                    {
+                        //ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        //ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                        ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                    }
+                    else
+                    {
+                        ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                        ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                        ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                        ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                        ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                        ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                    }
+                }
+                else
+                {
+                    location.location_state = LocationStateEnum.LocationState_Empty.ToString();
+                    OperateResult<bool> Yellow1 = ModbusPLCClient.ReadBool(LampYellowDB);
+                    OperateResult<bool> Yellow2 = ModbusPLCClient.ReadBool(LampYellowDB);
+                    if (location.logic_col == 2)
+                    {
+                        ModbusPLCClient.Write(LampRedDB, true); //绾㈢伅
+                        ModbusPLCClient.Write(LampRedDB, true); //绾㈢伅
+                    }
+                    
+                    if (location.task == 1 && (Yellow1.Content || Yellow2.Content))
+                    {
+                        ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                        ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                    }
+                    else if (location.task == 1 && (!Yellow1.Content || !Yellow2.Content))
+                    {
+                        ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                        ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                        ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                    }
+                    else
+                    {
+                        ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                        ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                        ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                        ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                        ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                        ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                    }
+                }
+
+                var executeAffrows = freeDB.Update(location).UpdateColumns(t => new
+                {
+                    t.location_state,
+                    t.logic_layer,
+                    t.update_time,
+                    t.wireless_time,
+                    t.tpgd,
+                    t.gd1,
+                    t.gd2,
+                    t.gd3,
+                    t.gd4
+                }).ExecuteAffrows();
+            }
         }
         private void LKHCJdispatch()
         {
@@ -445,6 +765,42 @@
                 doorState_1f_cx += 30;
            
             }
+            //鍏ュ3缂撳瓨鏋�
+            double comErr_rk = 9450.0;//鏄惁鎺夌嚎
+            double doorCode_rk = 9452.0;//缂撳瓨鏋禝D
+            double doorState_rk = 9474.0;//缂撳瓨鏋剁墿鏂欑姸鎬侊紙1锛氱┖浣嶏紝2:绌烘墭鐩橈紝3锛氭弧鎵樼洏锛�
+            var dt_stationinfo_rk = freeDB.Select<dt_stationinfo>().Where(d => d.stationType == "鍏ュ3缂撳瓨鏋�").OrderBy(t => t.sort).ToList();
+            foreach (var item in dt_stationinfo_rk)
+            {
+
+                if (item.connect == true)
+                {
+                    //鎺夌嚎
+                }
+                else
+                {
+                    if (item.tpgd == true && item.wlgd == true)
+                    {
+                        OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_rk, Convert.ToInt16(3));
+                    }
+                    else if (item.tpgd == true && item.wlgd == false)
+                    {
+                        OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_rk, Convert.ToInt16(2));
+                    }
+                    else
+                    {
+                        OperateResult W_HCJ_FullState = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorState_rk, Convert.ToInt16(1));
+                    }
+                }
+
+                OperateResult W_HCJ_StationCode = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + doorCode_rk, item.stationCode.ToString());
+                OperateResult W_HCJ_ComErr = agvzzplc.SiemensPLCClient.SiemensS7NetClient.Write("DB1003." + comErr_rk, item.connect);
+
+                comErr_1f_cx += 30;
+                doorCode_1f_cx += 30;
+                doorState_1f_cx += 30;
+
+            }
         }
 
         private void agvtaskAdd(string agv_remark, string begin, string end,bool communi)
@@ -641,7 +997,7 @@
                         t.LampYellow
                     }).ExecuteAffrows();
                 }
-                else if (stationList.HCJCenterName == "閾濆3缂撳瓨鏋朵竴妤�")
+                else if (stationList.HCJCenterName == "閾濆3缂撳瓨鏋朵竴妤�" && !item.HCJName.Contains("鍏ュ3缂撳瓨鏋�"))
                 {
                     string ButtonResetDB = item.RPLCDB[0];  //澶嶄綅鎸夐挳(榛勮壊)淇″彿鐐逛綅
                     string ButtonEnsureDB = item.RPLCDB[1];//纭鎸夐挳(缁胯壊)淇″彿鐐逛綅
@@ -820,6 +1176,142 @@
                         t.LampYellow
                     }).ExecuteAffrows();
                 }
+                else if (stationList.HCJCenterName == "閾濆3缂撳瓨鏋朵竴妤�" && item.HCJName.Contains("鍏ュ3缂撳瓨鏋�"))
+                {
+                    string ButtonEnsureDB = item.RPLCDB[0];//纭鎸夐挳(缁胯壊)淇″彿鐐逛綅
+                    string tpgdstateDB = item.RPLCDB[1];//鎵樼洏鍏夌數鐘舵�佷俊鍙风偣浣�
+                    string wlgdstateDB = item.RPLCDB[2];//鐗╂枡鍏夌數鐘舵�佷俊鍙风偣浣�
+
+                    ////纭鎸夐挳(缁胯壊)
+                    OperateResult<bool> R_TBR_XT = ModbusPLCClient.ReadBool(ButtonEnsureDB);
+                    WriteLog.GetLog().Write($"{item.HCJName}缂撳瓨鏋�,杩炴帴{R_TBR_XT.IsSuccess}", "鍏ュ3缂撳瓨鏋�");
+                    if (!R_TBR_XT.IsSuccess)
+                    {
+                        //Console.WriteLine($"-{ModbusPLCClient.IpAddress}---{station.stationCode}----{ButtonEnsureDB}--------false--{R_TBR_XT.Message}----------------");
+                        station.connect = true;
+                        var stationoff = freeDB.Update(station).UpdateColumns(t => new
+                        {
+                            t.connect
+                        }).ExecuteAffrows();
+                        continue;
+                    }
+                    bool ButtonEnsure = ModbusPLCClient.ReadBool(ButtonEnsureDB).Content;
+                    //鎵樼洏鍏夌數鐘舵��
+                    bool pgdstate = ModbusPLCClient.ReadBool(tpgdstateDB).Content;
+                    //鐗╂枡鍏夌數鐘舵��
+                    bool wlgdstate = ModbusPLCClient.ReadBool(wlgdstateDB).Content;
+
+                    //鏍规嵁璇诲埌鐨凱LC淇℃伅锛岃疆璇㈡洿鏂版暟鎹簱淇℃伅
+                    station.getLastTime = DateTime.Now;
+                    station.greenbutton = ButtonEnsure;
+                    station.tpgd = pgdstate;
+                    station.wlgd = wlgdstate;
+
+                    string LampYellowDB = item.WPLCDB[0];//榛勭伅淇″彿鐐逛綅
+                    string LampGreenDB = item.WPLCDB[1];//缁跨伅淇″彿鐐逛綅
+                    string LampRedDB = item.WPLCDB[2];//绾㈢伅淇″彿鐐逛綅
+                    //璐ф灦瀛樺湪浠诲姟浠诲姟鏃�
+                    if (station.task)
+                    {
+                        if (station.LampYellow)
+                        {
+                            ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                            ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                            ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                                                                       // Console.WriteLine($"{station.stationCode}---浜�---{DateTime.Now}");
+                            station.LampRed = false;
+                            station.LampYellow = false;
+                            station.LampGreen = false;
+
+                        }
+                        else
+                        {
+                            ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                            ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                            ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                                                                       // Console.WriteLine($"{station.stationCode}---鐏�---{DateTime.Now}");
+                            station.LampRed = false;
+                            station.LampYellow = true;
+                            station.LampGreen = false;
+
+                        }
+                    }
+                    else
+                    {
+                        //褰撴湁浜烘寜涓嬬豢鑹叉寜閽椂锛�
+                        //灏嗙紦瀛樻灦鐨勭伅鍏変寒缁跨伅
+                        if (ButtonEnsure && pgdstate && wlgdstate)
+                        {
+                            DateTime date = DateTime.Now;
+                            DateTime time2 = station.greenbuttontime;
+                            Double STAMP = (date - time2).TotalSeconds;
+                            if (STAMP > 4)
+                            {
+                                if (station.LampGreen)
+                                {
+                                    ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                                    station.LampGreen = false;
+
+                                }
+                                else
+                                {
+                                    ModbusPLCClient.Write(LampGreenDB, true); //缁跨伅
+                                    station.LampGreen = true;
+                                }
+
+                                //ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                                ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                                //station.LampRed = false;
+                                station.LampYellow = false;
+                                station.greenbuttontime = DateTime.Now;
+                            }
+                        }
+                        else if (station.LampGreen && (!pgdstate || !wlgdstate))
+                        {
+                            ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                            ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                            ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                            station.LampRed = false;
+                            station.LampYellow = false;
+                            station.LampGreen = false;
+                        }
+                        //妫�娴嬫墭鐩樺厜鐢垫湁鏂欙紝浣嗘湭鎸夌‘璁ゆ寜閽紝浜粍鐏�
+                        else if (!station.LampGreen && pgdstate)
+                        {
+                            // ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                            ModbusPLCClient.Write(LampYellowDB, true); //榛勭伅
+                            ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+                                                                       // station.LampRed = false;
+                            station.LampYellow = true;
+                            station.LampGreen = false;
+                        }
+                        else if (!station.LampGreen && !pgdstate && !wlgdstate)
+                        {
+                            ModbusPLCClient.Write(LampRedDB, false); //绾㈢伅
+                            ModbusPLCClient.Write(LampYellowDB, false); //榛勭伅
+                            ModbusPLCClient.Write(LampGreenDB, false); //缁跨伅
+
+                            station.LampRed = false;
+                            station.LampYellow = false;
+                            station.LampGreen = false;
+                        }
+
+                    }
+
+                    station.connect = false;
+
+                    var executeAffrows = freeDB.Update(station).UpdateColumns(t => new
+                    {
+                        t.connect,
+                        t.getLastTime,
+                        t.greenbutton,
+                        t.tpgd,
+                        t.wlgd,
+                        t.LampRed,
+                        t.LampGreen,
+                        t.LampYellow
+                    }).ExecuteAffrows();
+                }
             }
         }
 

--
Gitblit v1.9.3