diff --git a/RfidWeb/FormMain.cs b/RfidWeb/FormMain.cs index bb97759..8a81ef3 100644 --- a/RfidWeb/FormMain.cs +++ b/RfidWeb/FormMain.cs @@ -28,6 +28,9 @@ namespace RfidWeb public FormMain() { DbInfo.Init(typeof(UserInfo).Assembly); + + var rfidSetting = RfidSetting.Current; + InitializeComponent(); //if (this.FormBorderStyle == FormBorderStyle.None) //{ diff --git a/RfidWeb/FromSQl.cs b/RfidWeb/FromSQl.cs index b0b1204..d14cf32 100644 --- a/RfidWeb/FromSQl.cs +++ b/RfidWeb/FromSQl.cs @@ -23,8 +23,7 @@ namespace RfidWeb { //DbInfo.Init(typeof(RoleMapper).Assembly); DbInfo.Init(typeof(UserInfo).Assembly); - - + var rfidSetting = RfidSetting.Current; var dbContext = DbFactory.GetContext; new PostgreSQLTableGenerator(dbContext).CreateTables(TableCreateMode.CreateIfNotExists); diff --git a/Tool/HmiHelp.cs b/Tool/HmiHelp.cs new file mode 100644 index 0000000..1e5e2fe --- /dev/null +++ b/Tool/HmiHelp.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tool +{ + public class HmiHelp + { + + public static uint BitsToUint32(bool[] bits) + { + if (bits.Length > 32) + throw new ArgumentException("Bits array length must not exceed 32."); + + uint result = 0; + for (int i = 0; i < bits.Length; i++) + { + // 如果当前位是 true,则设置对应位置的位 + if (bits[i]) + { + result |= (uint)(1 << i); // 注意这里的位序是从最低位到最高位 + } + } + + return result; + } + + + public static uint ConvertBitsToUInt32(bool[] bits) + { + if (bits.Length != 32) + { + throw new ArgumentException("比特数组必须恰好包含 32 个比特"); + } + + uint result = 0; + + // 遍历比特数组,将每个比特转换为相应的位,并设置到 uint32 中 + for (int i = 0; i < 32; i++) + { + if (bits[i]) + { + result |= (uint)(1 << (31 - i)); // 设置对应位置的比特为 1 + } + } + + return result; + } + } +} diff --git a/Tool/Model/BoolModelFactory.cs b/Tool/Model/BoolModelFactory.cs new file mode 100644 index 0000000..2468253 --- /dev/null +++ b/Tool/Model/BoolModelFactory.cs @@ -0,0 +1,92 @@ +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; + } + } +} diff --git a/Tool/Model/HmiChModel.cs b/Tool/Model/HmiChModel.cs new file mode 100644 index 0000000..f210c4d --- /dev/null +++ b/Tool/Model/HmiChModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HslCommunication; + +namespace Tool.Model +{ + public class HmiChModel : BoolModelFactory + { + public HmiChModel() : base("HMI_button_CH_ON[0]", "HMI_button_CH_ON[1]") + { + } + } + + + public class HmiCqModel : BoolModelFactory + { + public HmiCqModel() : base("HMI_button_CQ_ON[0]", "HMI_button_CQ_ON[1]") + { + } + } + + public class HmiLpModel : BoolModelFactory + { + public HmiLpModel() : base("HMI_button_LP_ON[0]", "HMI_button_LP_ON[1]") + { + } + } +} diff --git a/Tool/Model/PlcBoolModel.cs b/Tool/Model/PlcBoolModel.cs new file mode 100644 index 0000000..b1e6438 --- /dev/null +++ b/Tool/Model/PlcBoolModel.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tool.Model +{ + public class PlcBoolModel + { + public bool A0 { get; set; } + public bool A1 { get; set; } + public bool A2 { get; set; } + public bool A3 { get; set; } + public bool A4 { get; set; } + public bool A5 { get; set; } + public bool A6 { get; set; } + public bool A7 { get; set; } + public bool A8 { get; set; } + public bool A9 { get; set; } + public bool A10 { get; set; } + public bool A11 { get; set; } + public bool A12 { get; set; } + public bool A13 { get; set; } + public bool A14 { get; set; } + public bool A15 { get; set; } + + + public bool A16 { get; set; } + public bool A17 { get; set; } + public bool A18 { get; set; } + public bool A19 { get; set; } + public bool A20 { get; set; } + public bool A21 { get; set; } + public bool A22 { get; set; } + + public bool A23 { get; set; } + public bool A24 { get; set; } + public bool A25 { get; set; } + public bool A26 { get; set; } + public bool A27 { get; set; } + public bool A28 { get; set; } + public bool A29 { get; set; } + + public bool A30 { get; set; } + + + + + public bool B0 { get; set; } + public bool B1 { get; set; } + public bool B2 { get; set; } + public bool B3 { get; set; } + public bool B4 { get; set; } + public bool B5 { get; set; } + public bool B6 { get; set; } + public bool B7 { get; set; } + public bool B8 { get; set; } + public bool B9 { get; set; } + public bool B10 { get; set; } + public bool B11 { get; set; } + public bool B12 { get; set; } + public bool B13 { get; set; } + public bool B14 { get; set; } + public bool B15 { get; set; } + + + public bool B16 { get; set; } + public bool B17 { get; set; } + public bool B18 { get; set; } + public bool B19 { get; set; } + public bool B20 { get; set; } + public bool B21 { get; set; } + public bool B22 { get; set; } + + public bool B23 { get; set; } + public bool B24 { get; set; } + public bool B25 { get; set; } + public bool B26 { get; set; } + public bool B27 { get; set; } + public bool B28 { get; set; } + public bool B29 { get; set; } + + public bool B30 { get; set; } + + } +} diff --git a/Tool/PlcConnect.cs b/Tool/PlcConnect.cs index 7374cbb..34c37fb 100644 --- a/Tool/PlcConnect.cs +++ b/Tool/PlcConnect.cs @@ -5,6 +5,7 @@ using HslCommunication; using HslCommunication.LogNet; using HslCommunication.Profinet.AllenBradley; using HslCommunication.Profinet.Siemens; +using NewLife; using Newtonsoft.Json; namespace Tool @@ -102,6 +103,15 @@ namespace Tool + + public static OperateResult WriteTag(string address, UInt32 num) + { + OperateResult operate = Instance.WriteTag(address, 0xC4, num.GetBytes()); + logNet.WriteInfo("打印日志", $"write 地址[{address}] value:[{num.ToString()}] type:[Tag] result:[{result.ToJsonString()}]"); + + return operate; + } + } diff --git a/Tool/RfidSetting.cs b/Tool/RfidSetting.cs index fe725aa..268a37a 100644 --- a/Tool/RfidSetting.cs +++ b/Tool/RfidSetting.cs @@ -16,7 +16,7 @@ namespace Tool public string Db { get; set; } = "server=127.0.0.1;database=gaosu;uid=postgres;pwd=123456"; - public string PlcIp { get; set; } = "192.168.1.100"; + public string PlcIp { get; set; } = "192.168.1.140"; public int Port { get; set; }=44818; diff --git a/Tool/Tool.csproj b/Tool/Tool.csproj index 538014d..c54db9f 100644 --- a/Tool/Tool.csproj +++ b/Tool/Tool.csproj @@ -63,8 +63,12 @@ + + + +