添加项目文件。

This commit is contained in:
liming 蔡
2026-07-14 13:55:17 +08:00
parent 63759495f2
commit 8bbdf78731
335 changed files with 81415 additions and 0 deletions
+103
View File
@@ -0,0 +1,103 @@
using HslCommunication;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PLCCommunication
{
public class DemoUtils
{
public static readonly string IpAddressInputWrong = "IpAddress input wrong";
public static readonly string PortInputWrong = "Port input wrong";
public static readonly string SlotInputWrong = "Slot input wrong";
public static readonly string BaudRateInputWrong = "Baud rate input wrong";
public static readonly string DataBitsInputWrong = "Data bit input wrong";
public static readonly string StopBitInputWrong = "Stop bit input wrong";
public static void ReadResultRender<T>(OperateResult<T> result, string address, TextBox textBox)
{
if (result.IsSuccess)
{
textBox.AppendText(DateTime.Now.ToString("[HH:mm:ss] ") + $"[{address}] {result.Content}{Environment.NewLine}");
return;
}
MessageBox.Show(DateTime.Now.ToString("[HH:mm:ss] ") + "[" + address + "] Read Failed " + Environment.NewLine + "Reason:" + result.ToMessageShowString());
}
public static void ReadResultRender<T>(OperateResult<T[]> result, string address, TextBox textBox)
{
string resTemp = string.Empty;
if (result.IsSuccess)
{
for (int i = 0; i < result.Content.Length; i++)
{
resTemp = string.Concat(resTemp, result.Content[i], ",");
}
string Result = resTemp.Substring(0, resTemp.Length - 1);
textBox.AppendText(DateTime.Now.ToString("[HH:mm:ss] ") + "[" + address + "] " + Result + Environment.NewLine);
}
else
{
MessageBox.Show(DateTime.Now.ToString("[HH:mm:ss] ") + "[" + address + "] Read Failed " + Environment.NewLine + "Reason:" + result.ToMessageShowString());
}
}
public static void WriteResultRender(OperateResult result, string address)
{
if (result.IsSuccess)
{
MessageBox.Show(DateTime.Now.ToString("[HH:mm:ss] ") + "[" + address + "] Write Success");
return;
}
MessageBox.Show(DateTime.Now.ToString("[HH:mm:ss] ") + "[" + address + "] Write Failed " + Environment.NewLine + " Reason:" + result.ToMessageShowString());
}
public static void WriteResultRender(Func<OperateResult> write, string address)
{
try
{
OperateResult result = write();
if (result.IsSuccess)
{
MessageBox.Show(DateTime.Now.ToString("[HH:mm:ss] ") + "[" + address + "] Write Success");
return;
}
MessageBox.Show(DateTime.Now.ToString("[HH:mm:ss] ") + "[" + address + "] Write Failed " + Environment.NewLine + " Reason:" + result.ToMessageShowString());
}
catch (Exception ex)
{
MessageBox.Show("Data for writting is not corrent: " + ex.Message);
}
}
public static void BulkReadRenderResult(IReadWriteNet readWrite, TextBox addTextBox, TextBox lengthTextBox, TextBox resultTextBox)
{
try
{
OperateResult<byte[]> read = readWrite.Read(addTextBox.Text, ushort.Parse(lengthTextBox.Text));
if (read.IsSuccess)
{
resultTextBox.Text = "Result:" + SoftBasic.ByteToHexString(read.Content);
}
else
{
MessageBox.Show("Read Failed:" + read.ToMessageShowString());
}
}
catch (Exception ex)
{
MessageBox.Show("Read Failed:" + ex.Message);
}
}
}
}
+60
View File
@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace PLCCommunication
{
public class IniHelper
{
public string path;
public IniHelper(string INIPath)
{
path = INIPath;
}
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
[DllImport("kernel32", CharSet = CharSet.Unicode)]
private static extern int GetPrivateProfileString(string section, string key, string defVal, byte[] retVal, int size, string filePath);
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, path);
}
public string IniReadValue(string Section, string Key)
{
try
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, path);
return temp.ToString();
}
catch (Exception)
{
return null;
}
}
public byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, path);
return temp;
}
public void ClearAllSection()
{
IniWriteValue(null, null, null);
}
public void ClearSection(string Section)
{
IniWriteValue(Section, null, null);
}
}
}