change - 添加验证 优化代码

wangsr
wangsr 1 year ago
parent 98bd3c57c4
commit e83ec7e87d

@ -12,8 +12,7 @@ namespace Mesnac.Action.ChemicalWeighing.InterfaceDocking
public string PostResponse(TankIsDischargedSyncEntity taskIsDisChargedSyncEntity) public string PostResponse(TankIsDischargedSyncEntity taskIsDisChargedSyncEntity)
{ {
return Post("http://192.168.202.23:5001/api/ReceivingAndFeedingMaterials/TankIsDischargedSync", taskIsDisChargedSyncEntity. return Post("http://192.168.202.23:5001/api/ReceivingAndFeedingMaterials/TankIsDischargedSync", taskIsDisChargedSyncEntity.JsonTo());
JsonTo());
} }

@ -35,22 +35,22 @@ namespace Mesnac.Action.ChemicalWeighing.LjReport.OpenDoor
} }
public class OpenDoorService //public class OpenDoorService
{ //{
public static void Insert(OpenDoorEntity entity) // public static void Insert(OpenDoorEntity entity)
{ // {
var ctx= FreeDb.FreeSqlUnit.Instance; // var ctx= FreeDb.FreeSqlUnit.Instance;
var openDoorEntity = ctx.Queryable<OpenDoorEntity>().Where(x => x.Status == entity.Status) // var openDoorEntity = ctx.Queryable<OpenDoorEntity>().Where(x => x.Status == entity.Status)
.Where(x => x.DeviceId == entity.DeviceId).OrderByDescending(x => x.CreateTime) // .Where(x => x.DeviceId == entity.DeviceId).OrderByDescending(x => x.CreateTime)
.Limit(1).ToOne(); // .Limit(1).ToOne();
if (openDoorEntity == null || entity.Status!=openDoorEntity.Status) // if (openDoorEntity == null || entity.Status!=openDoorEntity.Status)
{ // {
ctx.Insert(entity).ExecuteInserted(); // ctx.Insert(entity).ExecuteInserted();
} // }
} // }
} //}
} }

