|
|
@@ -54,9 +54,59 @@ public partial class ViewCViewModel : ObservableObject
|
|
|
UpdateTexts();
|
|
|
_lang.LanguageChanged += UpdateTexts;
|
|
|
InitializeChart();
|
|
|
+
|
|
|
+ // 璁㈤槄 PLC 杞鏁版嵁
|
|
|
+ PlcPollingService.Instance.DataUpdated += OnDataUpdated;
|
|
|
+
|
|
|
_ = LoadFlowRecordsAsync();
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// PLC 鏁版嵁鏇存柊鍥炶皟 - 璁板綍娴侀噺鏁版嵁
|
|
|
+ /// </summary>
|
|
|
+ private void OnDataUpdated(PlcDataModel data)
|
|
|
+ {
|
|
|
+ // 灏嗗綋鍓嶆祦閲忔暟鎹坊鍔犲埌鍥捐〃
|
|
|
+ AddDataPoint(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void AddDataPoint(PlcDataModel data)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var now = DateTime.Now;
|
|
|
+
|
|
|
+ // 鏇存柊杩涙按娴侀噺鍥捐〃
|
|
|
+ if (InflowSeries?.Length > 0 && InflowSeries[0] is ColumnSeries<DateTimePoint> inflowSeries)
|
|
|
+ {
|
|
|
+ var values = inflowSeries.Values?.ToList() ?? new List<DateTimePoint>();
|
|
|
+ values.Add(new DateTimePoint(now, data.InflowRate));
|
|
|
+
|
|
|
+ // 淇濈暀鏈杩 60 涓暟鎹偣
|
|
|
+ if (values.Count > 60)
|
|
|
+ values.RemoveAt(0);
|
|
|
+
|
|
|
+ inflowSeries.Values = values.ToArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 鏇存柊鍑烘按娴侀噺鍥捐〃
|
|
|
+ if (OutflowSeries?.Length > 0 && OutflowSeries[0] is ColumnSeries<DateTimePoint> outflowSeries)
|
|
|
+ {
|
|
|
+ var values = outflowSeries.Values?.ToList() ?? new List<DateTimePoint>();
|
|
|
+ values.Add(new DateTimePoint(now, data.OutflowRate));
|
|
|
+
|
|
|
+ if (values.Count > 60)
|
|
|
+ values.RemoveAt(0);
|
|
|
+
|
|
|
+ outflowSeries.Values = values.ToArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ Log.Error(ex, "鏇存柊鍥捐〃鏁版嵁澶辫触");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void UpdateTexts()
|
|
|
{
|
|
|
TitleText = _lang.Get("FlowRecords");
|