Commit 291c42bb 刘韬

1

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