You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lj_plc/Actions/ChemicalWeighing/Mesnac.Action.ChemicalWeighing/LjDeliver/DeliverInitAction.cs

106 lines
3.1 KiB
C#

using DevExpress.Data.Filtering.Helpers;
using Mesnac.Action.Base;
using Mesnac.Action.ChemicalWeighing.LjDeliver.Entity;
using Mesnac.Controls.ChemicalWeighing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesnac.Action.ChemicalWeighing.LjDeliver
{
public class DeliverInitAction : ChemicalWeighingAction, IAction
{
List<Control> Controls;
HslBottleEntity bottleE = new HslBottleEntity();
public void Run(RuntimeParameter runtime)
{
base.RunIni(runtime); //必须调用
Controls = GetAllControls();
ControlsHelper.ControlImport<HslBottle>(bottleE, Controls);
wangsr();
}
private void wangsr()
{
Random rd = new Random();
bool[] bottleFlag = new bool[15];
for (int i = 0; i < bottleFlag.Length; i++)
{
bottleFlag[i] = Convert.ToBoolean(rd.Next(0, 2));
}
Type bottleType = bottleE.GetType();
PropertyInfo[] properties = bottleType.GetProperties();
ThreadStart threadStart = new ThreadStart(() =>
{
double n = 100 / 15;
int i = 0;
foreach (PropertyInfo sourceProperty in properties)
{
string name = sourceProperty.Name;
PropertyInfo property = bottleType.GetProperty(name);
HslBottle bottle = (HslBottle)property.GetValue(bottleE);
//bottle.Value = n * i++;
bottle.Value = rd.Next(100);
property.SetValue(bottleE, bottle);
}
int num;
while (Application.OpenForms["LjDeliver"] != null)
{
num = 0;
foreach (PropertyInfo sourceProperty in properties)
{
string name = sourceProperty.Name;
PropertyInfo property = bottleType.GetProperty(name);
HslBottle bottle = (HslBottle)property.GetValue(bottleE);
if (bottle.Value <= 0.2)
{
bottleFlag[num] = true;
}
if (bottle.Value >= 99.8)
{
bottleFlag[num] = false;
}
if (bottleFlag[num])
{
bottle.Value += 0.2;
}
else
{
bottle.Value -= 0.2;
}
property.SetValue(bottleE, bottle);
num++;
}
Thread.Sleep(1);
}
});
Thread thread = new Thread(threadStart);
thread.Start();
}
}
}