Commit 81789272 刘韬

优化因网络不稳定导致的相机连接不稳定的问题,

1 个父辈 4d3a56ac
......@@ -54,8 +54,7 @@ namespace OnlineStore.AutoCountClient
[STAThread]
static void Main(string[] Args)
{
//string code = " (X: 380,Y: 148) L00000000000WG9D19055;E20191230 0180;B7H.10618.5B1008082019123004000;R0080820191230E9600";
//string r = CodeManager.ReplaceCode(code);
......
......@@ -41,8 +41,9 @@
<Reference Include="halcondotnet">
<HintPath>..\..\..\..\GeneralClassLibrary\CodeLibraryProject\CodeLibrary\bin\Debug\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="log4net">
<HintPath>..\..\..\..\GeneralClassLibrary\CodeLibraryProject\CodeLibrary\bin\Debug\log4net.dll</HintPath>
<Reference Include="log4net, Version=2.0.12.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\dll\log4net.dll</HintPath>
</Reference>
<Reference Include="MvCameraControl.Net">
<HintPath>..\..\..\..\GeneralClassLibrary\CodeLibraryProject\CodeLibrary\bin\Debug\MvCameraControl.Net.dll</HintPath>
......
......@@ -53,7 +53,6 @@
this.btnScanTest = new System.Windows.Forms.Button();
this.chbZxing = new System.Windows.Forms.CheckBox();
this.label5 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
......@@ -336,22 +335,11 @@
this.label5.Size = new System.Drawing.Size(0, 12);
this.label5.TabIndex = 32;
//
// button1
//
this.button1.Location = new System.Drawing.Point(1103, 57);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 33;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click_1);
//
// FrmCodeDecode
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1370, 729);
this.Controls.Add(this.button1);
this.Controls.Add(this.label5);
this.Controls.Add(this.chbZxing);
this.Controls.Add(this.btnScanTest);
......@@ -415,7 +403,6 @@
private System.Windows.Forms.Button btnScanTest;
private System.Windows.Forms.CheckBox chbZxing;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.Button button1;
}
}
......@@ -643,54 +643,6 @@ namespace CodeLibrary
Clipboard.SetDataObject(text);
}
private void button1_Click_1(object sender, EventArgs e)
{
Task.Run(() => { test(); });
}
void test()
{
var files = Directory.GetFiles(@"d:\批量测试图像","*.bmp");
int t = 0;
for (int i = 0; i < 100; i++)
{
foreach (string s in files)
{
Bitmap bmp = new Bitmap(s);
//HObject hoImage;
//HDCodeHelper.Bitmap2HObjectBpp24(bmp, out hoImage);
bool hasDetect = false;
try
{
t++;
List<CodeInfo> tlci = EyemDecode.Decoder(ref bmp, null);
//HDCodeHelper.DecodeCode(hoImage, "QR Code", GetCodeParamFilePath("QR Code"), 0, 2500);
//HDCodeHelper.DecodeCode(hoImage, "Data Matrix ECC 200", GetCodeParamFilePath("Data Matrix ECC 200"), 0, 2500);
foreach (CodeInfo c in tlci)
{
Console.WriteLine($"{t},{c.CodeType},{c.CodeStr}");
}
if (tlci.Count() == 0)
Console.WriteLine($"{t},No Detect.");
else
hasDetect = true;
}
catch { }
finally
{
//hoImage.Dispose();
bmp.Dispose();
}
var ss = Path.ChangeExtension(s, null);
ss = Path.ChangeExtension(ss, null);
ss = Path.ChangeExtension(ss, hasDetect?".bmp":".false.bmp");
File.Move(s, ss);
}
//GC.Collect();
}
}
public static string GetCodeParamFilePath(string codePath)
{
string appPath = Application.StartupPath;
......
......@@ -48,8 +48,7 @@ namespace CodeLibrary
eyemRect.iYs = 0;
eyemRect.iWidth = eyemImage.iWidth;
eyemRect.iHeight = eyemImage.iHeight;
string codeType = "DataMatrix";//QRCode
codeType = "QRCode";
string codeType = "QR_CODE|DATA_MATRIX";//QRCode
int ipNum;
EyemBarCode* tpResults;
......@@ -96,7 +95,7 @@ namespace CodeLibrary
}
}
[DllImport("eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown=0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
private static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown=1, double dToleErr = 0.5, double dMinorStep = 1.0);
/// <summary>
/// 读取图像
......@@ -138,6 +137,7 @@ namespace CodeLibrary
[StructLayout(LayoutKind.Sequential)]
public struct EyemBarCode
{
public double dAngle; // 角度
public int iCenterX; // y坐标
public int iCenterY; // y坐标
public IntPtr hType; // 码类型
......
......@@ -170,7 +170,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(it, IO_VALUE.LOW));
}
else
{
{
MoveInfo.NextMoveStep(StepEnum.IW50_InOutToP2);
WorkLog("取料: 开始重试 第" + getretry + "次");
var b = LeftBatchMove;
......
......@@ -532,6 +532,7 @@ namespace OnlineStore.DeviceLibrary
//}
private Stopwatch needEnterWatch = new Stopwatch();
private Stopwatch needLeaveWatch = new Stopwatch();
private Asa.ClientLevel curAgvOutLevel = Asa.ClientLevel.Low;
protected override void BaseTimerProcess()
{
if (isInSuddenDown || isNoAirCheck)
......@@ -577,7 +578,7 @@ namespace OnlineStore.DeviceLibrary
{
if (RobotManager.checkWatch(needEnterWatch, 3000))
{
AgvClient.NeedEnter(Config.AgvInName, "", Asa.ClientLevel.High);
AgvClient.NeedEnter(Config.AgvInName, "", curAgvOutLevel);
}
}
else if (AgvClient.GetAction(Config.AgvInName) != Asa.ClientAction.MayEnter && AgvClient.GetAction(Config.AgvInName) != Asa.ClientAction.None)
......@@ -592,7 +593,7 @@ namespace OnlineStore.DeviceLibrary
{
if (RobotManager.checkWatch(needLeaveWatch, 3000))
{
AgvClient.NeedLeave(Config.AgvOutName, "", Asa.ClientLevel.High);
AgvClient.NeedLeave(Config.AgvOutName, "", Asa.ClientLevel.Low);
}
}
else if (AgvClient.GetAction(Config.AgvOutName) != Asa.ClientAction.MayLeave && AgvClient.GetAction(Config.AgvOutName) != Asa.ClientAction.None)
......@@ -622,7 +623,7 @@ namespace OnlineStore.DeviceLibrary
return;
}
//若BOX和出料都没有在等待Io的过程中则此Io超时异常可能已经处理过
if ( MoveInfo.IsInWait.Equals(false) && SecMoveInfo.IsInWait.Equals(false)&&ShelfMoveInfo.IsInWait.Equals(false))
if ( MoveInfo.IsInWait.Equals(false) && SecMoveInfo.IsInWait.Equals(false)&&ShelfMoveInfo.IsInWait.Equals(false) && RobotManager.LastPrintStatus != Asa.PrintLabel.PrinterStatus.Printing)
{
LogUtil.info(Name + "清理信号超时报警【" + WarnMsg + "】 ");
alarmType = AlarmType.None;
......
......@@ -67,8 +67,7 @@ namespace OnlineStore.DeviceLibrary
{
LogUtil.error(MoveInfo.Name + "StartWorking 失败 , MoveInfo 忙碌中=" + MoveInfo.MoveType,201);
return false;
}
}
if(ShelfMoveInfo.MoveType.Equals(RobotMoveType.ShelfPro)&&ShelfMoveInfo.MoveStep>= StepEnum.OS_31_ShendShelfOut)
{
LogUtil.error(MoveInfo.Name + "StartWorking 失败 , ShelfMoveInfo 正在送出料架 " + ShelfMoveInfo.MoveType+"_"+ ShelfMoveInfo.MoveStep,202);
......@@ -80,6 +79,11 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error(MoveInfo.Name + "StartWorking 失败 , SecMoveInfo 上个贴标还打印中 " + SecMoveInfo.MoveType + "_" + SecMoveInfo.MoveStep,203);
return false;
}
if (RobotManager.robot.XrayBean.MoveInfo.MoveStep >=StepEnum.XW23_OutLineRun)
{
LogUtil.error(MoveInfo.Name + "StartWorking 失败 , 等待点料结果XrayBean " + RobotManager.robot.XrayBean.MoveInfo.MoveType + "_" + RobotManager.robot.XrayBean.MoveInfo.MoveStep,204);
return false;
}
if (IOValue(IO_Type.Out_TrayCheck).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.X_OLine_Run).Equals(IO_VALUE.LOW))
{
......@@ -88,7 +92,7 @@ namespace OnlineStore.DeviceLibrary
if (param.PlateW > 0 && param.PlateH > 0)
{
MoveInfo.MoveParam = param;
WorkLog(" 检测到XRay出口料盘[" + param.OutStr() + "],准备开始取料,重置 IsStartLabel = false");
WorkLog(" 检测到XRay出口料盘1[" + param.OutStr() + "],准备开始取料,重置 IsStartLabel = false");
}
else
{
......@@ -100,7 +104,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.MoveParam.SetReelInfo(reelInfo);
WorkLog(" 检测到XRay出口料盘[" + reelInfo.ToStr() + "],准备开始取料,重置 IsStartLabel = false");
WorkLog(" 检测到XRay出口料盘2[" + reelInfo.ToStr() + "],准备开始取料,重置 IsStartLabel = false");
}
if (MoveInfo.MoveParam.PlateW <= 0 ||
MoveInfo.MoveParam.PlateH <= 0 ||
......@@ -186,6 +190,7 @@ namespace OnlineStore.DeviceLibrary
}
}
bool saveone = false;
Task getPic=null;
private void OT05_GetImage()
{
if (MoveInfo.MoveParam.IsNgReel)
......@@ -198,9 +203,9 @@ namespace OnlineStore.DeviceLibrary
{
//暂时不需要拍照
MoveInfo.NextMoveStep(StepEnum.OT05_GetImage);
WorkLog("取料:[" + Config.CameraName + "]拍照并开始识别 ,等待100ms");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(100));
Task.Run(delegate
WorkLog("取料:[" + Config.CameraName + "]拍照并开始识别 ,等待1000ms");
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
getPic = Task.Run(delegate
{
if (string.IsNullOrEmpty(MoveInfo.MoveParam.WareCode))
return;
......@@ -208,55 +213,27 @@ namespace OnlineStore.DeviceLibrary
//var filename = "need";
CodeManager.CameraScan(Name, out cc, saveone, Config.CameraName);
saveone = true;
Task.Delay(1000).Wait();
if (cc.Count==0)
CodeManager.CameraScan(Name, out cc, saveone, Config.CameraName);
if (cc.Count > 0)
{
try
{
MoveInfo.MoveParam.codePointer.X = cc[0].X;
MoveInfo.MoveParam.codePointer.Y = cc[0].Y;
WorkLog("取料:识别到二维码位置:X:" + MoveInfo.MoveParam.codePointer.X + ",Y:" + MoveInfo.MoveParam.codePointer.Y, 1);
//x2230,y2115
//var textxy = string.Join("|",(from a in cc select "X:" + a.X.ToString() + ",Y:" + a.Y.ToString()).ToArray());
//System.IO.File.WriteAllText(filename + ".txt", textxy+ MoveInfo.MoveParam.WareCode);
//filename = filename + ".hobj";
/*
HalconDotNet.HImage image = new HalconDotNet.HImage();
image.ReadImage(filename);
Bitmap i;
CodeManager.HObject2Bpp8(image, out i);
Bitmap bmp = new Bitmap(i.Width, i.Height, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
Graphics g = Graphics.FromImage(bmp);
g.DrawImage(i, 0, 0);
foreach (CodeInfo ci in cc)
{
Point pt1 = new Point(ci.X, ci.Y);
g.DrawArc(new Pen(Color.Red, 15), new Rectangle(pt1, new Size(15, 15)), 0, 360);
}
g.Save();
bmp.Save(filename + ".bmp");
g.Dispose();
i.Dispose();
bmp.Dispose();
System.IO.File.Delete(filename);
*/
}
catch (Exception ex)
{
WorkLog("取料:识别绘图出错:" + ex.ToString(), 1);
}
MoveInfo.MoveParam.codePointer.X = cc[0].X;
MoveInfo.MoveParam.codePointer.Y = cc[0].Y;
WorkLog("取料:识别到二维码位置:X:" + MoveInfo.MoveParam.codePointer.X + ",Y:" + MoveInfo.MoveParam.codePointer.Y, 1);
}
else {
else
{
WorkLog("取料:2次没有识别到二维码", 1);
}
});
//MoveInfo.NextMoveStep(StepEnum.OT07_MoveZToP2);
//WorkLog("取料:取料Z轴到P2 ", 0);
//MoveZAxis.AbsMove(MoveInfo, Config.GetMoveZP2(MoveInfo.MoveParam.PlateH), Config.MoveZ_P2Speed);
//CheckStartLabel();
}
}
/// <summary>
/// 当前料串上的ReelID
/// </summary>
string CurrWareCode = "";
int TakeReelRetay = 0;
protected override void WorkingProcess()
{
......@@ -293,11 +270,15 @@ namespace OnlineStore.DeviceLibrary
}
else if (MoveInfo.IsStep(StepEnum.OT05_GetImage))
{
if (TakeReelRetay == 0 && getPic != null && !getPic.IsCompleted)
{
return;
}
getPic = null;
MoveInfo.NextMoveStep(StepEnum.OT07_MoveZToP2);
WorkLog("取料:取料Z轴到P2 1 "+ (TakeReelRetay > 0 ? TakeReelRetay - 1 : 0));
//MoveInfo.CanWhileCount = -1;
//+Config.Height_ChangeValue / 2 * (TakeReelRetay > 0 ? TakeReelRetay - 1 : 0)
MoveZAxis.AbsMove(MoveInfo, Config.GetMoveZP2(MoveInfo.MoveParam.PlateH) , Config.MoveZ_P2Speed);
WorkLog("取料:取料Z轴到P2 1 " + (TakeReelRetay > 0 ? TakeReelRetay - 1 : 0));
MoveZAxis.AbsMove(MoveInfo, Config.GetMoveZP2(MoveInfo.MoveParam.PlateH), Config.MoveZ_P2Speed);
CheckStartLabel();
}
else if (MoveInfo.IsStep(StepEnum.OT06_MoveXToP2))
......@@ -361,6 +342,7 @@ namespace OnlineStore.DeviceLibrary
WarnMsg = MoveInfo.Name + "[取料:取料失败,已重试3次,请手动取走料盘]";
WorkLog(WarnMsg);
Alarm(AlarmType.IoSingleTimeOut);
CylinderMove(MoveInfo, IO_Type.TakeT_Clamping_Work, IO_Type.TakeT_Clamping_Relax);
MoveInfo.NextMoveStep(StepEnum.OT25_NG_NGBack);
MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.Out_TrayCheck, IO_VALUE.LOW));
}
......@@ -369,7 +351,10 @@ namespace OnlineStore.DeviceLibrary
else if (MoveInfo.IsStep(StepEnum.OT09_MoveZToP1))
{
MoveInfo.NextMoveStep(StepEnum.OT11_WaitShelfOk);
WorkLog("取料完成,等待料串可放料 ");
bool r = RobotManager.robot.XrayBean.Out_ReelInfo.WareCode != MoveInfo.MoveParam.WareCode;
MoveInfo.MoveParam.SetReelInfo(RobotManager.robot.XrayBean.Out_ReelInfo);
//WorkLog($"取料完成,等待料串可放料 更新reelinfo={(r ? RobotManager.robot.XrayBean.Out_ReelInfo.ToStr():"false")}");
CheckStartLabel();
}
else if (MoveInfo.IsStep(StepEnum.OT11_WaitShelfOk))
......@@ -447,6 +432,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StepEnum.OT14_Clamping_Relax);
WorkLog("放料:取料气缸放松 ", 0);
CylinderMove(MoveInfo, IO_Type.TakeT_Clamping_Work, IO_Type.TakeT_Clamping_Relax);
CurrWareCode = MoveInfo.MoveParam.WareCode;
}
else if (MoveInfo.IsTimeOut(60))
{
......
......@@ -270,10 +270,9 @@ namespace OnlineStore.DeviceLibrary
}
if (!SecMoveInfo.MoveType.Equals(RobotMoveType.None)
&& SecMoveInfo.MoveParam != null
&& MoveInfo.MoveParam != null
&& SecMoveInfo.MoveParam.WareCode != MoveInfo.MoveParam.WareCode)
&& SecMoveInfo.MoveParam.WareCode != CurrWareCode)
{
ShelfWorkLog("标签错位,放弃当前标签");
ShelfWorkLog($"标签错位,放弃当前标签SecMoveInfo={SecMoveInfo.MoveParam.WareCode},CurrWareCode={CurrWareCode}");
SecMoveInfo.NextMoveStep(StepEnum.OL20_LableCancel);
}
}
......@@ -357,6 +356,16 @@ namespace OnlineStore.DeviceLibrary
{
ShelfMoveInfo.NextMoveStep(StepEnum.OS_36_WaitOutNoShelf);
ShelfWorkLog("等待出口无料串");
if (IOValue(IO_Type.O_WLine_OutCheck).Equals(IO_VALUE.HIGH))
{
if (AgvClient.GetAction(Config.AgvOutName).Equals(ClientAction.NeedLeave))
{
curAgvOutLevel = Asa.ClientLevel.High;
AgvClient.SetStatus(Config.AgvOutName, "", ClientAction.NeedLeave, Asa.ClientLevel.High, true);
}
}
ShelfMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.O_WLine_WorkOutCheck, IO_VALUE.LOW));
ShelfMoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_Type.O_WLine_OutCheck, IO_VALUE.LOW));
}
......@@ -364,7 +373,7 @@ namespace OnlineStore.DeviceLibrary
{
ShelfMoveInfo.NextMoveStep(StepEnum.OS_37_OutStopUp);
ShelfWorkLog("出口阻挡上升,清空出料信息=-1");
curAgvOutLevel = Asa.ClientLevel.Low;
OutReelHeight = -1;
OutReelCount = -1;
IOMove(IO_Type.O_WLine_OutStop, IO_VALUE.LOW);
......
......@@ -144,7 +144,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NextMoveStep(StepEnum.XW07_InLineStop);
WorkLog("料盘处理:停止入口皮带线,中间皮带线");
IOMove(IO_Type.X_InLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH,800);
IOMove(IO_Type.X_MLine_Run, IO_VALUE.HIGH,700);//皮带延时,控制料盘位置
}
else if (MoveInfo.IsTimeOut(20))
{
......
......@@ -136,7 +136,12 @@ namespace OnlineStore.DeviceLibrary
{
LogUtil.error(deviceName + " 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName);
continue;
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp);
if (ho_Image == null)
{
LogUtil.error(deviceName + " 【" + cameraName + "】第2次取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
continue;
}
}
LogUtil.debug(deviceName + " 【" + cameraName + "】取图片完成,开始扫码");
string r = "";
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!