diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs index 384b8aa..8201713 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/InterfaceDocking/HttpResponse.cs @@ -12,8 +12,7 @@ namespace Mesnac.Action.ChemicalWeighing.InterfaceDocking public string PostResponse(TankIsDischargedSyncEntity taskIsDisChargedSyncEntity) { - return Post("http://192.168.202.23:5001/api/ReceivingAndFeedingMaterials/TankIsDischargedSync", taskIsDisChargedSyncEntity. - JsonTo()); + return Post("http://192.168.202.23:5001/api/ReceivingAndFeedingMaterials/TankIsDischargedSync", taskIsDisChargedSyncEntity.JsonTo()); } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/OpenDoor/OpenDoorEntity.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/OpenDoor/OpenDoorEntity.cs index f93a2cf..3e9ed2c 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/OpenDoor/OpenDoorEntity.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjReport/OpenDoor/OpenDoorEntity.cs @@ -35,22 +35,22 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport.OpenDoor } - public class OpenDoorService - { - public static void Insert(OpenDoorEntity entity) - { - var ctx= FreeDb.FreeSqlUnit.Instance; + //public class OpenDoorService + //{ + // public static void Insert(OpenDoorEntity entity) + // { + // var ctx= FreeDb.FreeSqlUnit.Instance; - var openDoorEntity = ctx.Queryable().Where(x => x.Status == entity.Status) - .Where(x => x.DeviceId == entity.DeviceId).OrderByDescending(x => x.CreateTime) - .Limit(1).ToOne(); + // var openDoorEntity = ctx.Queryable().Where(x => x.Status == entity.Status) + // .Where(x => x.DeviceId == entity.DeviceId).OrderByDescending(x => x.CreateTime) + // .Limit(1).ToOne(); - if (openDoorEntity == null || entity.Status!=openDoorEntity.Status) - { - ctx.Insert(entity).ExecuteInserted(); - } + // if (openDoorEntity == null || entity.Status!=openDoorEntity.Status) + // { + // ctx.Insert(entity).ExecuteInserted(); + // } - } - } + // } + //} } diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/InitAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/InitAction.cs index 4b13955..377e5e6 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/InitAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/InitAction.cs @@ -58,6 +58,8 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl Color backColor; + Dictionary WetStatus = new Dictionary(); + #region 控件变量 IBaseControl WaterActualValue1; @@ -119,7 +121,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl public void Run(RuntimeParameter runtime) { - + base.RunIni(runtime); //必须要调用的 #region 控件获取 @@ -246,8 +248,8 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl private void Wet1_CheckedChanged(object sender, EventArgs e) { MCRadioButton mCRadio = sender as MCRadioButton; - Wet1.BackColor = backColor; - Wet2.BackColor=backColor; + Wet1.BackColor = backColor; + Wet2.BackColor = backColor; mCRadio.BackColor = Color.GreenYellow; } @@ -264,7 +266,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl MCRadioButton mCRadio = sender as MCRadioButton; Wet5.BackColor = backColor; Wet6.BackColor = backColor; - mCRadio.BackColor = Color.GreenYellow; + mCRadio.BackColor = Color.GreenYellow; } private void Wet7_CheckedChanged(object sender, EventArgs e) @@ -272,7 +274,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl MCRadioButton mCRadio = sender as MCRadioButton; Wet7.BackColor = backColor; Wet8.BackColor = backColor; - mCRadio.BackColor = Color.GreenYellow; + mCRadio.BackColor = Color.GreenYellow; } private MCRadioButton GetMCRadioButton(string name) @@ -338,17 +340,32 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl } - private void Time(int deviceNo,int statu) + private void Time(int deviceNo, int statu) { - OpenDoorService.Insert(new OpenDoorEntity() + //OpenDoorService.Insert(new OpenDoorEntity() + //{ + // DeviceId = deviceNo, + // OpenTime = DateTime.Now, + // CreateTime = DateTime.Now, + // Status = statu + //}); + + if (WetStatus.ContainsKey(deviceNo) == false) { - DeviceId = deviceNo, - OpenTime = DateTime.Now, - CreateTime = DateTime.Now, - Status = statu - }); + WetStatus.Add(deviceNo, statu); + DonwloadWetState(deviceNo, statu); + } + if (WetStatus[deviceNo] != statu) + { + WetStatus[deviceNo] = statu; + DonwloadWetState(deviceNo, statu); + } + } + + private void DonwloadWetState(int deviceNo, int statu) + { TankIsDischargedSyncEntity tankIsDischargedSyncEntity = new TankIsDischargedSyncEntity() { reqCode = System.Guid.NewGuid().ToString(), @@ -356,7 +373,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl deviceNo = deviceNo.ToString(), state = statu.ToString(), }; - + //即使网络不同 也不会影响上位机的使用 ThreadPool.QueueUserWorkItem(delegate { @@ -366,7 +383,6 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl // ManualLogControl($"湿混机{deviceNo}返回数据 " + returnTest); MesnacServiceManager.Instance.LoggingService.Info($"湿混机{deviceNo}返回数据" + returnTest); }); - } #endregion @@ -383,7 +399,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl DB2103 = new DB2103Helper(); no += 1; - if(no > 5) + if (no > 5) { no = 0; Timer1_Tick(); @@ -399,14 +415,14 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl if (DB2119.Coolwater_A.Dos_End) { - if(PlcControl("DB2119.28.3", false)) + if (PlcControl("DB2119.28.3", false)) { ManualLogControl("冷水称A称量结束", DB2119.Coolwater_A.Value_Initial, 2, 3, 1); - } + } } if (DB2119.Hotwater_A.Dos_End) { - if(PlcControl("DB2119.08.3", false)) + if (PlcControl("DB2119.08.3", false)) { ManualLogControl("热水称A称量结束", DB2119.Hotwater_A.Value_Initial, 2, 1, 1); } @@ -420,14 +436,14 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl } if (DB2119.Hotwater_B.Dos_End) { - if(PlcControl("DB2119.18.3", false)) + if (PlcControl("DB2119.18.3", false)) { ManualLogControl("热水称B称量结束", DB2119.Hotwater_B.Value_Initial, 2, 2, 1); } } if (DB2119.Spiral_A.Dos_End) { - if(PlcControl("DB2119.60.3", false)) + if (PlcControl("DB2119.60.3", false)) { if (DB2119.Spiral_A.Weter_Bin == 1) { @@ -445,7 +461,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl } if (DB2119.Spiral_B.Dos_End) { - if(PlcControl("DB2119.82.3", false)) + if (PlcControl("DB2119.82.3", false)) { if (DB2119.Spiral_B.Weter_Bin == 1) { @@ -463,7 +479,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl } if (DB2119.Spiral_C.Dos_End) { - if(PlcControl("DB2119.104.3", false)) + if (PlcControl("DB2119.104.3", false)) { if (DB2119.Spiral_C.Weter_Bin == 1) { @@ -848,7 +864,6 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl message = "湿混机4:" + status; } - if (name == "HslSwitch5") { message = "湿混机5:" + status; diff --git a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ManualControlAction.cs b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ManualControlAction.cs index 4db1404..fa2595c 100644 --- a/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ManualControlAction.cs +++ b/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/ManualControl/ManualControlAction.cs @@ -1405,10 +1405,13 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl Thread.Sleep(100); if (PlcConnect.Instance.Write(address, binNo).IsSuccess) { + ManualLogControl("第 " + (i + 1) + " 次重发测试成功"); return; } + ManualLogControl("第 " + (i + 1) + " 次重发测试失败"); } MessageBox.Show(address + "写入失败!"); + ManualLogControl("PLC写入失败!"); } } private void PlcControl(string address, bool state) @@ -1424,10 +1427,13 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl Thread.Sleep(100); if (PlcConnect.Instance.Write(address, state).IsSuccess) { + ManualLogControl("第 " + (i + 1) + " 次重发测试成功"); return; } + ManualLogControl("第 " + (i + 1) + " 次重发测试失败"); } MessageBox.Show(address + "写入失败!"); + ManualLogControl("PLC写入失败!"); } } diff --git a/DataBlockHelper/PlcConnect.cs b/DataBlockHelper/PlcConnect.cs index 057bf4b..98c6a99 100644 --- a/DataBlockHelper/PlcConnect.cs +++ b/DataBlockHelper/PlcConnect.cs @@ -14,20 +14,15 @@ namespace DataBlockHelper public class PlcConnect { - - private static readonly Lazy lazy = new Lazy(() => new PlcConnect().SiemensS7NetConnection()); public static SiemensS7Net Instance => lazy.Value; - - private PlcConnect() + + private PlcConnect() { - - } - - + } - public SiemensS7Net SiemensS7NetConnection() + public SiemensS7Net SiemensS7NetConnection() { SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); @@ -40,12 +35,17 @@ namespace DataBlockHelper { s7.IpAddress = "192.168.0.100"; s7.Port = 7788; - s7.ConnectServer(); + var fn = s7.ConnectServer(); + if (!fn.IsSuccess) + { + return new SiemensS7Net(siemensPLCS); + } } + return s7; } } - + }