|
|
|
@ -32,6 +32,10 @@ namespace Aucma.Core.CodeBinding.Business
|
|
|
|
|
public static MvCodeReader LinerDevice = null;
|
|
|
|
|
public static DateTime ShellLiveTime = DateTime.Now;
|
|
|
|
|
public static DateTime LinerLiveTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
private static string MesCode = string.Empty;
|
|
|
|
|
private static string SNCode = string.Empty;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -40,7 +44,7 @@ namespace Aucma.Core.CodeBinding.Business
|
|
|
|
|
|
|
|
|
|
#region 条码绑定上位机委托事件
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 刷新扫码器状态
|
|
|
|
@ -56,8 +60,15 @@ namespace Aucma.Core.CodeBinding.Business
|
|
|
|
|
/// code1扫码信息刷新
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Code1"></param>
|
|
|
|
|
public delegate void BindingReceiveCode(string code, string ip);
|
|
|
|
|
public static event BindingReceiveCode? BindingReceiveCodeEvent;
|
|
|
|
|
public delegate void ReceiveCode(string code, string ip);
|
|
|
|
|
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>
|
|
|
|
|
/// NoRead通知
|
|
|
|
@ -91,6 +102,8 @@ namespace Aucma.Core.CodeBinding.Business
|
|
|
|
|
log.Info(DateTime.Now + ":SN--->No Read 处理");
|
|
|
|
|
//更新扫码器存活时间
|
|
|
|
|
ShellLiveTime = DateTime.Now;
|
|
|
|
|
SNCode = string.Empty;
|
|
|
|
|
MesCode = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
for (Int32 i = 0; i < stBcrResult.nCodeNum; i++)
|
|
|
|
|
{
|
|
|
|
@ -106,12 +119,14 @@ namespace Aucma.Core.CodeBinding.Business
|
|
|
|
|
string strCode = Encoding.GetEncoding("GB2312").GetString(stBcrResult.stBcrInfoEx2[i].chCode);
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":SN扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
log.Info(DateTime.Now + ":SN扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
|
|
|
|
|
//更新扫码器存活时间
|
|
|
|
|
ShellLiveTime = DateTime.Now;
|
|
|
|
|
BindingReceiveCodeEvent?.Invoke(strCode.Trim().TrimEnd('\0'), ShellScannerIp);
|
|
|
|
|
// 业务处理
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//更新扫码器存活时间
|
|
|
|
|
ShellLiveTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
SNCode = strCode.Trim().TrimEnd('\0');
|
|
|
|
|
ReceiveCodeEvent?.Invoke(strCode.Trim().TrimEnd('\0'), ShellScannerIp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -127,51 +142,73 @@ namespace Aucma.Core.CodeBinding.Business
|
|
|
|
|
|
|
|
|
|
public static void LinerImageCallbackFunc(IntPtr pData, IntPtr pstFrameInfoEx2, IntPtr pUser)
|
|
|
|
|
{
|
|
|
|
|
var stFrameInfo = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2));
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var stFrameInfo = (MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2)Marshal.PtrToStructure(pstFrameInfoEx2, typeof(MvCodeReader.MV_CODEREADER_IMAGE_OUT_INFO_EX2));
|
|
|
|
|
|
|
|
|
|
MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2 stBcrResult = (MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)Marshal.PtrToStructure(stFrameInfo.UnparsedBcrList.pstCodeListEx2, typeof(MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2));
|
|
|
|
|
MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2 stBcrResult = (MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2)Marshal.PtrToStructure(stFrameInfo.UnparsedBcrList.pstCodeListEx2, typeof(MvCodeReader.MV_CODEREADER_RESULT_BCR_EX2));
|
|
|
|
|
|
|
|
|
|
// Console.WriteLine("CodeNum[" + Convert.ToString(stBcrResult.nCodeNum) + "]");
|
|
|
|
|
if (stBcrResult.nCodeNum == 0)
|
|
|
|
|
{
|
|
|
|
|
NoReadEvent?.Invoke(LinerScannerIp);
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":mes--->No Read 处理");
|
|
|
|
|
log.Info(DateTime.Now + ":mes--->No Read 处理");
|
|
|
|
|
// 更新存活时间
|
|
|
|
|
LinerLiveTime = DateTime.Now;
|
|
|
|
|
}
|
|
|
|
|
for (Int32 i = 0; i < stBcrResult.nCodeNum; i++)
|
|
|
|
|
{
|
|
|
|
|
bool bIsValidUTF8 = IsTextUTF8(stBcrResult.stBcrInfoEx2[i].chCode);
|
|
|
|
|
if (bIsValidUTF8)
|
|
|
|
|
// Console.WriteLine("CodeNum[" + Convert.ToString(stBcrResult.nCodeNum) + "]");
|
|
|
|
|
if (stBcrResult.nCodeNum == 0)
|
|
|
|
|
{
|
|
|
|
|
string strCode = Encoding.UTF8.GetString(stBcrResult.stBcrInfoEx2[i].chCode);
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
NoReadEvent?.Invoke(LinerScannerIp);
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":mes--->No Read 处理");
|
|
|
|
|
log.Info(DateTime.Now + ":mes--->No Read 处理");
|
|
|
|
|
// 更新存活时间
|
|
|
|
|
LinerLiveTime = DateTime.Now;
|
|
|
|
|
SNCode = string.Empty;
|
|
|
|
|
MesCode = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
for (Int32 i = 0; i < stBcrResult.nCodeNum; i++)
|
|
|
|
|
{
|
|
|
|
|
string strCode = Encoding.GetEncoding("GB2312").GetString(stBcrResult.stBcrInfoEx2[i].chCode);
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":mes扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
log.Info(DateTime.Now + ":mes扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
|
|
|
|
|
bool bIsValidUTF8 = IsTextUTF8(stBcrResult.stBcrInfoEx2[i].chCode);
|
|
|
|
|
if (bIsValidUTF8)
|
|
|
|
|
{
|
|
|
|
|
string strCode = Encoding.UTF8.GetString(stBcrResult.stBcrInfoEx2[i].chCode);
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string strCode = Encoding.GetEncoding("GB2312").GetString(stBcrResult.stBcrInfoEx2[i].chCode);
|
|
|
|
|
Console.WriteLine(DateTime.Now + ":mes扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
log.Info(DateTime.Now + ":mes扫码器==>Get CodeNum: " + "CodeNum[" + i.ToString() + "], CodeString[" + strCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
|
|
|
|
|
// 更新存活时间
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MvCodeReader.MV_CODEREADER_OCR_INFO_LIST stOcrInfo = (MvCodeReader.MV_CODEREADER_OCR_INFO_LIST)Marshal.PtrToStructure(stFrameInfo.UnparsedOcrList.pstOcrList, typeof(MvCodeReader.MV_CODEREADER_OCR_INFO_LIST));
|
|
|
|
|
MvCodeReader.MV_CODEREADER_OCR_INFO_LIST stOcrInfo = (MvCodeReader.MV_CODEREADER_OCR_INFO_LIST)Marshal.PtrToStructure(stFrameInfo.UnparsedOcrList.pstOcrList, typeof(MvCodeReader.MV_CODEREADER_OCR_INFO_LIST));
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("ocrAllNum[" + Convert.ToString(stOcrInfo.nOCRAllNum) + "]");
|
|
|
|
|
for (int i = 0; i < stOcrInfo.nOCRAllNum; i++)
|
|
|
|
|
Console.WriteLine("ocrAllNum[" + Convert.ToString(stOcrInfo.nOCRAllNum) + "]");
|
|
|
|
|
for (int i = 0; i < stOcrInfo.nOCRAllNum; i++)
|
|
|
|
|
{
|
|
|
|
|
string strOcrCharCode = Encoding.UTF8.GetString(stOcrInfo.stOcrRowInfo[i].chOcr);
|
|
|
|
|
Console.WriteLine("Get OcrInfo:" + "ocrNum[" + i.ToString() + "], ocrLen[" + Convert.ToString(stOcrInfo.stOcrRowInfo[i].nOcrLen) + "], ocrChar[" + strOcrCharCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
string strOcrCharCode = Encoding.UTF8.GetString(stOcrInfo.stOcrRowInfo[i].chOcr);
|
|
|
|
|
Console.WriteLine("Get OcrInfo:" + "ocrNum[" + i.ToString() + "], ocrLen[" + Convert.ToString(stOcrInfo.stOcrRowInfo[i].nOcrLen) + "], ocrChar[" + strOcrCharCode.Trim().TrimEnd('\0') + "]");
|
|
|
|
|
log.Info("mes扫码器回调函数异常:" + ex.Message.ToString());
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
MesCode = string.Empty;
|
|
|
|
|
SNCode = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void Shell()
|
|
|
|
|
{
|
|
|
|
|