Commit a63d2c11 刘韬

1

1 个父辈 df76da28
...@@ -64,5 +64,14 @@ namespace OnlineStore.Common ...@@ -64,5 +64,14 @@ namespace OnlineStore.Common
public static MyConfig<double> XRay_Current = 0.6; public static MyConfig<double> XRay_Current = 0.6;
[MyConfigComment("X高压点亮后延迟,毫秒")] [MyConfigComment("X高压点亮后延迟,毫秒")]
public static MyConfig<int> XRay_Light_Delay = 2500; public static MyConfig<int> XRay_Light_Delay = 2500;
[MyConfigComment("条码类型")]
public static MyConfig<string> Camera_CodeType = "QR Code#Data Matrix ECC 200";
[MyConfigComment("条码解码参数路径")]
public static MyConfig<string> Camera_CodeParamPath = "";
[MyConfigComment("筛选条码数量")]
public static MyConfig<int> Camera_QRCodeCount = 3;
[MyConfigComment("解码的超时时间")]
public static MyConfig<int> Camera_CodeTimeOut = 2000;
} }
} }
...@@ -70,12 +70,12 @@ namespace DeviceLibrary ...@@ -70,12 +70,12 @@ namespace DeviceLibrary
DeviceSuddenStop(); DeviceSuddenStop();
ok = false; ok = false;
} }
if (IOManager.GetDIValue("",0,16).Equals(IO_VALUE.LOW)) //if (IOManager.GetDIValue("",0,16).Equals(IO_VALUE.LOW))
{ //{
ok = false; // ok = false;
DeviceSuddenStop(); // DeviceSuddenStop();
Msg.add(crc.GetString("device_safedoor_open", "贴标或出料机构门禁被打开"), MsgLevel.warning); // Msg.add(crc.GetString("device_safedoor_open", "贴标或出料机构门禁被打开"), MsgLevel.warning);
} //}
lastSafeCheckStatus = ok; lastSafeCheckStatus = ok;
return ok; return ok;
} }
......
...@@ -32,6 +32,7 @@ namespace DeviceLibrary ...@@ -32,6 +32,7 @@ namespace DeviceLibrary
XRay_01_LocationDown, XRay_01_LocationDown,
XRay_02_RunIn, XRay_02_RunIn,
XRay_02_CheckReel,
XRay_03_CloseDoor, XRay_03_CloseDoor,
XRay_04_OpenXray, XRay_04_OpenXray,
XRay_04_CheckXray, XRay_04_CheckXray,
......
...@@ -113,7 +113,7 @@ namespace DeviceLibrary ...@@ -113,7 +113,7 @@ namespace DeviceLibrary
} }
else else
{ {
if (IOValue(IO_XRay_Type.Manual_Confirm_BTN).Equals(IO_VALUE.HIGH)) if (IOValue(IO_XRay_Type.SafetyLightCurtains).Equals(IO_VALUE.HIGH))
{ {
FeedingMoveinfo.NextMoveStep(MoveStep.Feeding_06_Goto_Xray); FeedingMoveinfo.NextMoveStep(MoveStep.Feeding_06_Goto_Xray);
FeedingMoveinfo.log($"按下入料按钮, 定位气缸下降"); FeedingMoveinfo.log($"按下入料按钮, 定位气缸下降");
...@@ -201,17 +201,17 @@ namespace DeviceLibrary ...@@ -201,17 +201,17 @@ namespace DeviceLibrary
var Tray15 = Math.Max(Tray15_L, Tray15_R); var Tray15 = Math.Max(Tray15_L, Tray15_R);
Debug.WriteLine($"Tray7:{Tray7},Tray13:{Tray13},Tray15:{Tray15}"); Debug.WriteLine($"Tray7:{Tray7},Tray13:{Tray13},Tray15:{Tray15}");
int v=0; int v=0;
if (Tray15 < overhight && Tray15>0) if (Tray15 < overhight && Tray15>4)
{ {
if (SensorDebounce.Debounce(Tray15, out v)) if (SensorDebounce.Debounce(Tray15, out v))
TrayWidth = 15; TrayWidth = 15;
} }
else if (Tray13 < overhight && Tray13>0) else if (Tray13 < overhight && Tray13>4)
{ {
if (SensorDebounce.Debounce(Tray13, out v)) if (SensorDebounce.Debounce(Tray13, out v))
TrayWidth = 13; TrayWidth = 13;
} }
else if (Tray7 < overhight && Tray7 > 0) else if (Tray7 < overhight && Tray7 > 4)
{ {
if (SensorDebounce.Debounce(Tray7, out v)) if (SensorDebounce.Debounce(Tray7, out v))
TrayWidth = 7; TrayWidth = 7;
......
...@@ -5,6 +5,7 @@ using System.Linq; ...@@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using CodeLibrary; using CodeLibrary;
using ConfigHelper;
using Newtonsoft.Json; using Newtonsoft.Json;
using OnlineStore.Common; using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary; using OnlineStore.LoadCSVLibrary;
...@@ -27,6 +28,7 @@ namespace DeviceLibrary ...@@ -27,6 +28,7 @@ namespace DeviceLibrary
bool ExitLine_Reel_IsSafe { bool ExitLine_Reel_IsSafe {
get => SideMoveInfo.MoveStep == MoveStep.Wait || SideMoveInfo.MoveStep >= MoveStep.SideMove_07; get => SideMoveInfo.MoveStep == MoveStep.Wait || SideMoveInfo.MoveStep >= MoveStep.SideMove_07;
} }
int ZDiff = 0;
void SideMoveProcess() void SideMoveProcess()
{ {
if (CheckWait(SideMoveInfo)) if (CheckWait(SideMoveInfo))
...@@ -41,6 +43,13 @@ namespace DeviceLibrary ...@@ -41,6 +43,13 @@ namespace DeviceLibrary
SideMoveInfo.ReelParam = ExitLine_Reel_Info.clone(); SideMoveInfo.ReelParam = ExitLine_Reel_Info.clone();
SideMoveInfo.log("检测到料盘到位"); SideMoveInfo.log("检测到料盘到位");
} }
else if (ExitLine_Reel_Info != null)
{
if (SideMoveInfo.IsTimeOut(10)) {
Msg.add("等待料盘到达横移机构超时", MsgLevel.warning);
SideMoveInfo.log("等待料盘到达横移机构超时");
}
}
else else
{ {
Msg.add("横移机构等待料盘", MsgLevel.info); Msg.add("横移机构等待料盘", MsgLevel.info);
...@@ -48,7 +57,6 @@ namespace DeviceLibrary ...@@ -48,7 +57,6 @@ namespace DeviceLibrary
break; break;
case MoveStep.SideMove_01: case MoveStep.SideMove_01:
SideMoveInfo.NextMoveStep(MoveStep.SideMove_02); SideMoveInfo.NextMoveStep(MoveStep.SideMove_02);
ExitLine_Location_Axis.AbsMove(SideMoveInfo, Config.ExitLine_Location_P1, Config.ExitLine_Location_P1_speed);
SideMove_Z_Axis.AbsMove(SideMoveInfo, Config.SideMove_Z_P1, Config.SideMove_Z_P1_speed); SideMove_Z_Axis.AbsMove(SideMoveInfo, Config.SideMove_Z_P1, Config.SideMove_Z_P1_speed);
SideMoveInfo.log("出料档停退到P1"); SideMoveInfo.log("出料档停退到P1");
suckReelRetryTimes = 0; suckReelRetryTimes = 0;
...@@ -61,12 +69,16 @@ namespace DeviceLibrary ...@@ -61,12 +69,16 @@ namespace DeviceLibrary
case MoveStep.SideMove_03: case MoveStep.SideMove_03:
SideMoveInfo.NextMoveStep(MoveStep.SideMove_04); SideMoveInfo.NextMoveStep(MoveStep.SideMove_04);
var p2 = Config.SideMove_Z_P2 - (SideMoveInfo.ReelParam.PlateH - 8 - suckReelRetryTimes*4) * 1000; var p2 = Config.SideMove_Z_P2 - (SideMoveInfo.ReelParam.PlateH - 8 - suckReelRetryTimes*4) * 1000;
p2 = Config.SideMove_Z_P2;
SideMove_Z_Axis.AbsMove(SideMoveInfo, p2, Config.SideMove_Z_P2_speed); SideMove_Z_Axis.AbsMove(SideMoveInfo, p2, Config.SideMove_Z_P2_speed);
CylinderMove(SideMoveInfo, IO_XRay_Type.SideMove_SuckerReel_Off, IO_XRay_Type.SideMove_SuckerReel_On, IO_VALUE.HIGH); CylinderMove(SideMoveInfo, IO_XRay_Type.SideMove_SuckerReel_Off, IO_XRay_Type.SideMove_SuckerReel_On, IO_VALUE.HIGH);
SideMoveInfo.log("升降轴到取料点P2:"+ p2); SideMoveInfo.log("升降轴到取料点P2:"+ p2);
break; break;
case MoveStep.SideMove_04: case MoveStep.SideMove_04:
SideMoveInfo.NextMoveStep(MoveStep.SideMove_05); SideMoveInfo.NextMoveStep(MoveStep.SideMove_05);
var ah = SideMove_Z_Axis.GetAclPosition();
ZDiff = Config.SideMove_Z_P2 - ah;
SideMoveInfo.log($"升降轴下降高度:P2:{Config.SideMove_Z_P2}-AH:{ah} = {ZDiff}");
break; break;
case MoveStep.SideMove_05: case MoveStep.SideMove_05:
SideMoveInfo.NextMoveStep(MoveStep.SideMove_06); SideMoveInfo.NextMoveStep(MoveStep.SideMove_06);
......
...@@ -29,6 +29,7 @@ namespace DeviceLibrary ...@@ -29,6 +29,7 @@ namespace DeviceLibrary
public int relmove; public int relmove;
const string xraydir = @"\Image\Xray"; const string xraydir = @"\Image\Xray";
Task GetResultTask = null; Task GetResultTask = null;
bool needhome = false;
void WorkProcess() void WorkProcess()
{ {
if (CheckWait(MoveInfo)) if (CheckWait(MoveInfo))
...@@ -45,7 +46,7 @@ namespace DeviceLibrary ...@@ -45,7 +46,7 @@ namespace DeviceLibrary
CylinderMove(null, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open, IO_VALUE.HIGH); CylinderMove(null, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open, IO_VALUE.HIGH);
break; break;
case MoveStep.XRay_02_RunIn: case MoveStep.XRay_02_RunIn:
MoveInfo.NextMoveStep(MoveStep.XRay_03_CloseDoor); MoveInfo.NextMoveStep(MoveStep.XRay_02_CheckReel);
MoveInfo.log($"入料伺服相对运转"); MoveInfo.log($"入料伺服相对运转");
//Line_Entry_Axis.RelMove(ResetMoveInfo, Config.Line_Entry_Relative, Config.Line_Entry_Relative_speed); //Line_Entry_Axis.RelMove(ResetMoveInfo, Config.Line_Entry_Relative, Config.Line_Entry_Relative_speed);
Line_Entry_Axis.SpeedMove(Config.Line_Entry_Relative_speed); Line_Entry_Axis.SpeedMove(Config.Line_Entry_Relative_speed);
...@@ -53,6 +54,19 @@ namespace DeviceLibrary ...@@ -53,6 +54,19 @@ namespace DeviceLibrary
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000)); MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_XRay_Type.Tray_Inside_Check, IO_VALUE.HIGH)); //MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_XRay_Type.Tray_Inside_Check, IO_VALUE.HIGH));
break; break;
case MoveStep.XRay_02_CheckReel:
if (IOValue(IO_XRay_Type.Tray_Inside_Check).Equals(IO_VALUE.HIGH))
{
MoveInfo.NextMoveStep(MoveStep.XRay_03_CloseDoor);
MoveInfo.log($"点料机检测到料盘");
}
else
{
Msg.add("点料机内没有检测到料盘", MsgLevel.warning);
MoveInfo.log($"点料机内没有检测到料盘");
RobotManage.UserPause(true);
}
break;
case MoveStep.XRay_03_CloseDoor: case MoveStep.XRay_03_CloseDoor:
MoveInfo.NextMoveStep(MoveStep.XRay_04_OpenXray); MoveInfo.NextMoveStep(MoveStep.XRay_04_OpenXray);
MoveInfo.log($"关闭点料机入口门"); MoveInfo.log($"关闭点料机入口门");
...@@ -177,10 +191,16 @@ namespace DeviceLibrary ...@@ -177,10 +191,16 @@ namespace DeviceLibrary
if (ExitLine_Reel_IsSafe && ExitLine_Reel_Info==null) if (ExitLine_Reel_IsSafe && ExitLine_Reel_Info==null)
{ {
MoveInfo.NextMoveStep(MoveStep.XRay_10_CloseOutDoor); MoveInfo.NextMoveStep(MoveStep.XRay_10_CloseOutDoor);
MoveInfo.log($"打开出口门,送出到贴标机构"); MoveInfo.log($"打开出口门,送出到贴标机构,W:{MoveInfo.ReelParam.PlateW}");
Line_In_Axis.SpeedMove(Config.Line_In_Relative_speed * 2); Line_In_Axis.RelMove(MoveInfo, Config.Line_In_Relative, Config.Line_In_Relative_speed);
IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.HIGH); IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.HIGH);
MoveInfo.StopwatchLog(false, "开始送出"); MoveInfo.StopwatchLog(false, "开始送出");
if (MoveInfo.ReelParam.PlateW == 7)
ExitLine_Location_Axis.AbsMove(MoveInfo, Config.ExitLine_Location_7, Config.ExitLine_Location_7_speed);
else if (MoveInfo.ReelParam.PlateW == 13)
ExitLine_Location_Axis.AbsMove(MoveInfo, Config.ExitLine_Location_13, Config.ExitLine_Location_13_speed);
else if (MoveInfo.ReelParam.PlateW == 15)
ExitLine_Location_Axis.AbsMove(MoveInfo, Config.ExitLine_Location_15, Config.ExitLine_Location_15_speed);
} }
else if (MoveInfo.IsTimeOut(30)) else if (MoveInfo.IsTimeOut(30))
...@@ -192,12 +212,19 @@ namespace DeviceLibrary ...@@ -192,12 +212,19 @@ namespace DeviceLibrary
case MoveStep.XRay_10_CloseOutDoor: case MoveStep.XRay_10_CloseOutDoor:
if (IOValue(IO_XRay_Type.ExitLine_Reel_Check).Equals(IO_VALUE.HIGH)) if (IOValue(IO_XRay_Type.ExitLine_Reel_Check).Equals(IO_VALUE.HIGH))
{ {
IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.LOW); IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.HIGH,false,2000);
MoveInfo.NextMoveStep(MoveStep.XRay_11_GetCoutResult); MoveInfo.NextMoveStep(MoveStep.XRay_11_GetCoutResult);
MoveInfo.log($"关闭出口门,停止X光机内线体"); MoveInfo.log($"关闭出口门,停止X光机内线体");
Line_In_Axis.SuddenStop();
CylinderMove(null, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open, IO_VALUE.LOW); CylinderMove(null, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open, IO_VALUE.LOW);
MoveInfo.StopwatchLog(false, "到达阻挡"); MoveInfo.StopwatchLog(false, "到达阻挡");
var nextpos = Line_In_Axis.GetAclPosition() + Config.Line_In_Relative;
var nextpresent = (double)nextpos / 1900000d - Math.Truncate((double)nextpos / 1917285d);
needhome = nextpresent >= 0.744437056;
MoveInfo.log($"当前位置:{Line_In_Axis.GetAclPosition()},下一个运行点位置:{nextpos},计算比例:{nextpresent},需要回原:{needhome}");
if (needhome)
Line_In_Axis.HomeMove(MoveInfo);
} }
else if (MoveInfo.IsTimeOut(10)) else if (MoveInfo.IsTimeOut(10))
{ {
......
...@@ -129,6 +129,7 @@ namespace DeviceLibrary ...@@ -129,6 +129,7 @@ namespace DeviceLibrary
{ {
ProcessMsgEventFire(Msg); ProcessMsgEventFire(Msg);
//ProcessMoveinfoEventFire(MoveInfo.List); //ProcessMoveinfoEventFire(MoveInfo.List);
if (canRunning && mstart)
Msg.Clear(); Msg.Clear();
} }
} }
...@@ -218,7 +219,13 @@ namespace DeviceLibrary ...@@ -218,7 +219,13 @@ namespace DeviceLibrary
case MoveStep.H01_HomeReset: case MoveStep.H01_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset); ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
ResetMoveInfo.log("正在回原, 托盘下降,门打开"); ResetMoveInfo.log("正在回原, 托盘下降,门打开");
CylinderMove(ResetMoveInfo, IO_XRay_Type.Location_Cylinder_Down, IO_XRay_Type.Location_Cylinder_Up,IO_VALUE.LOW);
if (IOValue(IO_XRay_Type.ExitLine_Reel_Check).Equals(IO_VALUE.LOW))
{
ExitLine_Reel_Info = null;
ResetMoveInfo.log("出料线没有检测到料盘, 删除缓存数据");
}
CylinderMove(ResetMoveInfo, IO_XRay_Type.Location_Cylinder_Down, IO_XRay_Type.Location_Cylinder_Up,IO_VALUE.HIGH);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open); CylinderMove(ResetMoveInfo, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open); CylinderMove(ResetMoveInfo, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open);
SideMove_Z_Axis.HomeMove(ResetMoveInfo); SideMove_Z_Axis.HomeMove(ResetMoveInfo);
...@@ -226,14 +233,17 @@ namespace DeviceLibrary ...@@ -226,14 +233,17 @@ namespace DeviceLibrary
break; break;
case MoveStep.H02_HomeReset: case MoveStep.H02_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H03_HomeReset); ResetMoveInfo.NextMoveStep(MoveStep.H03_HomeReset);
Line_Entry_Axis.RelMove(ResetMoveInfo, Config.Line_Entry_Relative*2, Config.Line_Entry_Relative_speed); Line_Entry_Axis.SpeedMove(Config.Line_Entry_Relative_speed);
Line_In_Axis.RelMove(ResetMoveInfo, Config.Line_In_Relative*2, Config.Line_In_Relative_speed); Line_In_Axis.RelMove(ResetMoveInfo, Config.Line_In_Relative*2, Config.Line_In_Relative_speed);
IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.HIGH);
SideMove_X_Axis.HomeMove(ResetMoveInfo); SideMove_X_Axis.HomeMove(ResetMoveInfo);
ResetMoveInfo.log("正在回原"); ResetMoveInfo.log("正在回原");
break; break;
case MoveStep.H03_HomeReset: case MoveStep.H03_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset); ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
ResetMoveInfo.log("正在回原, 门关闭"); ResetMoveInfo.log("正在回原, 门关闭");
IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.LOW);
Line_Entry_Axis.SuddenStop();
CylinderMove(ResetMoveInfo, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open,IO_VALUE.LOW); CylinderMove(ResetMoveInfo, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open,IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open, IO_VALUE.LOW); CylinderMove(ResetMoveInfo, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open, IO_VALUE.LOW);
CylinderMove(ResetMoveInfo, IO_XRay_Type.Location_Cylinder_Down, IO_XRay_Type.Location_Cylinder_Up, IO_VALUE.HIGH); CylinderMove(ResetMoveInfo, IO_XRay_Type.Location_Cylinder_Down, IO_XRay_Type.Location_Cylinder_Up, IO_VALUE.HIGH);
...@@ -241,8 +251,10 @@ namespace DeviceLibrary ...@@ -241,8 +251,10 @@ namespace DeviceLibrary
case MoveStep.HEND_HomeReset: case MoveStep.HEND_HomeReset:
ResetMoveInfo.log("回源完成"); ResetMoveInfo.log("回源完成");
ResetMoveInfo.EndMove(); ResetMoveInfo.EndMove();
//MoveInfo.NewMove(MoveStep.Feeding_05_Goto_Xray);
runStatus = RunStatus.Running; runStatus = RunStatus.Running;
FeedingMoveinfo.EndMove();
MoveInfo.EndMove();
SideMoveInfo.EndMove();
break; break;
} }
} }
......
...@@ -159,7 +159,7 @@ namespace DeviceLibrary ...@@ -159,7 +159,7 @@ namespace DeviceLibrary
int errorCount = Math.Abs(outCount - targetPosition); int errorCount = Math.Abs(outCount - targetPosition);
if (isOk) if (isOk)
{ {
if (errorCount <= axis.CanErrorCountMax) if (errorCount <= axis.CanErrorCountMax || GetLimitPositiveSingle(axis) == 1)
{ {
return true; return true;
} }
...@@ -200,6 +200,16 @@ namespace DeviceLibrary ...@@ -200,6 +200,16 @@ namespace DeviceLibrary
} }
return false; return false;
} }
static int GetLimitPositiveSingle(ConfigMoveAxis axis)
{
var p = AxisManager.GetLimitPositiveSingle(axis.DeviceName, axis.GetAxisValue());
if (p == 1)
{
LogUtil.info($"{axis.Explain}[{axis.GetAxisValue()}] 正极限 {(p == 1 ? "点亮" : "未亮")}");
return p;
}
return 0;
}
public static bool ACAxisRELMoveIsEnd(MoveInfo MoveInfo, ConfigMoveAxis axis, int targetPosition, int targetSpeed, out string msg) public static bool ACAxisRELMoveIsEnd(MoveInfo MoveInfo, ConfigMoveAxis axis, int targetPosition, int targetSpeed, out string msg)
{ {
msg = ""; msg = "";
......
...@@ -44,13 +44,17 @@ namespace DeviceLibrary ...@@ -44,13 +44,17 @@ namespace DeviceLibrary
set set
{ {
_WareCode = value; _WareCode = value;
if (!string.IsNullOrEmpty(_WareCode))
{
var w = _WareCode.Split('|'); var w = _WareCode.Split('|');
if (w.Length == 5) { if (w.Length == 5)
{
PN = w[0]; PN = w[0];
ReeID = w[3]; ReeID = w[3];
} }
} }
} }
}
public string ReeID { get; set; } public string ReeID { get; set; }
public string PN { get; set; } public string PN { get; set; }
/// <summary> /// <summary>
......
...@@ -50,8 +50,9 @@ ...@@ -50,8 +50,9 @@
<Reference Include="halcondotnet"> <Reference Include="halcondotnet">
<HintPath>..\..\RC1271-DUOStore\dll\halcondotnet.dll</HintPath> <HintPath>..\..\RC1271-DUOStore\dll\halcondotnet.dll</HintPath>
</Reference> </Reference>
<Reference Include="HuichuanLibrary"> <Reference Include="HuichuanLibrary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\HuichuanLibrary\HuichuanLibrary\bin\Debug\HuichuanLibrary.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\HuichuanLibrary\HuichuanLibrary\bin\Debug\HuichuanLibrary.dll</HintPath>
</Reference> </Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=AMD64"> <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
......
...@@ -12,41 +12,39 @@ using CodeLibrary; ...@@ -12,41 +12,39 @@ using CodeLibrary;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
using HalconDotNet;
using System.Web;
namespace DeviceLibrary namespace DeviceLibrary
{ {
public class CodeManager public class CodeManager
{ {
public static string CodeType = ConfigAppSettings.GetValue(Setting_Init.CodeType); public static string CodeType = Setting_Init.Camera_CodeType;
private static int QRCodeCount = ConfigAppSettings.GetIntValue(Setting_Init.QRCodeCount); private static int QRCodeCount = Setting_Init.Camera_QRCodeCount;
private static int CodeTimeOut = Setting_Init.Camera_CodeTimeOut;
public static List<string> cameraNameList = new List<string>(); public static List<string> cameraNameList = new List<string>();
public static List<string> codeTypeList = new List<string>(); public static List<string> codeTypeList = new List<string>();
public static List<string> hikNameList = new List<string>(); public static List<string> hikNameList = new List<string>();
public static List<int> Code_Block_Size_List = new List<int>(); public static event EventHandler<Bitmap> camera_event;
private static char spiltChar = '#'; private static char spiltChar = '#';
/// <summary> /// <summary>
/// 初始化摄像机名称和二维码类型 /// 初始化摄像机名称和二维码类型
/// </summary> /// </summary>
public static void LoadConfig() public static void LoadConfig()
{ {
//onfigHelper.Config.Set("CamTestReel_Test", "Click To Test");
//ConfigHelper.AdvanceConfigForm.AddCustomEditor<CameraTest>("CamTestReel_Test");
string code_block_size_list = ConfigAppSettings.GetValue(Setting_Init.code_block_size_list); codeTypeList = new List<string>();
var cl = code_block_size_list.Split(','); HDLogUtil.LogName = "RollingLogFileAppender";
foreach (string s in cl) try
{
int i;
if (int.TryParse(s, out i))
{ {
Code_Block_Size_List.Add(i); LoadCamera(true);
}
}
if (Code_Block_Size_List.Count == 0)
Code_Block_Size_List.Add(19);
string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName);
codeTypeList = new List<string>(); codeTypeList = new List<string>();
string[] codeArray = CodeType.Split(spiltChar); string[] codeArray = CodeType.Split(spiltChar);
foreach (string str in codeArray) foreach (string str in codeArray)
{ {
...@@ -58,36 +56,12 @@ namespace DeviceLibrary ...@@ -58,36 +56,12 @@ namespace DeviceLibrary
LogUtil.info("加载到配置二维码类型:" + str.Trim() + ",配置文件:" + file); LogUtil.info("加载到配置二维码类型:" + str.Trim() + ",配置文件:" + file);
codeTypeList.Add(str.Trim()); codeTypeList.Add(str.Trim());
} }
HDLogUtil.LogName = "RollingLogFileAppender";
try
{
string[] nameArray = nameStr.Split(spiltChar);
foreach (string str in nameArray)
{
if (str.Trim().Equals(""))
{
continue;
}
//LogUtil.info("加载到配置摄像机名称:" + str.Trim());
cameraNameList.Add(str.Trim());
}
LoadCamera(false);
CodeLibrary.HDCodeLearnHelper.LoadConfig("", CodeType); CodeLibrary.HDCodeLearnHelper.LoadConfig("", CodeType);
//如果未加载到配置相机,自动配置 //如果未加载到配置相机,自动配置
if (cameraNameList.Count <= 0 && hikNameList.Count > 0) if (cameraNameList.Count <= 0 && hikNameList.Count > 0)
{ {
cameraNameList = new List<string>(hikNameList); cameraNameList = new List<string>(hikNameList);
string cameraStr = "";
foreach (string name in hikNameList)
{
cameraStr += name + spiltChar;
}
cameraStr = cameraStr.Substring(0, cameraStr.Length - 1);
ConfigAppSettings.SaveValue(Setting_Init.CameraName, cameraStr);
LogUtil.info("未配置扫码相机,默认【" + Setting_Init.CameraName + "】=【" + cameraStr + "】");
} }
} }
catch (Exception ex) catch (Exception ex)
...@@ -95,7 +69,9 @@ namespace DeviceLibrary ...@@ -95,7 +69,9 @@ namespace DeviceLibrary
LogUtil.error("解析摄像机配置出错:" + ex.StackTrace); LogUtil.error("解析摄像机配置出错:" + ex.StackTrace);
} }
} }
private static void LoadCamera(bool isReLoad)
public static void LoadCamera(bool isReLoad)
{ {
if (isReLoad || Camera._cam == null) if (isReLoad || Camera._cam == null)
{ {
...@@ -141,99 +117,91 @@ namespace DeviceLibrary ...@@ -141,99 +117,91 @@ namespace DeviceLibrary
{ {
Camera._cam.CloseAll(); Camera._cam.CloseAll();
} }
public static List<CodeInfo> CameraScan(List<string> cameraNameList)
{
var x = CameraScan(cameraNameList, out Bitmap bitmap);
bitmap.Dispose();
return x;
}
[HandleProcessCorruptedStateExceptions] [HandleProcessCorruptedStateExceptions]
public static List<CodeInfo> CameraScan(List<string> cameraNameList,out Bitmap bitmap) public static List<CodeInfo> CameraScan(List<string> cameraNameList)
{ {
HashSet<string> codestr = new HashSet<string>();
List<CodeInfo> codeList = new List<CodeInfo>(); List<CodeInfo> codeList = new List<CodeInfo>();
bitmap = null; string bitmapfilename = "";
if (cameraNameList == null || cameraNameList.Count <= 0) if (cameraNameList == null || cameraNameList.Count <= 0)
{ {
throw new Exception("CameraScan方法没有传入相机名称."); throw new Exception("CameraScan方法没有传入相机名称.");
} }
try try
{ {
for (int i = 0; i < cameraNameList.Count(); i++) Task[] cameraTask = new Task[cameraNameList.Count()];
for (int ii = 0; ii < cameraNameList.Count(); ii++)
{ {
var cameraName = cameraNameList[ii];
var cameraName = cameraNameList[i]; var idx = ii;
cameraTask[ii] = Task.Run(new Action(() =>
{
int retrytime = 0;
retry:
LogUtil.info($"【" + cameraName + "】开始取图片");
if (cameraName.Trim().Equals("")) if (cameraName.Trim().Equals(""))
{ {
continue; return;
} }
DateTime startTime = DateTime.Now; DateTime startTime = DateTime.Now;
LogUtil.info(" 【" + cameraName + "】开始取图片");
HalconDotNet.HObject ho_Image = null; HalconDotNet.HObject ho_Image = null;
Bitmap bmp = null; Bitmap bmp = null;
try try
{ {
bool nohalcon = false; bool nohalcon = true;
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp, nohalcon); ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp, nohalcon);
bitmap = Common.DeepClone(bmp); if (bmp == null)
{
if (retrytime > 2)
return;
retrytime++;
LoadCamera(true);
LogUtil.info($"bitmap为空重试第{retrytime}次");
Task.Delay(1500).Wait();
goto retry;
}
//HalconDotNet.HOperatorSet.RotateImage()
if (ho_Image == null && !nohalcon) if (ho_Image == null && !nohalcon)
{ {
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机"); LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName); LoadCamera(true);
continue; return;
} }
if (idx == 0)
camera_event?.Invoke(null, bmp);
LogUtil.info(" 【" + cameraName + "】取图片完成,开始扫码"); LogUtil.info(" 【" + cameraName + "】取图片完成,开始扫码");
string r = ""; string r = "";
RemoteDecodeHelper.RemoteDecodeParam remoteDecodeParam = new RemoteDecodeHelper.RemoteDecodeParam
//foreach (int codesize in Code_Block_Size_List)
{
List<CodeInfo> tlci = EyemDecode2.Decoder(ref bmp, null);
foreach (CodeInfo code in tlci)
{
LogUtil.info(" 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr);
lock (codeList)
{
if (!codeList.Contains(code) && HasRightCode(code.CodeStr))
{
codeList.Add(code);
r = r + "##" + code.CodeStr;
}
}
}
}
if (!nohalcon && codeList.Count==0)
{ {
codeTypeList = codeTypeList.ToArray(),
codeCount = QRCodeCount,
timeout = CodeTimeOut
};
List<CodeInfo> cc = new List<CodeInfo>(); List<CodeInfo> cc = new List<CodeInfo>();
foreach (string codeType in codeTypeList)
{ cc = RemoteDecodeHelper.DecodeRequest(bmp, remoteDecodeParam);
//判断是否是一维码 if (cc != null && cc.Count > 0)
if (codeType.ToLower().Equals("barcode"))
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{ {
cc = HDCodeHelper.DecodeCode(ho_Image, codeType, GetCodeParamFilePath(codeType), QRCodeCount, 3000); cc.ForEach((c) =>
}
LogUtil.info(" 【" + cameraName + "】[Halcon]" + codeType + "," + QRCodeCount + ","+ cc.Count);
foreach (CodeInfo c in cc)
{ {
LogUtil.info(" 【" + cameraName + "】[Halcon]" + c.CodeType + "(X: " + c.X + ",Y: " + c.Y + ") " + c.CodeStr); LogUtil.info(c.CodeStr);
c.CodeStr = CodeManager.ReplaceCode(c.CodeStr); c.CodeStr = CodeManager.ReplaceCode(c.CodeStr);
lock (codeList) lock (codeList)
{ {
if (!codeList.Contains(c) && HasRightCode(c.CodeStr)) if (!codeList.Any(a=>a.CodeStr == c.CodeStr) && HasRightCode(c.CodeStr))
{ {
codeList.Add(c); codeList.Add(c);
r = r + "##" + c.CodeStr; r = r + "##" + c.CodeStr;
} }
} }
});
} }
} else
}
if (codeList.Count() != 1)
{ {
SaveImageToFile("mimo"+ codeList.Count(), cameraName, bmp); bitmapfilename = SaveImageToFile("mimo", cameraName, bmp);
} }
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r); LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
} }
...@@ -256,137 +224,52 @@ namespace DeviceLibrary ...@@ -256,137 +224,52 @@ namespace DeviceLibrary
if (bmp != null) if (bmp != null)
bmp.Dispose(); bmp.Dispose();
} }
}
//Task.WaitAll(cameraTask);
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常:" + e.ToString());
//throw new Exception("扫码出现AccessViolationException异常");
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
//throw new Exception("扫码出错");
}
return codeList;
}
public static List<CodeInfo> CameraScan2(List<string> cameraNameList) }));
{ Task.Delay(ii * 700).Wait();
List<CodeInfo> codeList = new List<CodeInfo>();
if (cameraNameList == null || cameraNameList.Count <= 0)
{
throw new Exception("CameraScan方法没有传入相机名称.");
} }
try
{
for (int i = 0; i < cameraNameList.Count(); i++)
{
var cameraName = cameraNameList[i];
if (cameraName.Trim().Equals(""))
{
continue;
}
LogUtil.info(" 【" + cameraName + "】开始取图片处理例程");
try while (!cameraTask[0].IsCompleted)
{
var fun1 = new Func<string, Bitmap, object>(decode);
Camera._cam.ProcessOnImage(cameraName, out object[] resule, fun1);
if (resule[0] != null)
codeList = (List<CodeInfo>)resule[0];
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
}
finally
{ {
Application.DoEvents();
} Thread.Sleep(100);
} }
} }
catch (AccessViolationException e) catch (AccessViolationException e)
{ {
LogUtil.error(" 扫码出现AccessViolationException异常:" + e.ToString()); LogUtil.error(" 扫码出现AccessViolationException异常:" + e.ToString());
//throw new Exception("扫码出现AccessViolationException异常");
// GC.Collect();
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error(" 扫码出错:" + ex.ToString()); LogUtil.error(" 扫码出错:" + ex.ToString());
//throw new Exception("扫码出错");
} }
return codeList; return codeList;
} }
public static string GetCodeParamFilePath(string codePath)
{
string appPath = Application.StartupPath;
string path = Path.Combine(appPath, ConfigAppSettings.GetValue(Setting_Init.CodeParamPath));
string filePath = Path.Combine(path, codePath + ".dcm");
if (File.Exists(filePath))
{
return filePath;
}
else
{
return "";
}
}
static object decode(string cameraName, Bitmap bmp)
{
DateTime startTime = DateTime.Now;
List<CodeInfo> codeList = new List<CodeInfo>();
LogUtil.info("取图片完成,开始扫码");
string r = "";
foreach (int codesize in Code_Block_Size_List)
{
List<CodeInfo> tlci = EyemDecode2.Decoder(ref bmp);
foreach (CodeInfo code in tlci)
{
LogUtil.info(" 【" + cameraName + "】[eyemDecode]" + code.CodeType + "(X: " + code.X + ",Y: " + code.Y + ") " + code.CodeStr);
lock (codeList)
{
if (!codeList.Contains(code) && HasRightCode(code.CodeStr))
{
codeList.Add(code);
r = r + "##" + code.CodeStr;
}
}
}
}
if (codeList.Count() == 0)
{
SaveImageToFile("", cameraName, bmp);
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
return codeList;
}
private static void SaveImageToFile(string deviceName, string cameraName, Bitmap bitmap) private static string SaveImageToFile(string deviceName, string cameraName, Bitmap bitmap)
{ {
string date = DateTime.Now.ToString("HH-mm-ss-") + DateTime.Now.Millisecond; string date = DateTime.Now.ToString("HH-mm-ss-") + DateTime.Now.Millisecond;
string dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\"; string dire = @"\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp"; string iamgeName = date + ".bmp";
try try
{ {
Bitmap bit = (Bitmap)bitmap.Clone();
if (Directory.Exists(dire).Equals(false)) if (Directory.Exists(dire).Equals(false))
{ {
Directory.CreateDirectory(dire); Directory.CreateDirectory(dire);
} }
bit.Save(dire + iamgeName, ImageFormat.Bmp); bitmap.Save(dire + iamgeName, ImageFormat.Bmp);
bit.Dispose(); //bitmap.Dispose();
LogUtil.info(deviceName + " 【" + cameraName + "】扫码失败,保存图片到【" + dire + iamgeName + "】成功"); LogUtil.info(deviceName + " 【" + cameraName + "】扫码完成,保存图片到【" + dire + iamgeName + "】成功");
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("保存" + deviceName + " 【" + cameraName + "】的图片到【" + dire + iamgeName + "】出错" + ex.ToString()); LogUtil.error("保存" + deviceName + " 【" + cameraName + "】的图片到【" + dire + iamgeName + "】出错" + ex.ToString());
} }
return dire + iamgeName;
} }
/// <summary> /// <summary>
...@@ -427,6 +310,21 @@ namespace DeviceLibrary ...@@ -427,6 +310,21 @@ namespace DeviceLibrary
{ {
return Regex.IsMatch(str, @"[\u4e00-\u9fa5]"); return Regex.IsMatch(str, @"[\u4e00-\u9fa5]");
} }
public static string GetCodeParamFilePath(string codePath)
{
string appPath = Application.StartupPath;
string path = Path.Combine(appPath, Setting_Init.Camera_CodeParamPath);
string filePath = Path.Combine(path, codePath + ".dcm");
if (File.Exists(filePath))
{
return filePath;
}
else
{
return "";
}
}
public static bool HasRightCode(string codes) public static bool HasRightCode(string codes)
{ {
//78.10222.20L-016651|-20200826|900|W78016651352000A6|SAMSUNG //78.10222.20L-016651|-20200826|900|W78016651352000A6|SAMSUNG
......
...@@ -110,7 +110,7 @@ namespace DeviceLibrary ...@@ -110,7 +110,7 @@ namespace DeviceLibrary
public void SpeedMove(string portName, short slvAddr, int speed) public void SpeedMove(string portName, short slvAddr, int speed)
{ {
HCBoardManager.SpeedMove(slvAddr, speed); HCBoardManager.SpeedMove(slvAddr, speed, speed * 4, speed * 4);
} }
public void SuddenStop(string portName, short slvAddr) public void SuddenStop(string portName, short slvAddr)
{ {
......
...@@ -457,7 +457,6 @@ namespace AutoCountMachine ...@@ -457,7 +457,6 @@ namespace AutoCountMachine
this.Controls.Add(this.btn_stop); this.Controls.Add(this.btn_stop);
this.Controls.Add(this.btn_run); this.Controls.Add(this.btn_run);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1"; this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Neo Counter X800"; this.Text = "Neo Counter X800";
......
...@@ -214,4 +214,7 @@ ...@@ -214,4 +214,7 @@
<Content Include="icon.ico" /> <Content Include="icon.ico" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>start $(TargetDir)</PostBuildEvent>
</PropertyGroup>
</Project> </Project>
\ No newline at end of file \ No newline at end of file
...@@ -361,7 +361,7 @@ namespace AutoCountMachine ...@@ -361,7 +361,7 @@ namespace AutoCountMachine
RobotManage.xrayMachine.IOMove(IO_XRay_Type.Xray_Lock, IO_VALUE.HIGH); RobotManage.xrayMachine.IOMove(IO_XRay_Type.Xray_Lock, IO_VALUE.HIGH);
Task.Delay(1000).Wait(); Task.Delay(1000).Wait();
RobotManage.XRay.Start(); RobotManage.XRay.Start();
Task.Delay(2000).Wait(); Task.Delay(5000).Wait();
var b = RobotManage.xrayImage.GenerateTemplate(2); var b = RobotManage.xrayImage.GenerateTemplate(2);
b.Wait(); b.Wait();
if (b.Result) if (b.Result)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!