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