222 lines
8.2 KiB
C#
222 lines
8.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Windows.Media;
|
|
using Logic.ProductionToProductMapper.Cordonel;
|
|
using ProductionUiCordonelLegacy.Data;
|
|
using Xylem.Common.CommonCore.Configuration;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.WaterMeterCore.Consts;
|
|
using Xylem.Common.Logic.SoftwareAccessHelper;
|
|
|
|
namespace ProductionUiCordonelLegacy.Model
|
|
{
|
|
public class PickingViewModel : INotifyPropertyChanged
|
|
{
|
|
public event EventHandler OnDataChanged;
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
|
|
|
private GenesisMeter currentMeter;
|
|
private PickingCompareItem baseFile;
|
|
|
|
public ObservableCollection<IPickingResultData> Data { get; set; }
|
|
|
|
private OverallStatus status = OverallStatus.NoDetect;
|
|
private OverallStatus Status
|
|
{
|
|
get => status;
|
|
set
|
|
{
|
|
status = value;
|
|
OnDataChanged?.Invoke(value.GetHashCode(), EventArgs.Empty);
|
|
|
|
}
|
|
}
|
|
|
|
private enum OverallStatus
|
|
{
|
|
NoDetect,
|
|
CheckingIsRunning,
|
|
CheckingIsDone,
|
|
CheckingIsNoMatch,
|
|
CheckingIsHasError,
|
|
}
|
|
public String StatusText
|
|
{
|
|
get
|
|
{
|
|
switch (Status)
|
|
{
|
|
case OverallStatus.NoDetect:
|
|
return "Wait for meter";
|
|
case OverallStatus.CheckingIsRunning:
|
|
return "Is checking, please wait";
|
|
case OverallStatus.CheckingIsDone:
|
|
return "Succsesfull check next Pcb";
|
|
case OverallStatus.CheckingIsNoMatch:
|
|
return "Check has mismatch, this PCB cannot be used!";
|
|
default:
|
|
return "Check has errors, this PCB cannot be used!";
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public Brush StatusColor
|
|
{
|
|
get
|
|
{
|
|
switch (Status)
|
|
{
|
|
case OverallStatus.NoDetect:
|
|
return (SolidColorBrush)new BrushConverter().ConvertFromString("White");
|
|
case OverallStatus.CheckingIsRunning:
|
|
return (SolidColorBrush)new BrushConverter().ConvertFromString("Yellow");
|
|
case OverallStatus.CheckingIsDone:
|
|
return (SolidColorBrush)new BrushConverter().ConvertFromString("Green");
|
|
case OverallStatus.CheckingIsNoMatch:
|
|
return (SolidColorBrush)new BrushConverter().ConvertFromString("Red");
|
|
default:
|
|
return (SolidColorBrush)new BrushConverter().ConvertFromString("DarkRed");
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void Init(GenesisMeter meter, Dictionary<UInt32, UInt32> checkAppsIdVersion, UInt32 Frequency, UInt32 MeterSize, Boolean PressurePresent)
|
|
{
|
|
|
|
|
|
currentMeter = meter;
|
|
var data = new List<IPickingResultData>();
|
|
|
|
data.Add(new PickingResultCustomCheckData(delegate
|
|
{
|
|
|
|
var r = meter.Login();
|
|
meter.SetProcessState(DisplayCodes.PickingStarted);
|
|
return new PickingItemCheckReturn { Result = true, Msg = "done" };
|
|
|
|
})
|
|
{ Index = data.Count, Ident = "Login", CheckText = "Try to access Meter", HasError = false, Result = null, CurrentValueText = "-" });
|
|
if (Frequency != 0)
|
|
{
|
|
data.Add(new PickingResultRegisterData { ReadMeter = meter, Index = data.Count, Ident = "Check Radio", CheckText = "433", CompareObject = Frequency, CurrentValueText = "none", HasError = false, Result = null, RegisterIdent = "SENSUSRADIO_FrequencyIndicator" }); ;
|
|
|
|
|
|
data.Add(new PickingResultRegisterData { ReadMeter = meter, Index = data.Count, Ident = "MeterSize", CheckText = "DN40-50", CompareObject = MeterSize, CurrentValueText = "none", HasError = false, Result = null, RegisterIdent = "GENESISFLOW_MeterSize" });
|
|
}
|
|
|
|
foreach (var item in checkAppsIdVersion)
|
|
{
|
|
data.Add(new PickingResultCustomCheckData(delegate
|
|
{
|
|
try
|
|
{
|
|
var MeterFWApp = meter.MeterAppListVersion.First(a => item.Key == a.AppId);
|
|
if (MeterFWApp == null || MeterFWApp.Version != item.Value)
|
|
{
|
|
return new PickingItemCheckReturn { Result = false, Msg = MeterFWApp.StrVersion };
|
|
}
|
|
return new PickingItemCheckReturn { Result = true, Msg = MeterFWApp.StrVersion };
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new PickingItemCheckReturn { Result = false, Msg = "error" };
|
|
}
|
|
|
|
})
|
|
{ Index = data.Count, Ident = $"Check AppId {item.Key}", CheckText = $"Version {item.Value}", HasError = false, Result = null, CurrentValueText = "-" }); ;
|
|
|
|
}
|
|
|
|
data.Add(new PickingResultCustomCheckData(delegate
|
|
{
|
|
try
|
|
{
|
|
meter.WriteRegister("METROLOGYASST_StoreConfiguration", 1);
|
|
Thread.Sleep(100);
|
|
var storeRet = meter.ReadRegister("METROLOGYASST_StoreConfiguration");
|
|
if (storeRet.All(a => a.Equals(0)))
|
|
{
|
|
return new PickingItemCheckReturn { Result = true, Msg = "Filesystem OK" };
|
|
}
|
|
|
|
return new PickingItemCheckReturn { Result = false, Msg = "Filesystem corrupt" };
|
|
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return new PickingItemCheckReturn { Result = false, Msg = "error" };
|
|
}
|
|
|
|
})
|
|
{ Index = data.Count, Ident = "Check Filesystem", CheckText = "Check Filesystem", HasError = false, Result = null, CurrentValueText = "checking" }); ;
|
|
|
|
Status = OverallStatus.CheckingIsRunning;
|
|
ChangeDataData(data);
|
|
}
|
|
private void ChangeDataData(List<IPickingResultData> data)
|
|
{
|
|
Data = new ObservableCollection<IPickingResultData>(data);
|
|
OnDataChanged?.Invoke(Data, EventArgs.Empty);
|
|
}
|
|
|
|
public Boolean Run(String pcbID, String OrderNr)
|
|
{
|
|
var tmpData = Data.ToList();
|
|
foreach (var item in tmpData.Where(a => !a.Result.HasValue).OrderBy(a => a.Index))
|
|
{
|
|
var result = item.Action.Invoke();
|
|
item.Result = result.Result;
|
|
item.CurrentValueText = result.Msg;
|
|
ChangeDataData(tmpData);
|
|
}
|
|
|
|
if (tmpData.All(a => !a.HasError && a.Result.HasValue && a.Result.Value))
|
|
{
|
|
currentMeter.SetProcessState(DisplayCodes.PickingTested);
|
|
var url = $"{ServiceUrls.MeterProcessStateUrl()}SetPickingState?PcbID={pcbID}&FertigungsauftragsNr={OrderNr}";
|
|
var RetString = LocalWebRequest.PostRequestAsyncAndGetContent(url);
|
|
|
|
var result = false;
|
|
if (bool.TryParse(RetString, out result))
|
|
{
|
|
Status = OverallStatus.CheckingIsDone;
|
|
return result;
|
|
|
|
}
|
|
|
|
Status = OverallStatus.CheckingIsHasError;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
currentMeter.SetProcessState(DisplayCodes.PickingFailed);
|
|
if (tmpData.All(a => a.HasError))
|
|
{
|
|
Status = OverallStatus.CheckingIsHasError;
|
|
}
|
|
else
|
|
{
|
|
Status = OverallStatus.CheckingIsNoMatch;
|
|
}
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
internal void Empty()
|
|
{
|
|
Status = OverallStatus.NoDetect;
|
|
ChangeDataData(new List<IPickingResultData>());
|
|
}
|
|
}
|
|
}
|