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.
CaiQie/Tool/Model/BoolModelFactory.cs

93 lines
2.0 KiB
C#

2 weeks ago
using HslCommunication;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NewLife.Reflection;
namespace Tool.Model
{
public class BoolModelFactory
{
private string a = "";
private string b = "";
public BoolModelFactory(string a, string b)
{
this.a = a;
this.b = b;
}
2 weeks ago
public PlcBoolModel GetPlcDb()
2 weeks ago
{
return Reload();
}
2 weeks ago
public UInt32 SetA(PlcBoolModel model)
2 weeks ago
{
return GetValue(model, "A");
}
2 weeks ago
public UInt32 SetB(PlcBoolModel model)
2 weeks ago
{
return GetValue(model,"B");
}
private UInt32 GetValue(PlcBoolModel model, string val)
{
bool[] bitArray = new bool[32];
for (int i = 0; i < 31; i++)
{
var value = model.GetValue(val + i);
bitArray[i] = Convert.ToBoolean(value);
}
Array.Reverse(bitArray);
return HmiHelp.ConvertBitsToUInt32(bitArray);
}
public PlcBoolModel Reload()
{
PlcBoolModel BoolModel = new PlcBoolModel();
var readUInt32 = PlcConnect.Instance.ReadUInt32(a);
var bo = readUInt32.IsSuccess;
var context = readUInt32.Content;
if (bo)
{
for (int i = 0; i < 31; i++)
{
BoolModel.SetValue("A" + i, context.GetBoolByIndex(i));
}
}
readUInt32 = PlcConnect.Instance.ReadUInt32(b);
bo = readUInt32.IsSuccess;
context = readUInt32.Content;
if (bo)
{
for (int i = 0; i < 31; i++)
{
BoolModel.SetValue("B" + i, context.GetBoolByIndex(i));
}
}
return BoolModel;
}
}
}