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; } public PlcBoolModel GetDb() { return Reload(); } public UInt32 GetA(PlcBoolModel model) { return GetValue(model, "A"); } public UInt32 GetB(PlcBoolModel model) { 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; } } }