|
|
@ -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
|
|
|
|
ImageData = FileHelper.FindPhoto(config.CameraFilePath);
|
|
|
|
|
|
|
|
if (ImageData != null)
|
|
|
|
// 刷新界面、刷新图片,照片按照日期存储本地
|
|
|
|
{
|
|
|
|
RefreshBoxInfoEvent?.Invoke(materialCodeStr, DateTime.Now.ToString(), logoConfig.MaterialName, hikFlag);
|
|
|
|
FileHelper.SaveImage(ImageData, materialCodeStr + ".jpg", PicturePath);
|
|
|
|
|
|
|
|
// 刷新界面、刷新图片,照片按照日期存储本地
|
|
|
|
await Task.Run(() =>
|
|
|
|
RefreshBoxInfoEvent?.Invoke(materialCodeStr, DateTime.Now.ToString(), logoConfig.MaterialName, ImageData, hikFlag);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
WarningAndStop($"读取相机保存照片文件夹失败,请检查文件夹:{config.CameraFilePath}是否存在");
|
|
|
|
Thread.Sleep(int.Parse(config.PictureSleep));
|
|
|
|
}
|
|
|
|
ImageData = FileHelper.FindPhoto(config.CameraFilePath);
|
|
|
|
|
|
|
|
if (ImageData != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FileHelper.SaveImage(ImageData, materialCodeStr + ".jpg", PicturePath);
|
|
|
|
|
|
|
|
RefreshPictureEvent?.Invoke(ImageData);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// 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)
|
|
|
|