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;
@ -341,14 +343,29 @@ 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(),
@ -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
@ -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,8 +14,6 @@ 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;
@ -24,9 +22,6 @@ namespace DataBlockHelper
} }
public SiemensS7Net SiemensS7NetConnection() public SiemensS7Net SiemensS7NetConnection()
{ {
SiemensPLCS siemensPLCS = SiemensPLCS.S1500; SiemensPLCS siemensPLCS = SiemensPLCS.S1500;
@ -40,8 +35,13 @@ 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