@ -58,6 +58,8 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
Color backColor; Color backColor;
Dictionary<int, int> WetStatus = new Dictionary<int, int>();
#region 控件变量 #region 控件变量
IBaseControl WaterActualValue1; IBaseControl WaterActualValue1;
@ -119,7 +121,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
public void Run(RuntimeParameter runtime) public void Run(RuntimeParameter runtime)
{ {
base.RunIni(runtime); //必须要调用的 base.RunIni(runtime); //必须要调用的
#region 控件获取 #region 控件获取
@ -246,8 +248,8 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
private void Wet1_CheckedChanged(object sender, EventArgs e) private void Wet1_CheckedChanged(object sender, EventArgs e)
{ {
MCRadioButton mCRadio = sender as MCRadioButton; MCRadioButton mCRadio = sender as MCRadioButton;
Wet1.BackColor = backColor; Wet1.BackColor = backColor;
Wet2.BackColor=backColor; Wet2.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow; mCRadio.BackColor = Color.GreenYellow;
} }
@ -264,7 +266,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
MCRadioButton mCRadio = sender as MCRadioButton; MCRadioButton mCRadio = sender as MCRadioButton;
Wet5.BackColor = backColor; Wet5.BackColor = backColor;
Wet6.BackColor = backColor; Wet6.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow; mCRadio.BackColor = Color.GreenYellow;
} }
private void Wet7_CheckedChanged(object sender, EventArgs e) private void Wet7_CheckedChanged(object sender, EventArgs e)
@ -272,7 +274,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
MCRadioButton mCRadio = sender as MCRadioButton; MCRadioButton mCRadio = sender as MCRadioButton;
Wet7.BackColor = backColor; Wet7.BackColor = backColor;
Wet8.BackColor = backColor; Wet8.BackColor = backColor;
mCRadio.BackColor = Color.GreenYellow; mCRadio.BackColor = Color.GreenYellow;
} }
private MCRadioButton GetMCRadioButton(string name) 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, WetStatus.Add(deviceNo, statu);
OpenTime = DateTime.Now, DonwloadWetState(deviceNo, statu);
CreateTime = DateTime.Now, }
Status = statu
});
if (WetStatus[deviceNo] != statu)
{
WetStatus[deviceNo] = statu;
DonwloadWetState(deviceNo, statu);
}
}
private void DonwloadWetState(int deviceNo, int statu)
{
TankIsDischargedSyncEntity tankIsDischargedSyncEntity = new TankIsDischargedSyncEntity() TankIsDischargedSyncEntity tankIsDischargedSyncEntity = new TankIsDischargedSyncEntity()
{ {
reqCode = System.Guid.NewGuid().ToString(), reqCode = System.Guid.NewGuid().ToString(),
@ -356,7 +373,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
deviceNo = deviceNo.ToString(), deviceNo = deviceNo.ToString(),
state = statu.ToString(), state = statu.ToString(),
}; };
//即使网络不同 也不会影响上位机的使用 //即使网络不同 也不会影响上位机的使用
ThreadPool.QueueUserWorkItem(delegate ThreadPool.QueueUserWorkItem(delegate
{ {
@ -366,7 +383,6 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
// ManualLogControl($"湿混机{deviceNo}返回数据 " + returnTest); // ManualLogControl($"湿混机{deviceNo}返回数据 " + returnTest);
MesnacServiceManager.Instance.LoggingService.Info($"湿混机{deviceNo}返回数据" + returnTest); MesnacServiceManager.Instance.LoggingService.Info($"湿混机{deviceNo}返回数据" + returnTest);
}); });
} }
#endregion #endregion
@ -383,7 +399,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
DB2103 = new DB2103Helper(); DB2103 = new DB2103Helper();
no += 1; no += 1;
if(no > 5) if (no > 5)
{ {
no = 0; no = 0;
Timer1_Tick(); Timer1_Tick();
@ -399,14 +415,14 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
if (DB2119.Coolwater_A.Dos_End) 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); ManualLogControl("冷水称A称量结束", DB2119.Coolwater_A.Value_Initial, 2, 3, 1);
} }
} }
if (DB2119.Hotwater_A.Dos_End) 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); 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 (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); ManualLogControl("热水称B称量结束", DB2119.Hotwater_B.Value_Initial, 2, 2, 1);
} }
} }
if (DB2119.Spiral_A.Dos_End) 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) if (DB2119.Spiral_A.Weter_Bin == 1)
{ {
@ -445,7 +461,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
} }
if (DB2119.Spiral_B.Dos_End) 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) if (DB2119.Spiral_B.Weter_Bin == 1)
{ {
@ -463,7 +479,7 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
} }
if (DB2119.Spiral_C.Dos_End) 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) if (DB2119.Spiral_C.Weter_Bin == 1)
{ {
@ -848,7 +864,6 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
message = "湿混机4:" + status; message = "湿混机4:" + status;
} }
if (name == "HslSwitch5") if (name == "HslSwitch5")
{ {
message = "湿混机5:" + status; message = "湿混机5:" + status;

@ -1405,10 +1405,13 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
Thread.Sleep(100); Thread.Sleep(100);
if (PlcConnect.Instance.Write(address, binNo).IsSuccess) if (PlcConnect.Instance.Write(address, binNo).IsSuccess)
{ {
ManualLogControl("第 " + (i + 1) + " 次重发测试成功");
return; return;
} }
ManualLogControl("第 " + (i + 1) + " 次重发测试失败");
} }
MessageBox.Show(address + "写入失败!"); MessageBox.Show(address + "写入失败!");
ManualLogControl("PLC写入失败");
} }
} }
private void PlcControl(string address, bool state) private void PlcControl(string address, bool state)
@ -1424,10 +1427,13 @@ namespace Mesnac.Action.ChemicalWeighing.ManualControl
Thread.Sleep(100); Thread.Sleep(100);
if (PlcConnect.Instance.Write(address, state).IsSuccess) if (PlcConnect.Instance.Write(address, state).IsSuccess)
{ {
ManualLogControl("第 " + (i + 1) + " 次重发测试成功");
return; return;
} }
ManualLogControl("第 " + (i + 1) + " 次重发测试失败");
} }
MessageBox.Show(address + "写入失败!"); MessageBox.Show(address + "写入失败!");
ManualLogControl("PLC写入失败");
} }
} }

@ -14,20 +14,15 @@ namespace DataBlockHelper
public class PlcConnect public class PlcConnect
{ {
private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection()); private static readonly Lazy<SiemensS7Net> lazy = new Lazy<SiemensS7Net>(() => new PlcConnect().SiemensS7NetConnection());
public static SiemensS7Net Instance => lazy.Value; public static SiemensS7Net Instance => lazy.Value;
private PlcConnect() private PlcConnect()
{ {
}
}
public SiemensS7Net SiemensS7NetConnection() public SiemensS7Net SiemensS7NetConnection()
{ {
SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensPLCS siemensPLCS = SiemensPLCS.S1500;
SiemensS7Net s7 = new SiemensS7Net(siemensPLCS); SiemensS7Net s7 = new SiemensS7Net(siemensPLCS);
@ -40,12 +35,17 @@ namespace DataBlockHelper
{ {
s7.IpAddress = "192.168.0.100"; s7.IpAddress = "192.168.0.100";
s7.Port = 7788; s7.Port = 7788;
s7.ConnectServer(); var fn = s7.ConnectServer();
if (!fn.IsSuccess)
{
return new SiemensS7Net(siemensPLCS);
}
} }
return s7; return s7;
} }
} }
} }

Loading…
Cancel
Save