|
|
@@ -16,14 +16,10 @@ namespace BPASmartClient.Academy._50L |
|
|
|
private volatile static PlcControl _Instance; |
|
|
|
public static PlcControl GetInstance => _Instance ?? (_Instance = new PlcControl()); |
|
|
|
private PlcControl() { } |
|
|
|
public bool IsConnect => true; |
|
|
|
public bool IsConnect => comm != null && comm.IsConnected(); |
|
|
|
public DeviceStatus DeviceStatus { get; set; } = new DeviceStatus(); |
|
|
|
private ICommSiemens comm = CommHelper.Siemens; |
|
|
|
public Action<bool> IsConnectChanged { get; set; } |
|
|
|
public string id { get; set; } = ""; |
|
|
|
private bool _lastConnectState; |
|
|
|
private volatile uint _readFailureCount; |
|
|
|
private Timer _readTrendDataTimer; |
|
|
|
public void Init() |
|
|
|
{ |
|
|
|
Task.Factory.StartNew(() => |
|
|
@@ -31,10 +27,8 @@ namespace BPASmartClient.Academy._50L |
|
|
|
CommHelper.CreateSiemens(CpuType.S71500, Json<DevicePar>.Data.IpAddress).OnSuccess(s => |
|
|
|
{ |
|
|
|
comm = s.Content; |
|
|
|
_lastConnectState = true; |
|
|
|
IsConnectChanged?.Invoke(true); |
|
|
|
WriteHeartBeat(); |
|
|
|
Read(); |
|
|
|
//_readTrendDataTimer = new(ReadTrendData, null,0,2000); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
@@ -46,7 +40,6 @@ namespace BPASmartClient.Academy._50L |
|
|
|
{ |
|
|
|
TaskManage.GetInstance.StartLong(() => |
|
|
|
{ |
|
|
|
_readFailureCount = 0; |
|
|
|
comm.Read<bool[]>("DB1.DBX2000.0", 31).OnSuccess(s => |
|
|
|
{ |
|
|
|
//Data[FeedbackData.旋转电机启停反馈] = s.Content[0]; |
|
|
@@ -86,7 +79,7 @@ namespace BPASmartClient.Academy._50L |
|
|
|
DeviceStatus.ColdWaterTankVacuumValve = s.Content[16]; |
|
|
|
DeviceStatus.CompressorRunning = s.Content[17]; |
|
|
|
#endregion |
|
|
|
}).OnFailure((s) => { _readFailureCount++; }); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
comm.Read<float[]>("DB1.DBD2006", 10).OnSuccess(s => |
|
|
@@ -140,7 +133,7 @@ namespace BPASmartClient.Academy._50L |
|
|
|
_isReadSuccess = true; |
|
|
|
} |
|
|
|
}); |
|
|
|
comm.Read<bool>("DB1.DBX1003.7", 1).OnSuccess(s => DeviceStatus.HeartBeat = s.Content ).OnFailure((s) => { _readFailureCount++; }); |
|
|
|
comm.Read<bool>("DB1.DBX1003.7", 1).OnSuccess(s => DeviceStatus.HeartBeat = s.Content ); |
|
|
|
|
|
|
|
comm.Read<bool[]>("DB1.DBX2004.0", 16).OnSuccess(s => |
|
|
|
{ |
|
|
@@ -149,80 +142,31 @@ namespace BPASmartClient.Academy._50L |
|
|
|
AlarmHelper.GetInstance.Get<AlarmData>("50L反应釜").AbnormalNegativePressureFan = s.Content[2]; |
|
|
|
AlarmHelper.GetInstance.Get<AlarmData>("50L反应釜").BrinePumpError = s.Content[3]; |
|
|
|
AlarmHelper.GetInstance.Get<AlarmData>("50L反应釜").CompressorError = s.Content[4]; |
|
|
|
}).OnFailure((s) => { _readFailureCount++; }); |
|
|
|
|
|
|
|
if (Delay.GetInstance("心跳").Start(!DeviceStatus.HeartBeat, 2)) |
|
|
|
{ |
|
|
|
Write(BoolAddEnum.心跳, true); |
|
|
|
} |
|
|
|
//if (_readFailureCount > 3 && _lastConnectState) |
|
|
|
//{ |
|
|
|
// _lastConnectState = false; |
|
|
|
// IsConnectChanged?.Invoke(false); |
|
|
|
//} |
|
|
|
//if (_readFailureCount == 0 && !_lastConnectState) |
|
|
|
//{ |
|
|
|
// _lastConnectState = true; |
|
|
|
// IsConnectChanged?.Invoke(true); |
|
|
|
//} |
|
|
|
IsConnectChanged?.Invoke(this.IsConnect); |
|
|
|
}); |
|
|
|
|
|
|
|
Thread.Sleep(100); |
|
|
|
}, "数据获取", true); |
|
|
|
//ThreadManage.GetInstance.StartLong(() => |
|
|
|
//{ |
|
|
|
// if (true)//产品开始测试数据 |
|
|
|
// { |
|
|
|
|
|
|
|
// } |
|
|
|
//}, "实时曲线数据"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void ReadTrendData(object? state) |
|
|
|
private void WriteHeartBeat() |
|
|
|
{ |
|
|
|
if (comm.IsConnected()) |
|
|
|
Task.Factory.StartNew( async() => |
|
|
|
{ |
|
|
|
comm.Read<float[]>("DB1.DBD2006", 10).OnSuccess(s => |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
//Data[FeedbackData.反应釜温度] = s.Content[0]; |
|
|
|
//Data[FeedbackData.反应釜蒸汽压力] = s.Content[1]; |
|
|
|
//Data[FeedbackData.反应釜蒸汽流量] = s.Content[2]; |
|
|
|
//Data[FeedbackData.冷凝水罐温度] = s.Content[3]; |
|
|
|
//Data[FeedbackData.冷凝水罐湿度] = s.Content[4]; |
|
|
|
//Data[FeedbackData.负压流量] = s.Content[5]; |
|
|
|
//Data[FeedbackData.称重水罐重量] = s.Content[6]; |
|
|
|
//Data[FeedbackData.反应釜编码器值] = s.Content[7]; |
|
|
|
//Data[FeedbackData.蒸汽比例阀实际开度] = s.Content[8]; |
|
|
|
DeviceStatus.ReactTemp = s.Content[0]; |
|
|
|
DeviceStatus.ReactSteamPressure = s.Content[1]; |
|
|
|
DeviceStatus.ReactSteamFlow = s.Content[2]; |
|
|
|
DeviceStatus.ColdWaterTankTemp = s.Content[3]; |
|
|
|
DeviceStatus.ColdWaterTankHumidity = s.Content[4]; |
|
|
|
DeviceStatus.VacuumFlow = s.Content[5]; |
|
|
|
DeviceStatus.WaterTankWeight = s.Content[6]; |
|
|
|
DeviceStatus.ReactEncoderValue = s.Content[7]; |
|
|
|
DeviceStatus.SteamProportValveRealOpening = s.Content[8]; |
|
|
|
DeviceStatus.BrineTankWeight = s.Content[9]; |
|
|
|
|
|
|
|
|
|
|
|
SamplingData sampling = new SamplingData() |
|
|
|
if (this.IsConnect) |
|
|
|
{ |
|
|
|
Temperature = s.Content[0], |
|
|
|
SteamPressure = s.Content[1], |
|
|
|
SteamFlowRate = s.Content[2], |
|
|
|
CondensateWaterTemperature = s.Content[3], |
|
|
|
CondensateWaterHumidity = s.Content[4], |
|
|
|
NegativePressureFlowRate = s.Content[5], |
|
|
|
WeighingWaterTankWeight = s.Content[6], |
|
|
|
ReactEncoderValue = s.Content[7], |
|
|
|
ProportionalValveOpening = s.Content[8], |
|
|
|
BrineTankWeight = s.Content[9] |
|
|
|
}; |
|
|
|
SqliteOperate.GetInstance.Add(sampling); |
|
|
|
SqliteOperate.GetInstance.RealtimeChart(sampling); |
|
|
|
//var tokenSource = new CancellationTokenSource(); |
|
|
|
//tokenSource.CancelAfter(2000); |
|
|
|
//await WriteAsync(BoolAddEnum.心跳, true,tokenSource.Token); |
|
|
|
Write(BoolAddEnum.心跳, true); |
|
|
|
} |
|
|
|
//IsConnectChanged?.Invoke(this.IsConnect); |
|
|
|
await Task.Delay(2500); |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
},TaskCreationOptions.LongRunning); |
|
|
|
|
|
|
|
} |
|
|
|
public OperateResult Write(BoolAddEnum add, bool value) |
|
|
|
{ |
|
|
@@ -248,5 +192,29 @@ namespace BPASmartClient.Academy._50L |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<OperateResult> WriteAsync(BoolAddEnum add, bool value,CancellationToken cancellationToken=default) |
|
|
|
{ |
|
|
|
if (boolAdds.ContainsKey(add)) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
var result = await Task.Run(() => |
|
|
|
{ |
|
|
|
return comm.Write(boolAdds[add], value); |
|
|
|
}, cancellationToken); |
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
catch (OperationCanceledException) |
|
|
|
{ |
|
|
|
return OperateResult.Failed($"操作被取消"); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
return OperateResult.Failed($"未查找到该地址{add.ToString()}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |