change-条码绑定扫码器,扫码枪方法由一个一个传改成两个一起传

dev
liuwf 10 months ago
parent 8fbb2ad83d
commit 3da5303554

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows</TargetFramework> <TargetFramework>net6.0-windows</TargetFramework>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>

@ -25,11 +25,13 @@ namespace Aucma.Core.CodeBinding.Business
// 箱壳扫码器ip // 箱壳扫码器ip
private static string SNScannerIp = allScanners.First(x => x.Name == "sn扫码器").Ip; private static string SNScannerIp = allScanners.First(x => x.Name == "sn扫码器").Ip;
private static string SNCode = string.Empty;
private static string MESCode = string.Empty;
/// <summary> /// <summary>
/// code1扫码信息刷新 /// code1扫码信息刷新
/// </summary> /// </summary>
/// <param name="Code1"></param> /// <param name="Code1"></param>
public delegate void BindingReceiveCode(string code, string ip); public delegate void BindingReceiveCode(string MesCode, string SnCode);
public static event BindingReceiveCode? BindingReceiveCodeEvent; public static event BindingReceiveCode? BindingReceiveCodeEvent;
#region 单例实现 #region 单例实现
@ -103,13 +105,22 @@ namespace Aucma.Core.CodeBinding.Business
if (str.Substring(0, 1) == "B") if (str.Substring(0, 1) == "B")
{ {
// mes条码 // mes条码
MESCode = str;
RefreshMaterialCodeStrEvent?.Invoke(str, MesScannerIp); RefreshMaterialCodeStrEvent?.Invoke(str, MesScannerIp);
} }
else else
{ {
//SN码 //SN码
SNCode = str;
RefreshMaterialCodeStrEvent?.Invoke(str,SNScannerIp); RefreshMaterialCodeStrEvent?.Invoke(str,SNScannerIp);
} }
if(!string.IsNullOrEmpty(MESCode) && !string.IsNullOrEmpty(SNCode))
{
// 委托
BindingReceiveCodeEvent?.Invoke(MESCode, SNCode);
SNCode = string.Empty;
MESCode = string.Empty;
}
sb.Clear(); sb.Clear();
} }

@ -32,6 +32,10 @@ namespace Aucma.Core.CodeBinding.Business
public static MvCodeReader LinerDevice = null; public static MvCodeReader LinerDevice = null;
public static DateTime ShellLiveTime = DateTime.Now; public static DateTime ShellLiveTime = DateTime.Now;
public static DateTime LinerLiveTime = DateTime.Now; public static DateTime LinerLiveTime = DateTime.Now;
private static string MesCode = string.Empty;
private static string SNCode = string.Empty;
#endregion #endregion
@ -56,8 +60,15 @@ namespace Aucma.Core.CodeBinding.Business
/// code1扫码信息刷新 /// code1扫码信息刷新
/// </summary> /// </summary>
/// <param name="Code1"></param> /// <param name="Code1"></param>
public delegate void BindingReceiveCode(string code, string ip); public delegate void ReceiveCode(string code, string ip);
public static event BindingReceiveCode? BindingReceiveCodeEvent; public static event ReceiveCode? ReceiveCodeEvent;
/// <summary>
/// 条码绑定
/// </summary>
/// <param name="Code1"></param>
public delegate void BindingCode(string mesCode, string snCode);
public static event BindingCode? BindingCodeEvent;
/// <summary> /// <summary>
/// NoRead通知 /// NoRead通知
@ -91,6 +102,8 @@ namespace Aucma.Core.CodeBinding.Business
log.Info(DateTime.Now + ":SN--->No Read 处理"); log.Info(DateTime.Now + ":SN--->No Read 处理");
//更新扫码器存活时间 //更新扫码器存活时间
ShellLiveTime = DateTime.Now; ShellLiveTime = DateTime.Now;
SNCode = string.Empty;
MesCode = string.Empty;
} }
for (Int32 i = 0; i < stBcrResult.nCodeNum; i++) for (Int32 i = 0; i < stBcrResult.nCodeNum; i++)
{ {
@ -109,8 +122,10 @@ namespace Aucma.Core.CodeBinding.Business
//更新扫码器存活时间 //更新扫码器存活时间
ShellLiveTime = DateTime.Now; ShellLiveTime = DateTime.Now;
BindingReceiveCodeEvent?.Invoke(strCode.Trim().TrimEnd('\0'), ShellScannerIp);
// 业务处理 SNCode = strCode.Trim().TrimEnd('\0');
ReceiveCodeEvent?.Invoke(strCode.Trim().TrimEnd('\0'), ShellScannerIp);
} }
} }
@ -126,6 +141,8 @@ namespace Aucma.Core.CodeBinding.Business
public static void LinerImageCallbackFunc(IntPtr pData, IntPtr pstFrameInfoEx2, IntPtr pUser) public static void LinerImageCallbackFunc(IntPtr pData, IntPtr pstFrameInfoEx2, IntPtr pUser)
{
try
{ {
var stFrameInfo = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)); var stFrameInfo = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2));
@ -139,6 +156,8 @@ namespace Aucma.Core.CodeBinding.Business
log.Info(DateTime.Now + ":mes--->No Read 处理"); log.Info(DateTime.Now + ":mes--->No Read 处理");
// 更新存活时间 // 更新存活时间
LinerLiveTime = DateTime.Now; LinerLiveTime = DateTime.Now;
SNCode = string.Empty;
MesCode = string.Empty;
} }
for (Int32 i = 0; i < stBcrResult.nCodeNum; i++) for (Int32 i = 0; i < stBcrResult.nCodeNum; i++)
{ {
@ -156,8 +175,16 @@ namespace Aucma.Core.CodeBinding.Business
// 更新存活时间 // 更新存活时间
LinerLiveTime = DateTime.Now; LinerLiveTime = DateTime.Now;
// 业务处理
BindingReceiveCodeEvent?.Invoke(strCode.Trim().TrimEnd('\0'), LinerScannerIp); MesCode = strCode.Trim().TrimEnd('\0');
ReceiveCodeEvent?.Invoke(strCode.Trim().TrimEnd('\0'), LinerScannerIp);
if (!string.IsNullOrEmpty(MesCode) && !string.IsNullOrEmpty(SNCode))
{
BindingCodeEvent?.Invoke(MesCode, SNCode);
MesCode = string.Empty;
SNCode = string.Empty;
}
} }
} }
@ -171,6 +198,16 @@ namespace Aucma.Core.CodeBinding.Business
Console.WriteLine("Get OcrInfo:" + "ocrNum[" + i.ToString() + "], ocrLen[" + Convert.ToString(stOcrInfo.stOcrRowInfo[i].nOcrLen) + "], ocrChar[" + strOcrCharCode.Trim().TrimEnd('\0') + "]"); Console.WriteLine("Get OcrInfo:" + "ocrNum[" + i.ToString() + "], ocrLen[" + Convert.ToString(stOcrInfo.stOcrRowInfo[i].nOcrLen) + "], ocrChar[" + strOcrCharCode.Trim().TrimEnd('\0') + "]");
} }
} }
catch (Exception ex)
{
log.Info("mes扫码器回调函数异常:" + ex.Message.ToString());
}
finally
{
MesCode = string.Empty;
SNCode = string.Empty;
}
}
public static void Shell() public static void Shell()

