读写代码

1023
nodyang@aliyun.com 2 weeks ago
parent b746a60ba9
commit 37f97831a1

@ -28,6 +28,9 @@ namespace RfidWeb
public FormMain()
{
DbInfo.Init(typeof(UserInfo).Assembly);
var rfidSetting = RfidSetting.Current;
InitializeComponent();
//if (this.FormBorderStyle == FormBorderStyle.None)
//{

@ -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);

@ -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;
}
}
}

@ -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;
}
}
}

@ -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]")
{
}
}
}

@ -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; }
}
}

@ -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;
}
}

@ -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;

@ -63,8 +63,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="DataTypeEnum.cs" />
<Compile Include="HmiHelp.cs" />
<Compile Include="HttpUtil.cs" />
<Compile Include="ILogNetFactory.cs" />
<Compile Include="Model\BoolModelFactory.cs" />
<Compile Include="Model\HmiChModel.cs" />
<Compile Include="Model\PlcBoolModel.cs" />
<Compile Include="PagedList.cs" />
<Compile Include="Result.cs" />
<Compile Include="RfidSetting.cs" />

Loading…
Cancel
Save