diff --git a/SlnMesnac.Business/SerialBusiness.cs b/SlnMesnac.Business/SerialBusiness.cs
new file mode 100644
index 0000000..b65687f
--- /dev/null
+++ b/SlnMesnac.Business/SerialBusiness.cs
@@ -0,0 +1,134 @@
+using System;
+using System.Collections.Generic;
+using System.IO.Ports;
+using System.Text;
+using System.Threading;
+
+#region << 版 本 注 释 >>
+/*--------------------------------------------------------------------
+* 版权所有 (c) 2025 WenJY 保留所有权利。
+* CLR版本:4.0.30319.42000
+* 机器名称:T14-GEN3-7895
+* 命名空间:SlnMesnac.Business
+* 唯一标识:a0333022-6db6-4dd1-8aa7-bc46b57b6050
+*
+* 创建者:WenJY
+* 电子邮箱:
+* 创建时间:2025-06-23 13:50:07
+* 版本:V1.0.0
+* 描述:
+*
+*--------------------------------------------------------------------
+* 修改人:
+* 时间:
+* 修改说明:
+*
+* 版本:V1.0.0
+*--------------------------------------------------------------------*/
+#endregion << 版 本 注 释 >>
+namespace SlnMesnac.Business
+{
+ public class SerialBusiness
+ {
+ private SerialPort serialPort;
+
+ public SerialBusiness()
+ {
+ serialPort = new SerialPort("COM6", 115200, Parity.None, 8, StopBits.One);
+ //serialPort.DataReceived += SerialPort_DataReceived;
+ }
+
+ private void SerialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
+ {
+ // 数据接收事件处理
+ // 这里可以根据需要处理接收到的数据
+ }
+
+ public void OpenPort()
+ {
+ try
+ {
+ if (!serialPort.IsOpen)
+ {
+ serialPort.Open();
+ }
+ }
+ catch (Exception ex)
+ {
+ Console.WriteLine($"打开串口时出错: {ex.Message}");
+ }
+ }
+
+ public void ClosePort()
+ {
+ if (serialPort.IsOpen)
+ {
+ serialPort.Close();
+ }
+ }
+
+ private byte[] receiveBuffer = new byte[1024];
+ private int bufferIndex = 0;
+
+ public byte[] SendDataAndWaitForResponse(byte[] dataToSend)
+ {
+ if (!serialPort.IsOpen)
+ {
+ throw new InvalidOperationException("串口未打开。");
+ }
+
+ // 清空接收缓冲区
+ serialPort.DiscardInBuffer();
+ bufferIndex = 0;
+
+ byte[] receivedData = new byte[0];
+ AutoResetEvent dataReceivedEvent = new AutoResetEvent(false);
+
+ serialPort.DataReceived += (sender, e) =>
+ {
+ int bytesToRead = serialPort.BytesToRead;
+ serialPort.Read(receiveBuffer, bufferIndex, bytesToRead);
+ bufferIndex += bytesToRead;
+
+
+ if (bufferIndex >= 5)
+ {
+ receivedData = new byte[bufferIndex];
+ Array.Copy(receiveBuffer, receivedData, bufferIndex);
+ dataReceivedEvent.Set();
+ }
+ };
+
+ try
+ {
+ // 发送数据
+ serialPort.Write(dataToSend, 0, dataToSend.Length);
+
+ // 等待数据返回,最多等待 5 秒
+ if (!dataReceivedEvent.WaitOne(5000))
+ {
+ throw new TimeoutException("在 5 秒内未收到响应。");
+ }
+
+ return receivedData;
+ }
+ finally
+ {
+ // 移除事件处理程序
+ serialPort.DataReceived -= (sender, e) =>
+ {
+ int bytesToRead = serialPort.BytesToRead;
+ serialPort.Read(receiveBuffer, bufferIndex, bytesToRead);
+ bufferIndex += bytesToRead;
+
+ if (bufferIndex >= 10)
+ {
+ receivedData = new byte[bufferIndex];
+ Array.Copy(receiveBuffer, receivedData, bufferIndex);
+ dataReceivedEvent.Set();
+ }
+ };
+ }
+ }
+ }
+}
diff --git a/SlnMesnac.Config/RfidConfig.cs b/SlnMesnac.Config/RfidConfig.cs
index 87622ea..3fb6f04 100644
--- a/SlnMesnac.Config/RfidConfig.cs
+++ b/SlnMesnac.Config/RfidConfig.cs
@@ -43,6 +43,11 @@ namespace SlnMesnac.Config
/// 设备 Key
///
public string? equipKey { get; set; }
+
+ ///
+ /// 连接会话
+ ///
+ public object? session { get;set; }
///
/// 是否启用
diff --git a/SlnMesnac.TouchSocket/TouchSocketSetup.cs b/SlnMesnac.TouchSocket/TouchSocketSetup.cs
index 637d77f..9b7549e 100644
--- a/SlnMesnac.TouchSocket/TouchSocketSetup.cs
+++ b/SlnMesnac.TouchSocket/TouchSocketSetup.cs
@@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Text;
using Microsoft.AspNetCore.Builder;
using TouchSocket.Sockets;
+using TouchSocket.Core;
+using SlnMesnac.Config;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
@@ -35,14 +37,11 @@ namespace SlnMesnac.TouchSocket
public static class TouchSocketSetup
{
- public static IApplicationBuilder UseTouchSocketExtensions(this IApplicationBuilder app)
+ public static async void UseTouchSocketExtensions(this IServiceProvider service)
{
- var _server = app.ApplicationServices.GetService();
- _server.Init(20108);
+ var ap = service.GetService();
- var _apiServer = app.ApplicationServices.GetService();
- _apiServer.Init();
- return app;
+
}
}
}
\ No newline at end of file
diff --git a/SlnMesnac.WPF/App.xaml.cs b/SlnMesnac.WPF/App.xaml.cs
index 09d82d0..3eeba18 100644
--- a/SlnMesnac.WPF/App.xaml.cs
+++ b/SlnMesnac.WPF/App.xaml.cs
@@ -7,6 +7,7 @@ using System.Windows;
using Microsoft.Extensions.Configuration;
using SlnMesnac.Extensions;
using SlnMesnac.Serilog;
+using SlnMesnac.TouchSocket;
using System.Reflection;
using TouchSocket.Sockets;
using SlnMesnac.WPF.Attribute;
@@ -14,6 +15,7 @@ using SlnMesnac.WPF.Page.Login;
using Prism.Events;
using SlnMesnac.WPF.Event;
using AduSkin.Controls.Metro;
+using TouchSocket.Core;
namespace SlnMesnac.WPF
{
@@ -58,6 +60,8 @@ namespace SlnMesnac.WPF
// 配置Serilog和其他扩展
ServiceProvider.UseSerilogExtensions();
+ ServiceProvider.UseTouchSocketExtensions();
+
//通知弹窗
NoticeManager.Initialize();
@@ -85,9 +89,33 @@ namespace SlnMesnac.WPF
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
IConfiguration configuration = configurationBuilder.Build();
var ap = configuration.GetSection("AppConfig").Get();
+
+ foreach (var item in ap.rfidConfig)
+ {
+ if (item.isFlage)
+ {
+ TcpClient tcpClient = new TcpClient();
+
+ var hashcode = tcpClient.GetHashCode();
+
+ tcpClient.Setup(new TouchSocketConfig()
+ .SetRemoteIPHost($"{item.equipIp}:{item.equipPort}"));
+
+ tcpClient.Connect();
+
+ Result result = tcpClient.TryConnect();
+ if (result.IsSuccess())
+ {
+ item.session = tcpClient;
+ }
+ var hashcode2 = tcpClient.GetHashCode();
+ }
+ }
+
return ap;
});
+
services.AddSingleton(typeof(SerilogHelper));
Assembly[] assemblies = {
diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml
index 63e83bd..ea0ada2 100644
--- a/SlnMesnac.WPF/MainWindow.xaml
+++ b/SlnMesnac.WPF/MainWindow.xaml
@@ -30,7 +30,7 @@
-
+
@@ -38,8 +38,8 @@
x:Name="Index" Command="{Binding ControlOnClickCommand}" CommandParameter="{Binding Name,ElementName=Index}">
-
-
+
+
@@ -49,8 +49,8 @@
x:Name="Set" Command="{Binding ControlOnClickCommand}" CommandParameter="{Binding Name,ElementName=Set}">
-
-
+
+
diff --git a/SlnMesnac.WPF/MainWindow.xaml.cs b/SlnMesnac.WPF/MainWindow.xaml.cs
index 0e790b5..658fceb 100644
--- a/SlnMesnac.WPF/MainWindow.xaml.cs
+++ b/SlnMesnac.WPF/MainWindow.xaml.cs
@@ -2,6 +2,7 @@
using SlnMesnac.WPF.ViewModel;
using System;
using System.Collections.Generic;
+using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@@ -26,8 +27,13 @@ namespace SlnMesnac.WPF
public MainWindow(MainWindowViewModel mainWindowViewModel)
{
InitializeComponent();
-
+ this.Closing += Application_Closing;
this.DataContext = mainWindowViewModel;
}
+ private void Application_Closing(object sender, CancelEventArgs e)
+ {
+ Application.Current.Shutdown();
+ // 在此处执行退出事件处理逻辑
+ }
}
}
diff --git a/SlnMesnac.WPF/Page/IndexControl.xaml b/SlnMesnac.WPF/Page/IndexControl.xaml
index 8769c88..77e31cc 100644
--- a/SlnMesnac.WPF/Page/IndexControl.xaml
+++ b/SlnMesnac.WPF/Page/IndexControl.xaml
@@ -52,32 +52,32 @@
-->
-
+
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
@@ -85,30 +85,30 @@
-
+
-
-
+
+
-
+
-
+
-
-
+
+
-
-
+
+
-
+
-
-
+
+
@@ -119,7 +119,7 @@
+ Command="{Binding LoadProductInfoCommand}" CommandParameter="C7FE8F01-8F7A-4916-B20F-CB9F3C7E76DF"/>
-
+
@@ -164,7 +164,7 @@
-
+
@@ -187,7 +187,7 @@
-
+
@@ -204,32 +204,37 @@
-->
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
+
+
@@ -250,7 +255,7 @@
-
+
@@ -269,7 +274,7 @@
-
+
diff --git a/SlnMesnac.WPF/Page/ProductDetails/ProductDetailsControl.xaml b/SlnMesnac.WPF/Page/ProductDetails/ProductDetailsControl.xaml
index 416c393..5ef33ba 100644
--- a/SlnMesnac.WPF/Page/ProductDetails/ProductDetailsControl.xaml
+++ b/SlnMesnac.WPF/Page/ProductDetails/ProductDetailsControl.xaml
@@ -30,12 +30,12 @@
-
-
+
+
-
+
-
+
@@ -50,19 +50,19 @@
-
-
-
+
+
+
-
-
+
+
-
+
-
-
+
+
@@ -92,9 +92,9 @@
-
+
-
+
@@ -111,9 +111,9 @@
-
+
-
+
@@ -130,9 +130,9 @@
-
+
-
+
@@ -149,11 +149,29 @@
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -165,7 +183,7 @@
-
+
@@ -183,32 +201,30 @@
-->
-
-
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
-
-
-
-
-
+
+
+
+
+
@@ -222,7 +238,7 @@
-
+
@@ -230,7 +246,7 @@
-
+
@@ -241,7 +257,7 @@
-
+
@@ -249,7 +265,7 @@
-
+
diff --git a/SlnMesnac.WPF/SlnMesnac.WPF.csproj b/SlnMesnac.WPF/SlnMesnac.WPF.csproj
index 8bb157c..5eafbb4 100644
--- a/SlnMesnac.WPF/SlnMesnac.WPF.csproj
+++ b/SlnMesnac.WPF/SlnMesnac.WPF.csproj
@@ -1,16 +1,16 @@
- Exe
+ WinExe
net6.0-windows
enable
true
+ Icon.png
-
@@ -64,4 +64,11 @@
+
+
+ True
+ \
+
+
+
diff --git a/SlnMesnac.WPF/Templates/icon/certification.jpg b/SlnMesnac.WPF/Templates/icon/certification.jpg
new file mode 100644
index 0000000..8c2e634
Binary files /dev/null and b/SlnMesnac.WPF/Templates/icon/certification.jpg differ
diff --git a/SlnMesnac.WPF/ViewModel/Index/IndexViewModel.cs b/SlnMesnac.WPF/ViewModel/Index/IndexViewModel.cs
index e5a676c..bb54ece 100644
--- a/SlnMesnac.WPF/ViewModel/Index/IndexViewModel.cs
+++ b/SlnMesnac.WPF/ViewModel/Index/IndexViewModel.cs
@@ -1,8 +1,12 @@
-using CommunityToolkit.Mvvm.Input;
+using AduSkin.Controls.Metro;
+using AduSkin.Controls;
+using CommunityToolkit.Mvvm.Input;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.VisualBasic;
using NVelocity.Util.Introspection;
using Prism.Events;
+using SlnMesnac.Common;
+using SlnMesnac.Config;
using SlnMesnac.Serilog;
using SlnMesnac.WPF.Attribute;
using SlnMesnac.WPF.Event;
@@ -12,6 +16,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using TouchSocket.Core;
+using TouchSocket.Sockets;
+using CommunityToolkit.Mvvm.ComponentModel;
+using System.Windows.Documents;
+using SlnMesnac.Business;
+using static Microsoft.WindowsAPICodePack.Shell.PropertySystem.SystemProperties.System;
+using System.Windows.Markup;
namespace SlnMesnac.WPF.ViewModel.Index
{
@@ -20,14 +31,44 @@ namespace SlnMesnac.WPF.ViewModel.Index
{
public readonly SerilogHelper _logger;
+ private readonly AppConfig _appConfig;
+
+ private readonly StringChange _stringChange;
+
private readonly IEventAggregator _eventAggregator;
- public IndexViewModel(SerilogHelper logger, IEventAggregator eventAggregator)
+ private readonly SerialBusiness _serialBusiness;
+
+ public IndexViewModel(SerilogHelper logger,AppConfig appConfig,StringChange stringChange, IEventAggregator eventAggregator, SerialBusiness serialBusiness)
{
_logger = logger;
+ _appConfig = appConfig;
+ _stringChange = stringChange;
_eventAggregator = eventAggregator;
+ _serialBusiness = serialBusiness;
+
+ _serialBusiness.OpenPort();
+
}
+ [ObservableProperty]
+ private string firstBatchEpcBarcode = string.Empty;
+
+ [ObservableProperty]
+ private string secondBatchEpcBarcode = string.Empty;
+
+ [ObservableProperty]
+ private string thirdBatchEpcBarcode = string.Empty;
+
+ [ObservableProperty]
+ private string fourthBatchEpcBarcode = string.Empty;
+
+ [ObservableProperty]
+ private string fifthBatchEpcBarcode = string.Empty;
+
+ [ObservableProperty]
+ private string sixthBatchEpcBarcode = string.Empty;
+
///
/// 加载产品信息
///
@@ -42,5 +83,393 @@ namespace SlnMesnac.WPF.ViewModel.Index
var mainWindow = App.ServiceProvider.GetService();
mainWindow.ControlOnClick("ProductInfo");
}
+
+ [RelayCommand]
+ private void ReadEpcCode(string deviceCode)
+ {
+ try
+ {
+ string configKey = string.Empty;
+ if (deviceCode == "050-B" || deviceCode == "I68")
+ {
+ configKey = "I68";
+ }
+ else
+ {
+ configKey = deviceCode;
+ }
+ var rfidConfig = _appConfig.rfidConfig.Where(x => x.equipKey == configKey).FirstOrDefault();
+
+ if (rfidConfig != null)
+ {
+ var session = rfidConfig.session as TcpClient;
+
+ if (session != null)
+ {
+ var waitClinet = session.CreateWaitingClient(new WaitingOptions()
+ {
+ FilterFunc = response =>
+ {
+ return true;
+ }
+ });
+
+ byte[] buffer = null;
+
+ if (deviceCode == "I90" || deviceCode == "RFR-RFLY")
+ {
+ buffer = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x03, 0x00, 0x10, 0x00, 0x04 };
+ }
+
+ if (deviceCode == "050-B") //站1
+ {
+ buffer = new byte[] { 0x00, 0x10, 0x00, 0x00, 0x00, 0x06, 0x01, 0x03, 0x00, 0x02, 0x00, 0x04 };
+ }
+
+ if (deviceCode == "I68") //站2
+ {
+ buffer = new byte[] { 0x00, 0x10, 0x00, 0x00, 0x00, 0x06, 0x01, 0x03, 0x00, 0x06, 0x00, 0x04 };
+ }
+
+ ResponsedData responsedData = waitClinet.SendThenResponse(buffer, 5000);
+
+ string str = _stringChange.bytesToHexStr(responsedData.Data, responsedData.Data.Length).Substring(18, 16);
+
+ SetEpcBarCode(deviceCode, str);
+
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备读取成功:{str}",
+ NotifiactionType = EnumPromptType.Success
+ });
+ }
+ else
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备未连接",
+ NotifiactionType = EnumPromptType.Warn
+ });
+ }
+ }
+ else
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备未获取到配置信息",
+ NotifiactionType = EnumPromptType.Warn
+ });
+ }
+ }catch (Exception ex)
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"条码读取异常:{ex.Message}",
+ NotifiactionType = EnumPromptType.Error
+ });
+ }
+ }
+
+ [RelayCommand]
+ private void WriteEpcCode(string deviceCode)
+ {
+ try
+ {
+ string configKey = string.Empty;
+ if (deviceCode == "050-B" || deviceCode == "I68")
+ {
+ configKey = "I68";
+ }
+ else
+ {
+ configKey = deviceCode;
+ }
+ var rfidConfig = _appConfig.rfidConfig.Where(x => x.equipKey == configKey).FirstOrDefault();
+
+ if (rfidConfig != null)
+ {
+ var session = rfidConfig.session as TcpClient;
+
+ if (session != null)
+ {
+ var waitClinet = session.CreateWaitingClient(new WaitingOptions()
+ {
+ FilterFunc = response =>
+ {
+ return true;
+ }
+ });
+
+ byte[] buffer = null;
+
+ if (deviceCode == "I90" || deviceCode == "RFR-RFLY")
+ {
+ byte[] FixedPart = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x10, 0x00, 0x10, 0x00, 0x04};
+
+ string epcBarCode = string.Empty;
+
+ if (deviceCode == "I90")
+ {
+ epcBarCode = FirstBatchEpcBarcode;
+ }
+ else
+ {
+ epcBarCode = SecondBatchEpcBarcode;
+ }
+
+ int inputByteLength = epcBarCode.Length / 2;
+ byte[] fixedPartWithLength = new byte[FixedPart.Length + 1];
+ Array.Copy(FixedPart, fixedPartWithLength, FixedPart.Length);
+ fixedPartWithLength[fixedPartWithLength.Length - 1] = (byte)inputByteLength;
+
+ byte[] inputBytes = Enumerable.Range(0, epcBarCode.Length)
+ .Where(x => x % 2 == 0)
+ .Select(x => Convert.ToByte(FirstBatchEpcBarcode.Substring(x, 2), 16))
+ .ToArray();
+ buffer = new byte[fixedPartWithLength.Length + inputBytes.Length];
+
+ Array.Copy(fixedPartWithLength, buffer, fixedPartWithLength.Length);
+
+ Array.Copy(inputBytes, 0, buffer, fixedPartWithLength.Length, inputBytes.Length);
+ }
+
+ if (deviceCode == "050-B")
+ {
+ buffer = new byte[] { 0x00, 0x82, 0x00, 0x00, 0x00, 0x1F, 0x01, 0x10, 0x00, 0x00, 0x00, 0x0C, 0x18, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
+
+ byte[] inputBytes = Enumerable.Range(0, FourthBatchEpcBarcode.Length)
+ .Where(x => x % 2 == 0)
+ .Select(x => Convert.ToByte(FourthBatchEpcBarcode.Substring(x, 2), 16))
+ .ToArray();
+ buffer = buffer.Concat(inputBytes).ToArray();
+ }
+
+ if (deviceCode == "I68")
+ {
+ buffer = new byte[] { 0x00, 0x89, 0x00, 0x00, 0x00, 0x27, 0x01, 0x10, 0x00, 0x00, 0x00, 0x10, 0x20, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
+
+ byte[] inputBytes = Enumerable.Range(0, ThirdBatchEpcBarcode.Length)
+ .Where(x => x % 2 == 0)
+ .Select(x => Convert.ToByte(ThirdBatchEpcBarcode.Substring(x, 2), 16))
+ .ToArray();
+ buffer = buffer.Concat(inputBytes).ToArray();
+
+ }
+
+
+
+ ResponsedData responsedData = waitClinet.SendThenResponse(buffer, 5000);
+
+ //string str = _stringChange.bytesToHexStr(responsedData.Data, responsedData.Data.Length).Substring(18, 16);
+
+ //SetEpcBarCode(deviceCode, str);
+
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备写入成功",
+ NotifiactionType = EnumPromptType.Success
+ });
+ }
+ else
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备未连接",
+ NotifiactionType = EnumPromptType.Warn
+ });
+ }
+ }
+ else
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备未获取到配置信息",
+ NotifiactionType = EnumPromptType.Warn
+ });
+ }
+ }
+ catch (Exception ex)
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备写入异常:{ex.Message}",
+ NotifiactionType = EnumPromptType.Error
+ });
+ }
+ }
+
+ [RelayCommand]
+ private void ReadEpcCodeByRtu(string deviceCode)
+ {
+ try
+ {
+
+ byte[] buffer = null;
+
+ if (deviceCode == "I40") //站1
+ {
+ buffer = new byte[] { 0x01, 0x03, 0x00, 0x10, 0x00, 0x04, 0x45, 0xCC, };
+ }
+
+ if (deviceCode == "RFR-050") //站2
+ {
+ buffer = new byte[] { 0x02, 0x03, 0x00, 0x10, 0x00, 0x04, 0x45, 0xFF, };
+ }
+
+ byte[] response = _serialBusiness.SendDataAndWaitForResponse(buffer);
+
+ if (response.Length == 13)
+ {
+ string str = _stringChange.bytesToHexStr(response, response.Length).Substring(6, 16);
+
+ SetEpcBarCode(deviceCode, str);
+
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备读取成功:{str}",
+ NotifiactionType = EnumPromptType.Success
+ });
+ }
+ else
+ {
+ SetEpcBarCode(deviceCode, string.Empty);
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备读取失败",
+ NotifiactionType = EnumPromptType.Success
+ });
+ }
+
+
+ }
+ catch (Exception ex)
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"条码读取异常:{ex.Message}",
+ NotifiactionType = EnumPromptType.Error
+ });
+ }
+ }
+
+ [RelayCommand]
+ private void WriteEpcCodeByRtu(string deviceCode)
+ {
+ try
+ {
+ //站1
+ //01 10 00 10 00 04 08 11 11 22 22 11 11 22 22 85 41
+ //01 10 00 10 00 04 08 11 11 11 11 11 11 11 11 85 41
+ //站2 02 10 00 10 00 04 08 11 11 11 11 11 11 11 11 93 62
+ byte[] buffer = null;
+ if (deviceCode == "I40")
+ {
+ buffer = new byte[] { 0x01, 0x10, 0x00, 0x10, 0x00, 0x04, 0x08, };
+ byte[] inputBytes = Enumerable.Range(0, SixthBatchEpcBarcode.Length)
+ .Where(x => x % 2 == 0)
+ .Select(x => Convert.ToByte(SixthBatchEpcBarcode.Substring(x, 2), 16))
+ .ToArray();
+ buffer = buffer.Concat(inputBytes).ToArray();
+ byte[] crcBytes = CRCCalc(buffer);
+
+ buffer = buffer.Concat(crcBytes).ToArray();
+ }
+
+ if (deviceCode == "RFR-050")
+ {
+ buffer = new byte[] { 0x02, 0x10, 0x00, 0x10, 0x00, 0x04, 0x08, };
+ byte[] inputBytes = Enumerable.Range(0, FifthBatchEpcBarcode.Length)
+ .Where(x => x % 2 == 0)
+ .Select(x => Convert.ToByte(FifthBatchEpcBarcode.Substring(x, 2), 16))
+ .ToArray();
+ buffer = buffer.Concat(inputBytes).ToArray();
+ byte[] crcBytes = CRCCalc(buffer);
+
+ buffer = buffer.Concat(crcBytes).ToArray();
+
+ }
+
+ _logger.Info($"{deviceCode}发送:{_stringChange.bytesToHexStr(buffer, buffer.Length)}");
+ var responsedData = _serialBusiness.SendDataAndWaitForResponse(buffer);
+
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备写入成功",
+ NotifiactionType = EnumPromptType.Success
+ });
+ }
+ catch (Exception ex)
+ {
+ NoticeManager.NotifiactionShow.AddNotifiaction(new NotifiactionModel()
+ {
+ Title = "通知",
+ Content = $"{deviceCode}设备写入异常:{ex.Message}",
+ NotifiactionType = EnumPromptType.Error
+ });
+ }
+ }
+
+ public static byte[] CRCCalc(byte[] data)
+ {
+ int crc = 0xffff;
+ for (int i = 0; i < data.Length; i++)
+ {
+ crc ^= data[i];
+ for (int j = 0; j < 8; j++)
+ {
+ int temp = crc & 1;
+ crc >>= 1;
+ crc &= 0x7fff;
+ if (temp == 1)
+ {
+ crc ^= 0xa001;
+ }
+ crc &= 0xffff;
+ }
+ }
+ byte[] crc16 = new byte[2];
+ crc16[1] = (byte)((crc >> 8) & 0xff);
+ crc16[0] = (byte)(crc & 0xff);
+ return crc16;
+ }
+
+ private void SetEpcBarCode(string deviceCode,string str)
+ {
+ switch (deviceCode)
+ {
+ case "I90":
+ FirstBatchEpcBarcode = str;
+ break;
+ case "RFR-RFLY":
+ SecondBatchEpcBarcode = str;
+ break;
+ case "I68":
+ ThirdBatchEpcBarcode = str;
+ break;
+ case "050-B":
+ FourthBatchEpcBarcode = str;
+ break;
+ case "RFR-050":
+ FifthBatchEpcBarcode = str;
+ break;
+ case "I40":
+ SixthBatchEpcBarcode= str;
+ break;
+ default:
+ break;
+ }
+ }
}
-}
+}
\ No newline at end of file
diff --git a/SlnMesnac.WPF/appsettings.json b/SlnMesnac.WPF/appsettings.json
index 6005a25..d8f2e2a 100644
--- a/SlnMesnac.WPF/appsettings.json
+++ b/SlnMesnac.WPF/appsettings.json
@@ -8,7 +8,7 @@
},
"AllowedHosts": "*",
"AppConfig": {
- "logPath": "E:\\桌面\\SlnMesnac\\SlnMesnac.WPF\\bin\\Debug\\net6.0-windows",
+ "logPath": "F:\\桌面\\RFID 展会软件\\程序设计\\RFID.Exhibition\\SlnMesnac.WPF\\bin\\Debug",
"SqlConfig": [
{
"configId": "iot",
@@ -17,40 +17,28 @@
"connStr": "server=1.13.177.47;Port=3306;Database=rfid_exhibition;Uid=root;Pwd=Haiwei123456;"
}
],
- "PlcConfig": [
- {
- "configId": 1,
- "plcType": "MelsecBinaryPlc",
- "plcIp": "127.0.0.1",
- "plcPort": 6000,
- "plcKey": "mcs",
- "isFlage": true
- },
- {
- "configId": 2,
- "plcType": "MelsecBinaryPlc",
- "plcIp": "127.0.0.1",
- "plcPort": 6001,
- "plcKey": "cwss",
- "isFlage": true
- }
- ],
"RfidConfig": [
{
"configId": 1,
"equipIp": "127.0.0.1",
- "equipPort": 6003,
- "equipKey": "test1",
+ "equipPort": 11,
+ "equipKey": "I90",
"isFlage": true
},
{
"configId": 2,
"equipIp": "127.0.0.1",
- "equipPort": 6004,
- "equipKey": "test2",
+ "equipPort": 11,
+ "equipKey": "22",
+ "isFlage": true
+ },
+ {
+ "configId": 3,
+ "equipIp": "127.0.0.1",
+ "equipPort": 11,
+ "equipKey": "I68",
"isFlage": true
}
- ],
- "redisConfig": "175.27.215.92:6379,password=redis@2023"
+ ]
}
}