push-提交现场调试版

master
liuwf 5 months ago
parent 70d846ed18
commit 0bdfe55b39

@ -45,9 +45,11 @@ namespace SlnMesnac.Business
private static bool HikCameraResult = false; private static bool HikCameraResult = false;
#region 委托定义 刷新界面扫描信息 #region 委托定义 刷新界面扫描信息
public delegate void RefreshBoxInfo(string boxCode, string boxTime, string model, byte[] imageData, bool isSuccess); public delegate void RefreshBoxInfo(string boxCode, string boxTime, string model, bool isSuccess);
public static event RefreshBoxInfo? RefreshBoxInfoEvent; public static event RefreshBoxInfo? RefreshBoxInfoEvent;
public delegate void RefreshPicture(byte[] imageData);
public static event RefreshPicture? RefreshPictureEvent;
public delegate void RefreshMessage(string message, bool isWarning = false); public delegate void RefreshMessage(string message, bool isWarning = false);
public static event RefreshMessage? RefreshMessageEvent; public static event RefreshMessage? RefreshMessageEvent;
@ -102,7 +104,7 @@ namespace SlnMesnac.Business
/// <param name="ip"></param> /// <param name="ip"></param>
public async void BarCodeHandler(string materialCodeStr, string ip) public async void BarCodeHandler(string materialCodeStr, string ip)
{ {
Console.WriteLine("相机流程开始:");
// 传入照片 // 传入照片
byte[] ImageData = null; byte[] ImageData = null;
try try
@ -129,6 +131,7 @@ namespace SlnMesnac.Business
if (logoConfig.IsChecked == 1) if (logoConfig.IsChecked == 1)
{ {
Thread.Sleep(int.Parse(config.SleepStr));
// 1.触发相机拍照 // 1.触发相机拍照
tcpServer.SendCommand(config.CameraIP, logoConfig.CheckKind.ToString()); tcpServer.SendCommand(config.CameraIP, logoConfig.CheckKind.ToString());
// 需要校验 // 需要校验
@ -166,18 +169,25 @@ namespace SlnMesnac.Business
record.RecordTime = DateTime.Now; record.RecordTime = DateTime.Now;
logoIdentifyService.InsertRecord(record); logoIdentifyService.InsertRecord(record);
#endregion #endregion
// 刷新界面、刷新图片,照片按照日期存储本地
RefreshBoxInfoEvent?.Invoke(materialCodeStr, DateTime.Now.ToString(), logoConfig.MaterialName, hikFlag);
await Task.Run(() =>
{
Thread.Sleep(int.Parse(config.PictureSleep));
ImageData = FileHelper.FindPhoto(config.CameraFilePath); ImageData = FileHelper.FindPhoto(config.CameraFilePath);
if (ImageData != null) if (ImageData != null)
{ {
FileHelper.SaveImage(ImageData, materialCodeStr + ".jpg", PicturePath); FileHelper.SaveImage(ImageData, materialCodeStr + ".jpg", PicturePath);
// 刷新界面、刷新图片,照片按照日期存储本地 RefreshPictureEvent?.Invoke(ImageData);
RefreshBoxInfoEvent?.Invoke(materialCodeStr, DateTime.Now.ToString(), logoConfig.MaterialName, ImageData, hikFlag);
} }
else else
{ {
WarningAndStop($"读取相机保存照片文件夹失败,请检查文件夹:{config.CameraFilePath}是否存在"); // WarningAndStop($"读取相机保存照片文件夹失败,请检查文件夹:{config.CameraFilePath}是否存在");
} }
});
} }
catch (Exception ex) catch (Exception ex)
@ -283,7 +293,7 @@ namespace SlnMesnac.Business
{ {
if (plc != null && plc.IsConnected) if (plc != null && plc.IsConnected)
{ {
plc.writeInt32ByAddress("DB22.DBW2", 8); plc.writeInt16ByAddress("DB22.DBW2", 8);
Task.Run(() => Task.Run(() =>
{ {
// 设置计时器 // 设置计时器
@ -291,10 +301,11 @@ namespace SlnMesnac.Business
stopwatch.Start(); stopwatch.Start();
while (true) while (true)
{ {
if (plc.readInt32ByAddress("DB22.DBW2") == 0) if (plc.readInt16ByAddress("DB22.DBW2") == 0)
{ {
logger.LogInformation("PLC复位成功,启动线体"); logger.LogInformation("PLC复位成功,启动线体");
RefreshMessageEvent?.Invoke("PLC复位成功,启动线体", true); RefreshMessageEvent?.Invoke("PLC复位成功,启动线体");
break;
} }
// 检查是否超过两秒 // 检查是否超过两秒
if (stopwatch.ElapsedMilliseconds > 3000) if (stopwatch.ElapsedMilliseconds > 3000)
@ -329,7 +340,7 @@ namespace SlnMesnac.Business
{ {
if (plc != null && plc.IsConnected) if (plc != null && plc.IsConnected)
{ {
plc.writeInt32ByAddress("DB22.DBW2", 9); plc.writeInt16ByAddress("DB22.DBW2", 9);
Task.Run(() => Task.Run(() =>
{ {
// 设置计时器 // 设置计时器
@ -337,10 +348,11 @@ namespace SlnMesnac.Business
stopwatch.Start(); stopwatch.Start();
while (true) while (true)
{ {
if (plc.readInt32ByAddress("DB22.DBW2") == 1) if (plc.readInt16ByAddress("DB22.DBW2") == 1)
{ {
logger.LogInformation("PLC复位成功,启动线体"); logger.LogInformation("PLC复位成功,启动线体");
RefreshMessageEvent?.Invoke("PLC复位成功,启动线体", true); RefreshMessageEvent?.Invoke("PLC复位成功,启动线体");
break;
} }
// 检查是否超过两秒 // 检查是否超过两秒
if (stopwatch.ElapsedMilliseconds > 3000) if (stopwatch.ElapsedMilliseconds > 3000)

@ -20,7 +20,7 @@ namespace SlnMesnac.Common
try try
{ {
// 获取目录中的所有文件 // 获取目录中的所有文件
string[] files = Directory.GetFiles(directoryPath, "*.jpg"); string[] files = Directory.GetFiles(directoryPath, "*.bmp");
// 检查是否有文件 // 检查是否有文件
if (files.Length == 0) if (files.Length == 0)

@ -38,7 +38,7 @@ namespace SlnMesnac.Common
} }
#endregion #endregion
private DebugConfig config = DebugConfig.Instance;
//初始化串口并启动接收数据 //初始化串口并启动接收数据
public void InstanceSerialPort() public void InstanceSerialPort()
@ -49,7 +49,7 @@ namespace SlnMesnac.Common
//实例化串行端口 //实例化串行端口
//端口名 注:因为使用的是USB转RS232 所以去设备管理器中查看一下虚拟com口的名字 //端口名 注:因为使用的是USB转RS232 所以去设备管理器中查看一下虚拟com口的名字
serialPort.PortName = port;// portName; serialPort.PortName = config.Port;// portName;
//波特率 霍尼威尔扫码枪115200,普通9600 //波特率 霍尼威尔扫码枪115200,普通9600
serialPort.BaudRate = 0x2580; serialPort.BaudRate = 0x2580;
//奇偶校验 //奇偶校验

@ -53,5 +53,31 @@ namespace SlnMesnac.Config
set { iniHelper.IniWriteValue("system", "CameraFilePath", value); } set { iniHelper.IniWriteValue("system", "CameraFilePath", value); }
} }
/// <summary>
/// 拍照延迟
/// </summary>
public string SleepStr
{
get { return iniHelper.IniReadValue("system", "Sleep"); }
set { iniHelper.IniWriteValue("system", "Sleep", value); }
}
/// <summary>
/// 读取照片延迟
/// </summary>
public string PictureSleep
{
get { return iniHelper.IniReadValue("system", "PictureSleep"); }
set { iniHelper.IniWriteValue("system", "PictureSleep", value); }
}
/// <summary>
/// Com口
/// </summary>
public string Port
{
get { return iniHelper.IniReadValue("system", "ComPort"); }
set { iniHelper.IniWriteValue("system", "ComPort", value); }
}
} }
} }

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks;
using TouchSocket.Core; using TouchSocket.Core;
using TouchSocket.Sockets; using TouchSocket.Sockets;
@ -83,16 +84,21 @@ namespace SlnMesnac.TouchSocket
} }
else else
{ {
string code = mes.Trim().TrimEnd('\0');
client.Logger.Info($"客户端{client.IP}:{client.Port}》接收到信息:{mes}"); client.Logger.Info($"客户端{client.IP}:{client.Port}》接收到信息:{mes}");
// 区分相机扫码器数据 // 区分相机扫码器数据
if (client.IP == config.ScannerIP) if (client.IP == config.ScannerIP)
{ {
RefreshMaterialCodeStrEvent?.Invoke(mes.Trim().TrimEnd('\0'), client.IP); if (code.Contains("heart"))
{ // 粘包丢弃
return Task.CompletedTask;
}
RefreshMaterialCodeStrEvent?.Invoke(code, client.IP);
} }
else if (client.IP == config.CameraIP) else if (client.IP == config.CameraIP)
{ {
// 相机返回数据 // 相机返回数据
CameraResultEvent?.Invoke(mes.Trim().TrimEnd('\0')); CameraResultEvent?.Invoke(code);
} }

@ -49,6 +49,7 @@ namespace SlnMesnac.WPF.ViewModel
logoIdentifyService = App.ServiceProvider.GetService<ILogoIdentifyService>(); logoIdentifyService = App.ServiceProvider.GetService<ILogoIdentifyService>();
LogoBusiness.RefreshMessageEvent += RefreshMessage; LogoBusiness.RefreshMessageEvent += RefreshMessage;
LogoBusiness.RefreshBoxInfoEvent += RefreshBoxInfo; LogoBusiness.RefreshBoxInfoEvent += RefreshBoxInfo;
LogoBusiness.RefreshPictureEvent += RefreshPicture;
ResetCommand = new RelayCommand(Reset); ResetCommand = new RelayCommand(Reset);
RefreshDataGrid(); RefreshDataGrid();
@ -71,8 +72,8 @@ namespace SlnMesnac.WPF.ViewModel
/// <exception cref="NotImplementedException"></exception> /// <exception cref="NotImplementedException"></exception>
private void Reset() private void Reset()
{ {
logoBusiness.BarCodeHandler("2737001000021E6M0627", "111"); //FileHelper.FindPhoto(DebugConfig.Instance.CameraFilePath);
// logoBusiness.Pass(); logoBusiness.Pass();
} }
/// <summary> /// <summary>
@ -134,16 +135,33 @@ namespace SlnMesnac.WPF.ViewModel
/// <param name="boxTime"></param> /// <param name="boxTime"></param>
/// <param name="model"></param> /// <param name="model"></param>
/// <param name="imageData"></param> /// <param name="imageData"></param>
public void RefreshBoxInfo(string boxCode,string boxTime,string model,byte[] imageData,bool isSuccess) public void RefreshBoxInfo(string boxCode,string boxTime,string model,bool isSuccess)
{ {
BoxCode = boxCode; BoxCode = boxCode;
BoxTime = boxTime; BoxTime = boxTime;
ProductModel = model; ProductModel = model;
ImageData = imageData;
RefreshResultColor(isSuccess); RefreshResultColor(isSuccess);
RefreshDataGrid(); RefreshDataGrid();
} }
/// <summary>
/// 刷新界面照片
/// </summary>
/// <param name="boxCode"></param>
/// <param name="boxTime"></param>
/// <param name="model"></param>
/// <param name="imageData"></param>
public void RefreshPicture(byte[] imageData)
{
ImageData = imageData;
}
/// <summary> /// <summary>
/// 刷新界面提示信息 /// 刷新界面提示信息
/// </summary> /// </summary>

@ -112,9 +112,9 @@
<RowDefinition/> <RowDefinition/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center" > <StackPanel Grid.Row="0" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center" >
<TextBlock Text="箱体码 " FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 0 30 0"/> <TextBlock Text="产品编码" FontSize="20" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 0 30 0"/>
<TextBox FontSize="18" Text="{Binding BoxCode,Mode=TwoWay}" BorderBrush="White" Foreground="White" Width="250" IsReadOnly="True" Margin="0 0 10 0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" /> <TextBox FontSize="20" Text="{Binding BoxCode,Mode=TwoWay}" BorderBrush="White" Foreground="White" Width="250" IsReadOnly="True" Margin="0 0 10 0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" />
<TextBox FontSize="18" Text="{Binding BoxTime,Mode=TwoWay}" BorderBrush="White" Foreground="White" Width="200" IsReadOnly="True" Margin="10 0 0 0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/> <TextBox FontSize="20" Text="{Binding BoxTime,Mode=TwoWay}" BorderBrush="White" Foreground="White" Width="200" IsReadOnly="True" Margin="10 0 0 0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"/>
</StackPanel> </StackPanel>
<StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center" > <StackPanel Grid.Row="1" Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Center" >
<TextBlock Text="产品型号" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 0 30 0"/> <TextBlock Text="产品型号" FontSize="18" Foreground="White" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0 0 30 0"/>
@ -126,7 +126,7 @@
<StackPanel Grid.Row="2" Grid.RowSpan="2" > <StackPanel Grid.Row="2" Grid.RowSpan="2" >
<TextBlock Text="提示信息" FontSize="20" Foreground="White"/> <TextBlock Text="提示信息" FontSize="20" Foreground="White"/>
<TextBox FontSize="15" BorderBrush="White" <TextBox FontSize="22" BorderBrush="White"
MinHeight="70" IsReadOnly="True" Foreground="{Binding MsgColor}" Margin="30 0 0 0" MinHeight="70" IsReadOnly="True" Foreground="{Binding MsgColor}" Margin="30 0 0 0"
AcceptsReturn="True" Text="{Binding Message,Mode=TwoWay}" AcceptsReturn="True" Text="{Binding Message,Mode=TwoWay}"
Style="{StaticResource MaterialDesignOutlinedTextBox}" Style="{StaticResource MaterialDesignOutlinedTextBox}"

@ -25,8 +25,8 @@
{ {
"configId": 1, "configId": 1,
"plcType": "SiemensPlc", "plcType": "SiemensPlc",
"plcIp": "10.10.51.11", // "plcIp": "10.10.51.11",
// "plcIp": "127.0.0.1", "plcIp": "127.0.0.1",
"plcPort": 102, "plcPort": 102,
"plcKey": "plc", "plcKey": "plc",
"isFlage": true "isFlage": true

Loading…
Cancel
Save