Commit b237d193 刘韬

SO1340 定制添加删除含有NA字样的条码

1 个父辈 9a16b822
......@@ -43,9 +43,9 @@ namespace AutoScanAndLabel
this.tableLayoutPanel.ColumnCount = 2;
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 12.98701F));
this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 87.01299F));
this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2);
this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 0);
this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 1);
this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2);
this.tableLayoutPanel.Controls.Add(this.labelCompanyName, 1, 3);
this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 1, 4);
this.tableLayoutPanel.Controls.Add(this.okButton, 1, 5);
......@@ -97,6 +97,7 @@ namespace AutoScanAndLabel
this.labelCopyright.Name = "labelCopyright";
this.labelCopyright.Size = new System.Drawing.Size(354, 16);
this.labelCopyright.TabIndex = 21;
this.labelCopyright.Tag = "not";
this.labelCopyright.Text = "版权";
this.labelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
......@@ -124,6 +125,7 @@ namespace AutoScanAndLabel
this.textBoxDescription.Size = new System.Drawing.Size(354, 116);
this.textBoxDescription.TabIndex = 23;
this.textBoxDescription.TabStop = false;
this.textBoxDescription.Tag = "not";
this.textBoxDescription.Text = "说明";
//
// okButton
......
......@@ -18,7 +18,7 @@ namespace AutoScanAndLabel
this.Text = String.Format(crc.GetString("Res0001", "关于 {0}"), crc.GetString("App_Title", "自动贴标机"));
this.labelProductName.Text = AssemblyProduct;
this.labelVersion.Text = String.Format(crc.GetString("Res0002", "版本 {0}"), AssemblyVersion);
this.labelCopyright.Text = crc.GetString("Res0219", "版权 © 2021");
this.labelCopyright.Text = AssemblyCopyright;
this.labelCompanyName.Text = AssemblyCompany;
this.textBoxDescription.Text = AssemblyDescription;
}
......@@ -63,10 +63,10 @@ namespace AutoScanAndLabel
{
int days = Convert.ToInt32(strArray[2]);
int seconds = Convert.ToInt32(strArray[3]);
DateTime d1 = DateTime.Parse("2024-06-06");
//var newData = d1.AddDays(days);
//newData = newData.AddSeconds(seconds * 2);
updatetime = $"{crc.GetString("Res0220", "最后更新时间:")}" + d1.ToString("yyyy-MM-dd HH:mm:ss");
DateTime d1 = DateTime.Parse("2000-01-01");
var newData = d1.AddDays(days);
newData = newData.AddSeconds(seconds * 2);
updatetime = $"{crc.GetString("Res0220", "最后更新时间:")}" + newData.ToString("yyyy-MM-dd HH:mm:ss");
}
if (attributes.Length == 0)
......
......@@ -73,6 +73,7 @@ namespace AutoScanAndLabel
}
Environment.CurrentDirectory = Application.StartupPath;
XmlConfigurator.Configure();
Config.LoadMyConfig(typeof(Setting_Init));
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
......
......@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Neotel")]
[assembly: AssemblyProduct("NS200")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
......
using System;
using ConfigHelper;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
......@@ -74,5 +75,14 @@ namespace OnlineStore.Common
public static string SMB_StorageUnitValue = "SMB_StorageUnitValue";
[MyConfigComment("设备项目号")]
public static MyConfig<Procjet_NO> ProcjetNO = Procjet_NO.General;
}
public enum Procjet_NO
{
General,
SO1340
}
}
using CodeLibrary;
using ConfigHelper;
using Newtonsoft.Json;
using OnlineStore.Common;
using OnlineStore.Common.util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Windows.Forms;
using CodeLibrary;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using ConfigHelper;
using System.Reflection.Emit;
using System.Windows.Forms;
using static RemoteDecodeHelper_mod;
using System.Web;
using log4net;
using OnlineStore.Common.util;
using Newtonsoft.Json;
namespace DeviceLibrary
{
......@@ -29,7 +24,7 @@ namespace DeviceLibrary
public static List<string> codeTypeList = new List<string>();
public static List<string> hikNameList = new List<string>();
//是否使用扫码相机
public static bool iscode = Config.Get<bool>("isStartscanningcode", true);
public static bool iscode = Config.Get<bool>("isStartscanningcode", true);
private static char spiltChar = '#';
/// <summary>
/// 初始化摄像机名称和二维码类型
......@@ -53,7 +48,7 @@ namespace DeviceLibrary
}
LoadCamera(false);
iscode= Config.Get<bool>("isStartscanningcode", true);
iscode = Config.Get<bool>("isStartscanningcode", true);
LogUtil.info("加载到扫码相机");
if (!iscode)
{
......@@ -70,7 +65,7 @@ namespace DeviceLibrary
codeTypeList.Add(str.Trim());
}
CodeLibrary.HDCodeLearnHelper.LoadConfig("", CodeType);
}
}
//如果未加载到配置相机,自动配置
if (cameraNameList.Count <= 0 && hikNameList.Count > 0)
{
......@@ -88,7 +83,7 @@ namespace DeviceLibrary
catch (Exception ex)
{
LogUtil.error("解析摄像机配置出错:" + ex.StackTrace);
}
}
}
public static void LoadCamera(bool isReLoad)
{
......@@ -99,7 +94,7 @@ namespace DeviceLibrary
if (Camera._cam != null)
{
Camera._cam.CloseAll();
}
}
string camname = $"普通相机";
CameraType cameraType = CameraType.HIK;
if (iscode)
......@@ -141,10 +136,10 @@ namespace DeviceLibrary
{
Camera._cam.CloseAll();
}
[HandleProcessCorruptedStateExceptions]
public static (List<CodeInfo>, Dictionary<string, string>, string, Dictionary<string, int>) CameraScan(List<string> cameraNameList,int PlateW)
{
public static (List<CodeInfo>, Dictionary<string, string>, string, Dictionary<string, int>) CameraScan(List<string> cameraNameList, int PlateW)
{
List<CodeInfo> codeList = new List<CodeInfo>();
Dictionary<string, string> keyword = new Dictionary<string, string>();
string bitmapfilename = "";
......@@ -152,13 +147,13 @@ namespace DeviceLibrary
if (cameraNameList == null || cameraNameList.Count <= 0)
{
throw new Exception("CameraScan方法没有传入相机名称.");
}
}
try
{
LogUtil.info($"是否扫码相机:{iscode};相机名称:{string.Join(",", cameraNameList)};相机数量:{cameraNameList.Count}");
for (int i = 0; i < cameraNameList.Count(); i++)
{
var cameraName = cameraNameList[i];
var cameraName = cameraNameList[i];
if (cameraName.Trim().Equals(""))
{
continue;
......@@ -170,38 +165,49 @@ namespace DeviceLibrary
{
int retry = 0;
bool nohalcon = true;
retry:
retry:
_ = Camera._cam.CaptureOnImage(cameraName, out bmp, out List<CodeInfo> codes, nohalcon);
if (bmp == null)
{
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机,重试:"+ retry);
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机,重试:" + retry);
Camera._cam.CloseAll();
//LoadCamera(true);
retry++;
if (retry>2)
if (retry > 2)
continue;
goto retry;
}
bitmapfilename = SaveImageToFile("Ns200", cameraName, bmp);
WebResultCode webResult = null;
WebResultCode webResult = null;
if (iscode)
{
if (codes.Count==0)
if (codes.Count == 0)
{
//throw new FileNotFoundException("扫码相机未扫描到任何条码!");
LogUtil.error("扫码相机未扫描到任何条码!");
return (codeList, keyword, bitmapfilename, newpointanlge);
}
LogUtil.info("识别条码为:" + JsonConvert.SerializeObject(codes));
if (Setting_Init.ProcjetNO == Procjet_NO.SO1340)
{
var rc = codes.RemoveAll(c =>
{
var ss = c.CodeStr.Count(cs => cs == ';');
return (ss == 9 || ss == 10) && c.CodeStr.Contains(";NA;");
});
LogUtil.info($"SO1340 删除NA后条码 count:{rc} :" + JsonConvert.SerializeObject(codes));
}
LogUtil.info($"开始请求ns100服务");
webResult =NeoSacnRequest(BitmapToBase64(bmp), codes, PlateW, RobotManage.Config.Right_Batch_X, RobotManage.Config.Right_Batch_Y);
webResult = NeoSacnRequest(BitmapToBase64(bmp), codes, PlateW, RobotManage.Config.Right_Batch_X, RobotManage.Config.Right_Batch_Y);
}
else
{
//RemoteDecodeHelper_mod.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper_mod.RemoteDecodeParam();
//webResult = RemoteDecodeHelper_mod.DecodeRequest(bmp, remoteDecodeParam);
webResult = NeoSacnRequest_ordinary(BitmapToBase64(bmp), PlateW);
}
}
if (webResult == null)
{
LogUtil.info(" 【" + cameraName + "】调用外部转码失败");
......@@ -222,32 +228,32 @@ namespace DeviceLibrary
CodeType = code.CodeType,
Orientation = code.Angle,
};
codeList.Add(codeInfo);
codeList.Add(codeInfo);
}
foreach (var code in webResult.workCodeKeyword)
{
if (!keyword.ContainsKey(code.Key))
{
keyword.Add(code.Key, code.Value);
}
}
}
newpointanlge.Add("PointX",webResult.positionAngle.X);
newpointanlge.Add("PointX", webResult.positionAngle.X);
newpointanlge.Add("PointY", webResult.positionAngle.Y);
newpointanlge.Add("Angle", webResult.positionAngle.Angle);
if (webResult.positionAngle.IsCodeUsed!=null)
if (webResult.positionAngle.IsCodeUsed != null)
{
newpointanlge.Add("IsCodeUsed", Array.FindIndex(webResult.positionAngle.IsCodeUsed, x => x)); ;
}
LogUtil.info($"贴标数据X={webResult.positionAngle.X};Y={webResult.positionAngle.Y};角度={webResult.positionAngle.Angle}");
if (bmp!=null)
if (bmp != null)
{
string cid = ConfigHelper.Config.Get("CID");
_ = UnifiedDataHandler.PostSmfImageAsync(bmp,new Dictionary<string, string> { { "cid", cid+"_1" } });
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】" );
}
_ = UnifiedDataHandler.PostSmfImageAsync(bmp, new Dictionary<string, string> { { "cid", cid + "_1" } });
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】");
}
}
catch (AccessViolationException e)
{
......@@ -263,17 +269,17 @@ namespace DeviceLibrary
if (bmp != null)
{
bmp.Dispose();
}
}
}
}
}
catch (AccessViolationException e)
{
LogUtil.error( " 扫码出现AccessViolationException异常:" + e.ToString());
LogUtil.error(" 扫码出现AccessViolationException异常:" + e.ToString());
}
catch (Exception ex)
{
LogUtil.error( " 扫码出错:" + ex.ToString());
LogUtil.error(" 扫码出错:" + ex.ToString());
}
return (codeList, keyword, bitmapfilename, newpointanlge);
}
......@@ -349,7 +355,8 @@ namespace DeviceLibrary
/// <param name="pX"></param>
/// <param name="pY"></param>
/// <returns>x,y</returns>
static (int, int) PointRoate270(int imgWidth, int imgHeight, int pX, int pY) {
static (int, int) PointRoate270(int imgWidth, int imgHeight, int pX, int pY)
{
int x = pY;
int y = imgWidth - pX;
return (x, y);
......@@ -357,7 +364,7 @@ namespace DeviceLibrary
private static string SaveImageToFile(string deviceName, string cameraName, Bitmap bitmap)
{
string date = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + DateTime.Now.Millisecond;
string dire = Application.StartupPath+@"\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string dire = Application.StartupPath + @"\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp";
try
{
......@@ -462,6 +469,6 @@ namespace DeviceLibrary
{
return "";
}
}
}
}
}
\ No newline at end of file
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!