Commit 291c42bb 刘韬

1

1 个父辈 f436ade8
...@@ -26,14 +26,21 @@ namespace OnlineStore.Common ...@@ -26,14 +26,21 @@ namespace OnlineStore.Common
} }
var ls = File.ReadAllText(algopnFile); var ls = File.ReadAllText(algopnFile);
algopnList = JsonConvert.DeserializeObject<Dictionary<string, string>>(ls); algopnList = JsonConvert.DeserializeObject<Dictionary<string, string>>(ls);
if (algopnList == null)
algopnList = new Dictionary<string, string>();
} }
static void SaveFile() static void SaveFile()
{ {
Directory.CreateDirectory(Path.GetDirectoryName(algopnFile)); Directory.CreateDirectory(Path.GetDirectoryName(algopnFile));
string s = JsonConvert.SerializeObject(algopnList); File.WriteAllText(algopnFile + ".ready", JsonConvert.SerializeObject(algopnList));
File.WriteAllText(algopnFile, s); try
File.Copy(algopnFile, algopnFile + "."+DateTime.Now.ToShortDateString(), true); {
File.Delete(algopnFile + ".bck");
File.Move(algopnFile, algopnFile + ".bck");
File.Move(algopnFile + ".ready", algopnFile);
}
catch { }
} }
public static void Set(string pn, string value, double? finetuning = null) public static void Set(string pn, string value, double? finetuning = null)
{ {
...@@ -42,7 +49,7 @@ namespace OnlineStore.Common ...@@ -42,7 +49,7 @@ namespace OnlineStore.Common
if (string.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
return; return;
//Common.LOG.Info($"set pnalgo pn:{pn}, algo:{value}, finetuning:{finetuning}"); LogUtil.info($"set pnalgo pn:{pn}, algo:{value}, finetuning:{finetuning}");
if (finetuning != null) if (finetuning != null)
value = value + "," + finetuning.ToString(); value = value + "," + finetuning.ToString();
...@@ -58,6 +65,7 @@ namespace OnlineStore.Common ...@@ -58,6 +65,7 @@ namespace OnlineStore.Common
{ {
hasMatch = false; hasMatch = false;
finetuning = null; finetuning = null;
if (algopnList.ContainsKey(pn)) if (algopnList.ContainsKey(pn))
{ {
hasMatch = true; hasMatch = true;
...@@ -65,9 +73,10 @@ namespace OnlineStore.Common ...@@ -65,9 +73,10 @@ namespace OnlineStore.Common
if (value.IndexOf(",") > 0) if (value.IndexOf(",") > 0)
{ {
var vs = value.Split(','); var vs = value.Split(',');
if (double.TryParse(vs[1], out double result))
if (vs.Length == 3 && double.TryParse(vs[2], out double result))
{ {
value = vs[0]; value = vs[0] + "," + vs[1];
finetuning = result; finetuning = result;
} }
} }
......
...@@ -194,130 +194,105 @@ namespace DeviceLibrary ...@@ -194,130 +194,105 @@ namespace DeviceLibrary
try try
{ {
Task[] cameraTask = new Task[cameraNameList.Count()];
for (int ii = 0; ii < cameraNameList.Count(); ii++) var cameraName = cameraNameList[0];
int retrytime = 0;
retry:
LogUtil.info($"【" + cameraName + "】开始取图片");
if (cameraName.Trim().Equals(""))
{ {
var cameraName = cameraNameList[ii]; return (new List<CodeInfo>(), bitmapfilename);
var idx = ii; }
cameraTask[ii] = Task.Run(new Action(() => 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)
{ {
int retrytime = 0; if (retrytime > 2)
retry: return (new List<CodeInfo>(), bitmapfilename);
LogUtil.info($"【" + cameraName + "】开始取图片"); retrytime++;
if (cameraName.Trim().Equals("")) LoadCamera(true);
{ LogUtil.info($"bitmap为空重试第{retrytime}次");
return; Task.Delay(1500).Wait();
} goto retry;
DateTime startTime = DateTime.Now; }
HalconDotNet.HObject ho_Image = null; //HalconDotNet.HOperatorSet.RotateImage()
Bitmap bmp = null; if (ho_Image == null && !nohalcon)
try {
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
LoadCamera(true);
return (new List<CodeInfo>(), bitmapfilename);
}
//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>();
bool hasRightCode = false;
cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam);
if (cc != null)
{
LogUtil.info("返回条码:" + string.Join("#", cc.Select(c => { return c.CodeType + ":" + c.CodeStr; }).ToArray()));
cc.ForEach((c) =>
{ {
bool nohalcon = true; codeList.Add(c);
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp, nohalcon); r += "##" + c.CodeStr;
if (bmp == null) });
{ LogUtil.info("Camera 01");
if (retrytime > 2) if (codeList.Count > 0 && cc.Find(c => c.CodeStr.StartsWith("S20")) != null)
return;
retrytime++;
CloseCamera(cameraName);
LogUtil.info($"bitmap为空重试第{retrytime}次");
Task.Delay(1500).Wait();
goto retry;
}
//HalconDotNet.HOperatorSet.RotateImage()
if (ho_Image == null && !nohalcon)
{
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName);
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>();
bool hasRightCode = false;
cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam);
if (cc != null)
{
lock (codeList)
{
LogUtil.info("返回条码:" + string.Join("#" , cc.Select(c => { return c.CodeType+":"+c.CodeStr; }).ToArray()));
cc.ForEach((c) =>
{
//c.CodeStr = CodeManager.ReplaceCode(c.CodeStr);
//if ((c.CodeStr.StartsWith("S20") && c.CodeType== "Data Matrix ECC 200") || c.CodeStr.StartsWith("AT"))
{
//if (!codestr.Contains(c.CodeStr))
{
codeList.Add(c);
//codestr.Add(c.CodeStr);
r += "##" + c.CodeStr;
}
}
});
if (codeList.Count > 0 && cc.Find(c => c.CodeStr.StartsWith("S20")) != null)
{
hasRightCode = true;
}
else {
codeList.Clear();
}
}
}
//if (!hasRightCode)
{
bitmapfilename = SaveImageToFile("mimo", cameraName, bmp);
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
}
catch (AccessViolationException e)
{ {
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString()); hasRightCode = true;
Camera._cam.Close(cameraName);
// GC.Collect();
} }
catch (Exception ex) else
{ {
LogUtil.error(" 扫码出错:" + ex.ToString()); codeList.Clear();
} }
finally }
{ //if (!hasRightCode)
if (ho_Image != null) {
{ bitmapfilename = SaveImageToFile("mimo", cameraName, bmp);
ho_Image.Dispose(); }
} LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
if (bmp != null)
bmp.Dispose();
}
}));
Task.Delay(ii * 700).Wait();
} }
catch (AccessViolationException e)
while (!cameraTask[0].IsCompleted)
{ {
Application.DoEvents(); LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Thread.Sleep(100); 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();
} }
} }
catch (AccessViolationException e) catch (AccessViolationException e)
{ {
LogUtil.error( " 扫码出现AccessViolationException异常:" + e.ToString()); LogUtil.error(" 扫码出现AccessViolationException异常:" + e.ToString());
//throw new Exception("扫码出现AccessViolationException异常"); //throw new Exception("扫码出现AccessViolationException异常");
// GC.Collect(); // GC.Collect();
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error( " 扫码出错:" + ex.ToString()); LogUtil.error(" 扫码出错:" + ex.ToString());
//throw new Exception("扫码出错"); //throw new Exception("扫码出错");
} }
return (codeList, bitmapfilename); return (codeList, bitmapfilename);
......
...@@ -14,8 +14,7 @@ namespace DeviceLibrary ...@@ -14,8 +14,7 @@ namespace DeviceLibrary
ZebraPrinterHelper.ZebraManger zebraManger; ZebraPrinterHelper.ZebraManger zebraManger;
string Port; string Port;
public PrinterHelper() { public PrinterHelper() {
print = new Asa.PrintLabel(Application.StartupPath + "\\Label",300); print = new Asa.PrintLabel(Application.StartupPath + "\\Label", 300);
} }
public bool Connection(string port) { public bool Connection(string port) {
...@@ -28,7 +27,10 @@ namespace DeviceLibrary ...@@ -28,7 +27,10 @@ namespace DeviceLibrary
return false; return false;
} }
else else
{
print = new Asa.PrintLabel(Application.StartupPath + "\\Label", zebraManger.PrinterDPI);
return true; return true;
}
} }
public void Close() { public void Close() {
zebraManger.Close(); zebraManger.Close();
......
...@@ -302,7 +302,7 @@ namespace DeviceLibrary ...@@ -302,7 +302,7 @@ namespace DeviceLibrary
} }
else { else {
if (angleblock[180].Count==0) if (angleblock[180].Count==0)
return rightangle+180; return rightangle+120;
else else
return GetAngleAvg(angleblock[180]); return GetAngleAvg(angleblock[180]);
} }
......
...@@ -150,7 +150,7 @@ namespace DeviceLibrary ...@@ -150,7 +150,7 @@ namespace DeviceLibrary
} }
else else
{ {
LogUtil.info($"{wait.AxisInfo.DeviceName},继续上升:{wait.TargetPosition}"); LogUtil.info($"{wait.AxisInfo.Explain},继续上升:{wait.TargetPosition}");
axisBean.AbsMove(null, wait.TargetPosition, wait.TargetSpeed); axisBean.AbsMove(null, wait.TargetPosition, wait.TargetSpeed);
wait.IsEnd = false; wait.IsEnd = false;
} }
......
...@@ -59,6 +59,7 @@ namespace DeviceLibrary ...@@ -59,6 +59,7 @@ namespace DeviceLibrary
{ {
Setting_Init.Temp_Last_Reel_Height = 8; Setting_Init.Temp_Last_Reel_Height = 8;
} }
scantrytimes = 0;
} }
else { else {
Msg.add("点料机放料位没有检测到料盘",MsgLevel.alarm); Msg.add("点料机放料位没有检测到料盘",MsgLevel.alarm);
...@@ -71,19 +72,21 @@ namespace DeviceLibrary ...@@ -71,19 +72,21 @@ namespace DeviceLibrary
ScanCode(); ScanCode();
CountMoveInfo.log($"开始扫码"); CountMoveInfo.log($"开始扫码");
break; break;
case MoveStep.Count_03: case MoveStep.Count_03:
CountMoveInfo.NextMoveStep(MoveStep.Count_04);
int retrytime = 0; int retrytime = 0;
retry: retry:
if (RobotManage.XRay.Start()) if (RobotManage.XRay.Start())
{ {
CountMoveInfo.NextMoveStep(MoveStep.Count_04);
CountMoveInfo.log($"打开X光"); CountMoveInfo.log($"打开X光");
CountMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(Setting_Init.XRay_Light_Delay)); CountMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(Setting_Init.XRay_Light_Delay));
return;
} }
else { else {
if (RobotManage.XRay.Start()) if (RobotManage.XRay.Start())
{ {
CountMoveInfo.log($"打开X光第2次"); CountMoveInfo.NextMoveStep(MoveStep.Count_04);
CountMoveInfo.log($"打开X光第{retrytime}次");
CountMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(Setting_Init.XRay_Light_Delay)); CountMoveInfo.WaitList.Add(WaitResultInfo.WaitTime(Setting_Init.XRay_Light_Delay));
return; return;
} }
...@@ -138,8 +141,11 @@ namespace DeviceLibrary ...@@ -138,8 +141,11 @@ namespace DeviceLibrary
CountMoveInfo.MoveParam.PN = CountMoveInfo.MoveParam.codeInfos.Where(c=>c.CodeStr.StartsWith("AT")).FirstOrDefault()?.CodeStr; CountMoveInfo.MoveParam.PN = CountMoveInfo.MoveParam.codeInfos.Where(c=>c.CodeStr.StartsWith("AT")).FirstOrDefault()?.CodeStr;
if (string.IsNullOrWhiteSpace(CountMoveInfo.MoveParam.PN)) { if (string.IsNullOrWhiteSpace(CountMoveInfo.MoveParam.PN)) {
var hc =CountMoveInfo.MoveParam.codeInfos.Where(c => Regex.IsMatch(c.CodeStr, @"(?:@@|-)(AT\w*)(?:@@|-)")).FirstOrDefault()?.CodeStr; var hc =CountMoveInfo.MoveParam.codeInfos.Where(c => Regex.IsMatch(c.CodeStr, @"(?:@@|-)(AT\w*)(?:@@|-)")).FirstOrDefault()?.CodeStr;
var pn = Regex.Match(hc, "@@(AT\\w*)@@").Groups[1].Value; if (!string.IsNullOrEmpty(hc))
CountMoveInfo.MoveParam.PN = pn; {
var pn = Regex.Match(hc, "@@(AT\\w*)@@").Groups[1].Value;
CountMoveInfo.MoveParam.PN = pn;
}
} }
//var xx = CountMoveInfo.MoveParam.codeInfos.Find(c=> { return c.CodeStr.StartsWith("S20") && c.CodeType == "barcode"; }); //var xx = CountMoveInfo.MoveParam.codeInfos.Find(c=> { return c.CodeStr.StartsWith("S20") && c.CodeType == "barcode"; });
//if (xx != null) //if (xx != null)
...@@ -280,7 +286,7 @@ namespace DeviceLibrary ...@@ -280,7 +286,7 @@ namespace DeviceLibrary
IOMove(IO_Type.Counting_Camera_Led, IO_VALUE.HIGH); IOMove(IO_Type.Counting_Camera_Led, IO_VALUE.HIGH);
var (LastCodeList, filename) = CodeManager.CameraScan(CodeManager.hikNameList); var (LastCodeList, filename) = CodeManager.CameraScan(CodeManager.hikNameList);
LogUtil.info("扫码完成:"+ filename);
return (LastCodeList, filename); return (LastCodeList, filename);
})); }));
} }
......
...@@ -197,6 +197,7 @@ namespace DeviceLibrary ...@@ -197,6 +197,7 @@ namespace DeviceLibrary
case MoveStep.InCarOut_01: case MoveStep.InCarOut_01:
InCarMoveInfo.NextMoveStep(MoveStep.InCarOut_02); InCarMoveInfo.NextMoveStep(MoveStep.InCarOut_02);
incarProcessFinish = true;
InCarMoveInfo.log($"料串下降到P1点"); InCarMoveInfo.log($"料串下降到P1点");
Loading_Batch_Axis.AbsMove(InCarMoveInfo, Config.Loading_Batch_Axis_P1, Config.Loading_Batch_Axis_P1_speed); Loading_Batch_Axis.AbsMove(InCarMoveInfo, Config.Loading_Batch_Axis_P1, Config.Loading_Batch_Axis_P1_speed);
InCarMoveInfo.WaitList.Add(WaitResultInfo.WaitMsg("料串正在下降", MsgLevel.warning)); InCarMoveInfo.WaitList.Add(WaitResultInfo.WaitMsg("料串正在下降", MsgLevel.warning));
......
...@@ -20,6 +20,10 @@ namespace DeviceLibrary ...@@ -20,6 +20,10 @@ namespace DeviceLibrary
public CarTypeE OutCarType = CarTypeE.None; public CarTypeE OutCarType = CarTypeE.None;
public int OutCurrentStringNum = 0; public int OutCurrentStringNum = 0;
bool outnewreel = false; bool outnewreel = false;
/// <summary>
/// 指示入料车是否已经处理完毕
/// </summary>
bool incarProcessFinish = false;
void OutCarProcess() void OutCarProcess()
{ {
if (CheckWait(OutCarMoveInfo)) if (CheckWait(OutCarMoveInfo))
...@@ -73,15 +77,23 @@ namespace DeviceLibrary ...@@ -73,15 +77,23 @@ namespace DeviceLibrary
case MoveStep.OutCar_03: case MoveStep.OutCar_03:
OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04); OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04);
outnewreel = true; outnewreel = true;
incarProcessFinish = true;
OutCarMoveInfo.log($"新料串"); OutCarMoveInfo.log($"新料串");
break; break;
case MoveStep.OutCar_04: case MoveStep.OutCar_04:
OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_05); OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_05);
OutCarMoveInfo.log($"批量轴高速上升到顶部检测点"); var lowlist = OutGetLowReelCheckIOList();
BatchAxisToP2(OutCarMoveInfo, Unloading_Batch_Axis, OutGetLowReelCheckIOList(),IO_VALUE.HIGH, Config.Unloading_Batch_Axis_P2, Config.Unloading_Batch_Axis_P1_speed); if (lowlist.Length > 0)
{
OutCarMoveInfo.log($"批量轴高速上升到顶部检测点");
BatchAxisToP2(OutCarMoveInfo, Unloading_Batch_Axis, OutGetLowReelCheckIOList(), IO_VALUE.HIGH, Config.Unloading_Batch_Axis_P2, Config.Unloading_Batch_Axis_P1_speed);
}
else {
OutCarMoveInfo.log($"批量轴所有监测点都已Low");
}
break; break;
case MoveStep.OutCar_05: case MoveStep.OutCar_05:
var lowlist = OutGetLowReelCheckIOList(); lowlist = OutGetLowReelCheckIOList();
if (Unloading_Batch_Axis.IsInPosition(Config.Unloading_Batch_Axis_P2)) { if (Unloading_Batch_Axis.IsInPosition(Config.Unloading_Batch_Axis_P2)) {
OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_06); OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_06);
OutCarMoveInfo.log($"批量轴已到顶,可放料位置有:{string.Join(",", lowlist)}"); OutCarMoveInfo.log($"批量轴已到顶,可放料位置有:{string.Join(",", lowlist)}");
...@@ -140,6 +152,10 @@ namespace DeviceLibrary ...@@ -140,6 +152,10 @@ namespace DeviceLibrary
break; break;
case MoveStep.OutCarReadyPut: case MoveStep.OutCarReadyPut:
Msg.add("出口料串放料准备就绪", MsgLevel.info); Msg.add("出口料串放料准备就绪", MsgLevel.info);
if (incarProcessFinish && InMoveInfo.MoveStep == MoveStep.Wait && CountMoveInfo.MoveStep == MoveStep.Wait && OutMoveInfo.MoveStep == MoveStep.Wait) {
OutCarMoveInfo.NextMoveStep(MoveStep.OutCarOut_01);
OutCarMoveInfo.log($"入料车已处理完毕");
}
break; break;
case MoveStep.OutCarReelPut: case MoveStep.OutCarReelPut:
OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04); OutCarMoveInfo.NextMoveStep(MoveStep.OutCar_04);
......
...@@ -130,11 +130,17 @@ namespace DeviceLibrary ...@@ -130,11 +130,17 @@ namespace DeviceLibrary
}else }else
LogUtil.info("图像平板打开成功"); LogUtil.info("图像平板打开成功");
if (!printerHelper.Connection(Setting_Init.Printer_IP)) { if (!printerHelper.Connection(Setting_Init.Printer_IP))
{
msg += "标签打印机打开失败" + "\n"; msg += "标签打印机打开失败" + "\n";
IsLoadOk = false; IsLoadOk = false;
}else }
else
{
LogUtil.info("标签打印机打开成功"); LogUtil.info("标签打印机打开成功");
}
LogUtil.info("设备初始化完成"); LogUtil.info("设备初始化完成");
} }
catch (Exception ex) { catch (Exception ex) {
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!