Commit 0fd210bf LN

扫码时如果未找到有效条码,把图片保存到文件

1 个父辈 9d181bed
......@@ -95,11 +95,10 @@ namespace OnlineStore.DeviceLibrary
{
Camera._cam.CloseAll();
}
private static int ScanCount = 0;
private static int codeCount = ConfigAppSettings.GetIntValue(Setting_Init.CodeCount);
[HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan( string deviceName ,params string[] cameraList)
public static List<string> CameraScan(string deviceName, params string[] cameraList)
{
List<string> codeList = new List<string>();
if (cameraList == null || cameraList.Length <= 0)
......@@ -118,10 +117,10 @@ namespace OnlineStore.DeviceLibrary
DateTime startTime = DateTime.Now;
if (deviceName != "")
{
LogUtil.debug (deviceName + " 【" + cameraName + "】开始取图片");
LogUtil.debug(deviceName + " 【" + cameraName + "】开始取图片");
}
HalconDotNet.HObject ho_Image = null;
bool findRightCode = false;
try
{
ho_Image = Camera._cam.CaptureOnImage(cameraName);
......@@ -144,7 +143,7 @@ namespace OnlineStore.DeviceLibrary
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, codeCount, GetCodeParamFilePath(codeType), codeType);
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), codeCount, 1500);
}
foreach (CodeInfo c in cc)
{
......@@ -153,17 +152,20 @@ namespace OnlineStore.DeviceLibrary
{
codeList.Add(str);
r = r + "##" + str;
if (!findRightCode)
{
findRightCode = HasRightCode(str);
}
}
}
if (String.IsNullOrEmpty(r))
}
if (!findRightCode)
{
// SaveImageToFile(deviceName, cameraName, bit);
SaveImageToFile(deviceName, cameraName, ho_Image);
}
if (deviceName != "" || r != "")
{
LogUtil.info(deviceName + " 【" + cameraName + "】扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】" + ScanCount + " :" + r);
LogUtil.info(deviceName + " 【" + cameraName + "】扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】[" + findRightCode + "]" + ScanCount + " :" + r);
}
}
catch (AccessViolationException e)
......@@ -197,10 +199,29 @@ namespace OnlineStore.DeviceLibrary
}
return codeList;
}
private static void SaveImageToFile(string deviceName, string cameraName, HalconDotNet.HObject bitmap)
{
string date = deviceName.Trim().Replace('_', '-') + "-" + DateTime.Now.ToString("yyyyMMdd-HHmmss") + "-" + DateTime.Now.Millisecond.ToString().PadLeft(4, '0');
string dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp";
try
{
if (!Directory.Exists(dire))
{
Directory.CreateDirectory(dire);
}
bitmap.WriteObject(dire + iamgeName);
LogUtil.info(deviceName + " 【" + cameraName + "】扫码失败,保存图片到【" + dire + iamgeName + "】成功");
}
catch (Exception ex)
{
LogUtil.error("保存" + deviceName + " 【" + cameraName + "】的图片到【" + dire + iamgeName + "】出错" + ex.ToString());
}
}
private static void SaveImageToFile(string deviceName, string cameraName, Bitmap bitmap)
{
string date = DateTime.Now.ToString("HH-mm-ss-") + DateTime.Now.Millisecond;
string date = deviceName.Trim().Replace('_', '-') + "-" + DateTime.Now.ToString("HH-mm-ss-") + DateTime.Now.Millisecond;
string dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp";
try
......@@ -219,7 +240,30 @@ namespace OnlineStore.DeviceLibrary
}
}
public static bool HasRightCode(params string[] codes)
{
//分号分割后长度=4,L,E,B,R
try
{
foreach (string code in codes)
{
string[] strarray = code.Split(';');
if (strarray.Length == 4)
{
if (strarray[0].StartsWith("L") &&
strarray[1].StartsWith("E") &&
strarray[2].StartsWith("B"))
{
return true;
}
}
}
}
catch (Exception ex)
{
}
return false;
}
public static string GetCodeParamFilePath(string codePath)
{
string appPath = Application.StartupPath;
......@@ -265,27 +309,18 @@ namespace OnlineStore.DeviceLibrary
message = asciiEncoding.GetString(newBytes.ToArray());
return message;
}
private static bool IsRightCode(string code)
{
//分号分割后长度=4,L,E,B,R
try
public static string ProcessCode(List<string> codeList)
{
string[] strarray = code.Split(';');
if (strarray.Length == 4)
string code = "";
foreach (string cc in codeList)
{
if (strarray[0].StartsWith("L") &&
strarray[1].StartsWith("E") &&
strarray[2].StartsWith("B") &&
strarray[3].StartsWith("R"))
if (string.IsNullOrEmpty(cc))
{
return true;
}
}
continue;
}
catch (Exception ex)
{
code += cc + "##";
}
return false;
return ReplaceCode(code);
}
public static string GetValidCode(List<string> codeList)
{
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!