133 lines
4.6 KiB
C#
133 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using Newtonsoft.Json;
|
|
using ProductionUiCordonelLegacy.ProductionProcesses.Enum;
|
|
using ProductionUiCordonelLegacy.UserControls.FinalTest;
|
|
using Xylem.Common.CommonCore.Configuration;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Registers;
|
|
using Xylem.Common.Logic.ProductionOrderCore;
|
|
using Xylem.Common.Logic.SoftwareAccessHelper;
|
|
|
|
namespace ProductionUiCordonelLegacy.ProductionProcesses.Actions
|
|
{
|
|
public class ProductionProcessConnect : BaseProductionProcess
|
|
{
|
|
public Task<IList<ProgrammingParameters>> asyncProgrammingParametersTask;
|
|
private UcPlain UserControl;
|
|
public ProductionProcessConnect(GenesisMeter meter)
|
|
{
|
|
Meter = meter;
|
|
name = "Connect";
|
|
currentProcessState = ProductionProcessState.Waiting;
|
|
}
|
|
public override void InitUserControl()
|
|
{
|
|
UserControl = new UcPlain
|
|
{
|
|
lblHl =
|
|
{
|
|
Content = name
|
|
},
|
|
lblText =
|
|
{
|
|
Content = ""
|
|
}
|
|
};
|
|
}
|
|
|
|
public override UserControl GetControl()
|
|
{
|
|
if (UserControl == null)
|
|
{
|
|
throw new Exception($"UserControl {GetType()} not Ready");
|
|
}
|
|
return UserControl;
|
|
}
|
|
|
|
|
|
public override void ProcessDone()
|
|
{
|
|
//clear
|
|
}
|
|
|
|
public override void StartProcess()
|
|
{
|
|
NewStatus("Prüfe Verbindung");
|
|
Progress = 0;
|
|
if (!Meter.IsLoggedOn)
|
|
{
|
|
NewStatus("Login wird gestartet");
|
|
if (!Meter.Login())
|
|
{
|
|
|
|
|
|
var url = ServiceUrls.GenesisGetPasswordContainerServiceUrl();
|
|
|
|
var requestResponse = LocalWebRequest.GetRequestWithError(url + Meter.PcbId, out var errorCode, 30000, isRetry: true);
|
|
if (errorCode == System.Net.HttpStatusCode.OK.GetHashCode())
|
|
{
|
|
var passwordContainer = JsonConvert.DeserializeObject<Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd.MeterPwdDb>(requestResponse);
|
|
if (System.Text.Encoding.UTF8.GetString(passwordContainer.ListOfPasswords[7]) != passwordContainer.Password)
|
|
{
|
|
if (Meter.Login(System.Text.Encoding.UTF8.GetString(passwordContainer.ListOfPasswords[7])))
|
|
{
|
|
Xylem.Common.Hardware.WaterMeter.Genesis.GenesisPwd.MeterPwdHandlerDb.SetPwdFromSkeletonToLvl8inDd(Meter.PcbId, passwordContainer);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
if (!Meter.IsLoggedOn)
|
|
{
|
|
NewStatus("Connect nicht möglich");
|
|
currentProcessState = ProductionProcessState.Error;
|
|
return;
|
|
}
|
|
Meter.WriteRegister(Register.Genesisflow.SampleRate, 2);
|
|
Meter.WriteRegister(Register.Genesisflow.LedMode, 0);
|
|
|
|
//Check access in
|
|
Progress = 50;
|
|
NewStatus("Zugang wird überprüft");
|
|
//var res = base.Meter.ReadRegister(Register.Genesisflow.LedMode);
|
|
//if (res != null && res.Length > 0)
|
|
//{
|
|
Progress = 100;
|
|
NewStatus("Zugang verifiziert");
|
|
currentProcessState = ProductionProcessState.Done;
|
|
//RadioFrequencyMhz
|
|
asyncProgrammingParametersTask = new Task<IList<ProgrammingParameters>>(() =>
|
|
{
|
|
try
|
|
{
|
|
//var url = $"http://localhost:56011/api/FinalCheck/GetProgrammingParameters?PcbID={base.Meter.PcbId}";
|
|
var url = $"{ServiceUrls.GenesisFinalCheckServiceUrl()}GetProgrammingParameters?PcbID={base.Meter.PcbId}";
|
|
var csdRet = LocalWebRequest.GetRequest(url, 80000);
|
|
|
|
|
|
return JsonConvert.DeserializeObject<IList<ProgrammingParameters>>(csdRet);
|
|
|
|
}
|
|
catch (Exception ec)
|
|
{
|
|
return new List<ProgrammingParameters>
|
|
{
|
|
Capacity = 0
|
|
};
|
|
}
|
|
|
|
|
|
});
|
|
|
|
asyncProgrammingParametersTask.Start();
|
|
|
|
}
|
|
}
|
|
}
|