115 lines
3.4 KiB
C#
115 lines
3.4 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Xylem.Common.CommonCore.Consts;
|
|
using Xylem.Common.Hardware.Interfaces.Ports.PortCore;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisConfig;
|
|
|
|
namespace Xylem.Common.Ui.GenesisToolBox
|
|
{
|
|
public partial class FrmMultiUpdate : Form
|
|
{
|
|
public FrmMultiUpdate()
|
|
{
|
|
InitializeComponent();
|
|
var configfile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), nameof(Xylem.Common.Hardware.WaterMeter.Genesis), ProgramConfig.SerialConfigFileName);
|
|
|
|
if (!File.Exists(configfile))
|
|
{
|
|
throw new ApplicationException($"Configuration file {configfile} not found ");
|
|
}
|
|
var tr = new StreamReader(configfile);
|
|
var meterConfigList = JsonConvert.DeserializeObject<SlotConfig[]>(tr.ReadToEnd());
|
|
clbMeters.Items.Clear();
|
|
var listSlots = new List<Int32>();
|
|
foreach (var item in meterConfigList)
|
|
{
|
|
clbMeters.Items.Add(item.Slot);
|
|
listSlots.Add(item.Slot);
|
|
}
|
|
|
|
}
|
|
|
|
private void FrmMultiUpdate_Load(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnStart_Click(Object sender, EventArgs e)
|
|
{
|
|
IEnumerable<Object> notChecked = (from Object item in clbMeters.Items
|
|
where clbMeters.CheckedItems.Contains(item)
|
|
select item);
|
|
var reps = (Int32)nudRep.Value;
|
|
foreach (Object item in notChecked)
|
|
{
|
|
if (item is Int32 SlotNR)
|
|
{
|
|
RunTest(SlotNR, reps, txtUpBin.Text, txtUpInfo.Text, txtDownBin.Text, txtDownInfo.Text);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void RunTest(Int32 slot, Int32 rep,String UPBin,String UpInfo, String DownBin, String DownInfo, Int32 retry = 4,Int32 wait = 250)
|
|
{
|
|
Boolean up = true;
|
|
|
|
for (Int32 i = 0; i < rep; i++)
|
|
{
|
|
using (var frm = new FrmFwUpdate())
|
|
{
|
|
|
|
frm.Show();
|
|
var result = false;
|
|
frm.LastMsgEvent = null;
|
|
if (up)
|
|
{
|
|
result = frm.Prepare(slot, UPBin, UpInfo);
|
|
}
|
|
else
|
|
{
|
|
|
|
result = frm.Prepare(slot, UPBin, UpInfo);
|
|
}
|
|
|
|
if (result)
|
|
{
|
|
while (frm.LastMsgEvent == null)
|
|
{
|
|
System.Threading.Thread.Sleep(500);
|
|
}
|
|
|
|
switch (frm.LastMsgEvent.Caption)
|
|
{
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (result)
|
|
{
|
|
up = !up;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//cbComSlot
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|