@ -54,10 +54,10 @@ namespace Aucma.Core.CodeBinding.ViewModels
// 过点数据表物料完成记录MaterialCompletion // 过点数据表物料完成记录MaterialCompletion
private readonly IMaterialCompletionServices? _iMaterialCompletionServices; private readonly IMaterialCompletionServices? _iMaterialCompletionServices;
// 静态变量存code1 // 静态变量存code1
private static string code1Str = string.Empty; // private static string code1Str = string.Empty;
// 静态变量存code2 // 静态变量存code2
private static string code2Str = string.Empty; // private static string code2Str = string.Empty;
//配置文件扫码器列表 //配置文件扫码器列表
private static List<ScannerModel> allScanners = Appsettings.app<ScannerModel>("ScannerServer").ToList(); private static List<ScannerModel> allScanners = Appsettings.app<ScannerModel>("ScannerServer").ToList();
public IndexPageViewModel() public IndexPageViewModel()
@ -70,9 +70,11 @@ namespace Aucma.Core.CodeBinding.ViewModels
_printBarCodeServices = App.ServiceProvider.GetService<IPrintBarCodeServices>(); _printBarCodeServices = App.ServiceProvider.GetService<IPrintBarCodeServices>();
_iMaterialCompletionServices = App.ServiceProvider.GetService<IMaterialCompletionServices>(); _iMaterialCompletionServices = App.ServiceProvider.GetService<IMaterialCompletionServices>();
Business.MvCodeHelper.BindingReceiveCodeEvent += ReceiveCode; Business.MvCodeHelper.ReceiveCodeEvent += ReceiveCode;
GunBusiness.RefreshMaterialCodeStrEvent += ReceiveCode; Business.MvCodeHelper.BindingCodeEvent += BindingCode;
Business.MvCodeHelper.NoReadEvent += ReceiveNoRead; Business.MvCodeHelper.NoReadEvent += ReceiveNoRead;
GunBusiness.BindingReceiveCodeEvent += BindingCode;
GunBusiness.RefreshMaterialCodeStrEvent += ReceiveCode;
LoadData(); LoadData();
@ -104,29 +106,29 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
string tempCode1 ; string tempCode1 ;
string tempCode2; string tempCode2;
// 实时绑定条码 //// 实时绑定条码
Task.Run(() => //Task.Run(() =>
{ //{
while(true) // while(true)
{ // {
try // try
{ // {
if (!string.IsNullOrEmpty(code1Str) && !string.IsNullOrEmpty(code2Str)) // if (!string.IsNullOrEmpty(code1Str) && !string.IsNullOrEmpty(code2Str))
{ // {
tempCode1 = code1Str; // tempCode1 = code1Str;
tempCode2 = code2Str; // tempCode2 = code2Str;
code1Str = string.Empty; // code1Str = string.Empty;
code2Str = string.Empty; // code2Str = string.Empty;
BindingCode(tempCode1, tempCode2); // BindingCode(tempCode1, tempCode2);
} // }
} // }
catch (Exception ex) // catch (Exception ex)
{ // {
Console.WriteLine(ex.ToString()); // Console.WriteLine(ex.ToString());
} // }
Thread.Sleep(500); // Thread.Sleep(500);
} // }
}); //});
// 心跳线程 // 心跳线程
Task.Run(() => Task.Run(() =>
@ -449,11 +451,11 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
log.Info("MES条码NoRead:"); log.Info("MES条码NoRead:");
// 全局变量赋值 // 全局变量赋值
code1Str = string.Empty ; // code1Str = string.Empty ;
code2Str = string.Empty; // code2Str = string.Empty;
// 页面扫码信息清空 // 页面扫码信息清空
Code1 = code1Str; Code1 = string.Empty;
Code2 = code2Str; Code2 = string.Empty;
Code1Time = string.Empty ; Code1Time = string.Empty ;
Code2Time = string.Empty ; Code2Time = string.Empty ;
SendPlcStop(); SendPlcStop();
@ -462,11 +464,11 @@ namespace Aucma.Core.CodeBinding.ViewModels
else if(model.Id == 2) else if(model.Id == 2)
{ {
RefreshAndWriteLog("SN条码未扫描到,NoRead报警,线体停止,请重新扫描!"); RefreshAndWriteLog("SN条码未扫描到,NoRead报警,线体停止,请重新扫描!");
code1Str = string.Empty; // code1Str = string.Empty;
code2Str = string.Empty; // code2Str = string.Empty;
// 页面扫码信息清空 // 页面扫码信息清空
Code1 = code1Str; Code1 = string.Empty;
Code2 = code2Str; Code2 = string.Empty;
Code1Time = string.Empty; Code1Time = string.Empty;
Code2Time = string.Empty; Code2Time = string.Empty;
SendPlcStop(); SendPlcStop();
@ -487,7 +489,7 @@ namespace Aucma.Core.CodeBinding.ViewModels
{ {
log.Info("扫描到MES条码:" + codeStr); log.Info("扫描到MES条码:" + codeStr);
// 全局变量赋值SN码扫描后使用 // 全局变量赋值SN码扫描后使用
code1Str = codeStr; // code1Str = codeStr;
RefreshCode1(codeStr); RefreshCode1(codeStr);
} }
else else
@ -495,7 +497,7 @@ namespace Aucma.Core.CodeBinding.ViewModels
log.Info("扫描到成品条码:" + codeStr); log.Info("扫描到成品条码:" + codeStr);
// 1.刷新界面条码信息 // 1.刷新界面条码信息
// 全局变量赋值,mes条码扫描后使用 // 全局变量赋值,mes条码扫描后使用
code2Str = codeStr; // code2Str = codeStr;
RefreshCode2(codeStr); RefreshCode2(codeStr);
} }
@ -554,8 +556,8 @@ namespace Aucma.Core.CodeBinding.ViewModels
/// <summary> /// <summary>
/// 条码绑定 /// 条码绑定
/// </summary> /// </summary>
/// <param name="code1"></param> /// <param name="code1">MES码</param>
/// <param name="code2"></param> /// <param name="code2">SN码</param>
public void BindingCode(string code1,string code2) public void BindingCode(string code1,string code2)
{ {
try try
@ -656,8 +658,8 @@ namespace Aucma.Core.CodeBinding.ViewModels
} }
finally finally
{ {
code1Str = string.Empty; // code1Str = string.Empty;
code2Str = string.Empty; // code2Str = string.Empty;
} }
} }
@ -705,7 +707,7 @@ namespace Aucma.Core.CodeBinding.ViewModels
var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc")); var obj = PlcHelper.melsecList.FirstOrDefault(d => d.EquipName.Equals("条码绑定Plc"));
if (obj != null) if (obj != null)
{ {
log.Info("停止信号D7102写1"); log.Info("下发放行,停止信号D7102写0");
// 停止信号复位 // 停止信号复位
obj.plc.WriteInt16("D7102", "0"); obj.plc.WriteInt16("D7102", "0");
// 报警信号复位 // 报警信号复位

Loading…
Cancel
Save