Commit 66068c21 张东亮

扫码使用服务

1 个父辈 3a0334d4
...@@ -33,6 +33,9 @@ ...@@ -33,6 +33,9 @@
<Prefer32Bit>false</Prefer32Bit> <Prefer32Bit>false</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ConfigHelper">
<HintPath>..\XLRStoreClient\bin\Debug\ConfigHelper.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL"> <Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<HintPath>..\..\packages\log4net.2.0.12\lib\net40\log4net.dll</HintPath> <HintPath>..\..\packages\log4net.2.0.12\lib\net40\log4net.dll</HintPath>
</Reference> </Reference>
......
using System; using ConfigHelper;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
...@@ -125,5 +126,9 @@ namespace OnlineStore.Common ...@@ -125,5 +126,9 @@ namespace OnlineStore.Common
public static string Device_HumidityLimited = "Device_HumidityLimited"; public static string Device_HumidityLimited = "Device_HumidityLimited";
public static string Device_TemptureAdjust = "Device_TemptureAdjust"; public static string Device_TemptureAdjust = "Device_TemptureAdjust";
public static string Device_TemptureLimited = "Device_TemptureLimited"; public static string Device_TemptureLimited = "Device_TemptureLimited";
[MyConfigComment("筛选条码数量")]
public static MyConfig<int> Camera_QRCodeCount = 3;
[MyConfigComment("解码的超时时间")]
public static MyConfig<int> Camera_CodeTimeOut = 1000;
} }
} }
...@@ -48,8 +48,9 @@ ...@@ -48,8 +48,9 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\dll\Client.dll</HintPath> <HintPath>..\..\dll\Client.dll</HintPath>
</Reference> </Reference>
<Reference Include="CodeLibrary"> <Reference Include="CodeLibrary, Version=1.0.8787.29577, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\dll\CodeLibrary.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\Standalone\MIMO_G2\DLL\CodeLibrary.dll</HintPath>
</Reference> </Reference>
<Reference Include="ConfigHelper"> <Reference Include="ConfigHelper">
<HintPath>..\..\..\..\SharedRefDll\Neotel\ConfigHelper.dll</HintPath> <HintPath>..\..\..\..\SharedRefDll\Neotel\ConfigHelper.dll</HintPath>
......
...@@ -20,7 +20,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -20,7 +20,8 @@ namespace OnlineStore.DeviceLibrary
public static List<string> codeTypeList = new List<string>(); public static List<string> codeTypeList = new List<string>();
public static List<string> balserNameList = new List<string>(); public static List<string> balserNameList = new List<string>();
public static List<string> hikNameList = new List<string>(); public static List<string> hikNameList = new List<string>();
private static int QRCodeCount = Setting_Init.Camera_QRCodeCount;
private static int CodeTimeOut = Setting_Init.Camera_CodeTimeOut;
private static char spiltChar = '#'; private static char spiltChar = '#';
/// <summary> /// <summary>
/// 初始化摄像机名称和二维码类型 /// 初始化摄像机名称和二维码类型
...@@ -104,11 +105,140 @@ namespace OnlineStore.DeviceLibrary ...@@ -104,11 +105,140 @@ namespace OnlineStore.DeviceLibrary
public static List<string> CameraScan(string cameraName, string deviceName, bool findRightCodeBreak = false, int timeOut = 1500) public static List<string> CameraScan(string cameraName, string deviceName, bool findRightCodeBreak = false, int timeOut = 1500)
{ {
List<string> nameList = new List<string>() { cameraName }; List<string> nameList = new List<string>() { cameraName };
return CameraScan(nameList, deviceName, findRightCodeBreak, timeOut); return CameraScan(nameList, deviceName);
} }
private static int ScanCount = 0; private static int ScanCount = 0;
private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount); private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount);
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static List<CodeInfo> CameraScan(List<string> cameraNameList)
{
HashSet<string> codestr = new HashSet<string>();
List<CodeInfo> codeList = new List<CodeInfo>();
// string bitmapfilename = "";
if (cameraNameList == null || cameraNameList.Count <= 0)
{
throw new Exception("CameraScan方法没有传入相机名称.");
}
try
{
Task[] cameraTask = new Task[cameraNameList.Count()];
for (int ii = 0; ii < cameraNameList.Count(); ii++)
{
var cameraName = cameraNameList[ii];
var idx = ii;
cameraTask[ii] = Task.Run(new Action(() =>
{
int retrytime = 0;
retry:
LogUtil.info($"【" + cameraName + "】开始取图片");
if (cameraName.Trim().Equals(""))
{
return;
}
DateTime startTime = DateTime.Now;
HalconDotNet.HObject ho_Image = null;
Bitmap bmp = null;
try
{
bool nohalcon = true;
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp, nohalcon);
if (bmp == null)
{
if (retrytime > 2)
return;
retrytime++;
LoadCamera(true);
LogUtil.info($"bitmap为空重试第{retrytime}次");
Task.Delay(1500).Wait();
goto retry;
}
//HalconDotNet.HOperatorSet.RotateImage()
if (ho_Image == null && !nohalcon)
{
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
LoadCamera(true);
return;
}
// if (idx == 0)
// camera_event?.Invoke(null, bmp);
LogUtil.info(" 【" + cameraName + "】取图片完成,开始扫码");
string r = "";
RemoteDecodeHelper.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper.RemoteDecodeParam
{
codeTypeList = codeTypeList.ToArray(),
codeCount = QRCodeCount,
timeout = CodeTimeOut
};
List<CodeInfo> cc = new List<CodeInfo>();
cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam);
if (cc != null && cc.Count > 0)
{
lock (codeList)
{
cc.ForEach((c) =>
{
c.CodeStr = CodeManager.ReplaceCode(c.CodeStr);
if (!codestr.Contains(c.CodeStr))
{
codeList.Add(c);
codestr.Add(c.CodeStr);
r += "##" + c.CodeStr;
}
});
}
}
else
{
SaveImageToFile("mimo", cameraName, bmp);
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
}
finally
{
if (ho_Image != null)
{
ho_Image.Dispose();
}
if (bmp != null)
bmp.Dispose();
}
}));
Task.Delay(ii * 700).Wait();
}
while (!cameraTask[0].IsCompleted || !cameraTask[1].IsCompleted)
{
Application.DoEvents();
Thread.Sleep(100);
}
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常:" + e.ToString());
//throw new Exception("扫码出现AccessViolationException异常");
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
//throw new Exception("扫码出错");
}
return codeList;
}
[HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(List<string> cameraList, string deviceName, bool findRightCodeBreak = false, int timeOut = 1500) public static List<string> CameraScan(List<string> cameraList, string deviceName, bool findRightCodeBreak = false, int timeOut = 1500)
{ {
bool isPreScan = deviceName.EndsWith("预扫码"); bool isPreScan = deviceName.EndsWith("预扫码");
......
...@@ -600,7 +600,7 @@ namespace OnlineStore.XLRStore ...@@ -600,7 +600,7 @@ namespace OnlineStore.XLRStore
{ {
Camera._cam.CloseAll(); Camera._cam.CloseAll();
} }
CodeLibrary.FrmCodeDecode frm = new CodeLibrary.FrmCodeDecode(false); CodeLibrary.FrmCodeDecode frm = new CodeLibrary.FrmCodeDecode();
frm.ShowDialog(); frm.ShowDialog();
frm.Dispose(); frm.Dispose();
} }
......
...@@ -63,8 +63,9 @@ ...@@ -63,8 +63,9 @@
<Reference Include="Client"> <Reference Include="Client">
<HintPath>..\..\dll\Client.dll</HintPath> <HintPath>..\..\dll\Client.dll</HintPath>
</Reference> </Reference>
<Reference Include="CodeLibrary"> <Reference Include="CodeLibrary, Version=1.0.8182.32076, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\dll\CodeLibrary.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\..\Standalone\MIMO_G2\DLL\CodeLibrary.dll</HintPath>
</Reference> </Reference>
<Reference Include="ConfigHelper, Version=1.0.0.2, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="ConfigHelper, Version=1.0.0.2, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!