Commit a63d2c11 刘韬

1

1 个父辈 df76da28
......@@ -64,5 +64,14 @@ namespace OnlineStore.Common
public static MyConfig<double> XRay_Current = 0.6;
[MyConfigComment("X高压点亮后延迟,毫秒")]
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
DeviceSuddenStop();
ok = false;
}
if (IOManager.GetDIValue("",0,16).Equals(IO_VALUE.LOW))
{
ok = false;
DeviceSuddenStop();
Msg.add(crc.GetString("device_safedoor_open", "贴标或出料机构门禁被打开"), MsgLevel.warning);
}
//if (IOManager.GetDIValue("",0,16).Equals(IO_VALUE.LOW))
//{
// ok = false;
// DeviceSuddenStop();
// Msg.add(crc.GetString("device_safedoor_open", "贴标或出料机构门禁被打开"), MsgLevel.warning);
//}
lastSafeCheckStatus = ok;
return ok;
}
......
......@@ -32,6 +32,7 @@ namespace DeviceLibrary
XRay_01_LocationDown,
XRay_02_RunIn,
XRay_02_CheckReel,
XRay_03_CloseDoor,
XRay_04_OpenXray,
XRay_04_CheckXray,
......
......@@ -113,7 +113,7 @@ namespace DeviceLibrary
}
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.log($"按下入料按钮, 定位气缸下降");
......@@ -201,17 +201,17 @@ namespace DeviceLibrary
var Tray15 = Math.Max(Tray15_L, Tray15_R);
Debug.WriteLine($"Tray7:{Tray7},Tray13:{Tray13},Tray15:{Tray15}");
int v=0;
if (Tray15 < overhight && Tray15>0)
if (Tray15 < overhight && Tray15>4)
{
if (SensorDebounce.Debounce(Tray15, out v))
TrayWidth = 15;
}
else if (Tray13 < overhight && Tray13>0)
else if (Tray13 < overhight && Tray13>4)
{
if (SensorDebounce.Debounce(Tray13, out v))
TrayWidth = 13;
}
else if (Tray7 < overhight && Tray7 > 0)
else if (Tray7 < overhight && Tray7 > 4)
{
if (SensorDebounce.Debounce(Tray7, out v))
TrayWidth = 7;
......
......@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CodeLibrary;
using ConfigHelper;
using Newtonsoft.Json;
using OnlineStore.Common;
using OnlineStore.LoadCSVLibrary;
......@@ -27,6 +28,7 @@ namespace DeviceLibrary
bool ExitLine_Reel_IsSafe {
get => SideMoveInfo.MoveStep == MoveStep.Wait || SideMoveInfo.MoveStep >= MoveStep.SideMove_07;
}
int ZDiff = 0;
void SideMoveProcess()
{
if (CheckWait(SideMoveInfo))
......@@ -41,6 +43,13 @@ namespace DeviceLibrary
SideMoveInfo.ReelParam = ExitLine_Reel_Info.clone();
SideMoveInfo.log("检测到料盘到位");
}
else if (ExitLine_Reel_Info != null)
{
if (SideMoveInfo.IsTimeOut(10)) {
Msg.add("等待料盘到达横移机构超时", MsgLevel.warning);
SideMoveInfo.log("等待料盘到达横移机构超时");
}
}
else
{
Msg.add("横移机构等待料盘", MsgLevel.info);
......@@ -48,7 +57,6 @@ namespace DeviceLibrary
break;
case MoveStep.SideMove_01:
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);
SideMoveInfo.log("出料档停退到P1");
suckReelRetryTimes = 0;
......@@ -61,12 +69,16 @@ namespace DeviceLibrary
case MoveStep.SideMove_03:
SideMoveInfo.NextMoveStep(MoveStep.SideMove_04);
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);
CylinderMove(SideMoveInfo, IO_XRay_Type.SideMove_SuckerReel_Off, IO_XRay_Type.SideMove_SuckerReel_On, IO_VALUE.HIGH);
SideMoveInfo.log("升降轴到取料点P2:"+ p2);
break;
case MoveStep.SideMove_04:
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;
case MoveStep.SideMove_05:
SideMoveInfo.NextMoveStep(MoveStep.SideMove_06);
......
......@@ -29,6 +29,7 @@ namespace DeviceLibrary
public int relmove;
const string xraydir = @"\Image\Xray";
Task GetResultTask = null;
bool needhome = false;
void WorkProcess()
{
if (CheckWait(MoveInfo))
......@@ -45,7 +46,7 @@ namespace DeviceLibrary
CylinderMove(null, IO_XRay_Type.Entry_Close, IO_XRay_Type.Entry_Open, IO_VALUE.HIGH);
break;
case MoveStep.XRay_02_RunIn:
MoveInfo.NextMoveStep(MoveStep.XRay_03_CloseDoor);
MoveInfo.NextMoveStep(MoveStep.XRay_02_CheckReel);
MoveInfo.log($"入料伺服相对运转");
//Line_Entry_Axis.RelMove(ResetMoveInfo, Config.Line_Entry_Relative, Config.Line_Entry_Relative_speed);
Line_Entry_Axis.SpeedMove(Config.Line_Entry_Relative_speed);
......@@ -53,6 +54,19 @@ namespace DeviceLibrary
MoveInfo.WaitList.Add(WaitResultInfo.WaitTime(1000));
//MoveInfo.WaitList.Add(WaitResultInfo.WaitIO(IO_XRay_Type.Tray_Inside_Check, IO_VALUE.HIGH));
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:
MoveInfo.NextMoveStep(MoveStep.XRay_04_OpenXray);
MoveInfo.log($"关闭点料机入口门");
......@@ -177,10 +191,16 @@ namespace DeviceLibrary
if (ExitLine_Reel_IsSafe && ExitLine_Reel_Info==null)
{
MoveInfo.NextMoveStep(MoveStep.XRay_10_CloseOutDoor);
MoveInfo.log($"打开出口门,送出到贴标机构");
Line_In_Axis.SpeedMove(Config.Line_In_Relative_speed * 2);
MoveInfo.log($"打开出口门,送出到贴标机构,W:{MoveInfo.ReelParam.PlateW}");
Line_In_Axis.RelMove(MoveInfo, Config.Line_In_Relative, Config.Line_In_Relative_speed);
IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.HIGH);
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))
......@@ -192,12 +212,19 @@ namespace DeviceLibrary
case MoveStep.XRay_10_CloseOutDoor:
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.log($"关闭出口门,停止X光机内线体");
Line_In_Axis.SuddenStop();
CylinderMove(null, IO_XRay_Type.Exit_Close, IO_XRay_Type.Exit_Open, IO_VALUE.LOW);
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))
{
......
......@@ -129,7 +129,8 @@ namespace DeviceLibrary
{
ProcessMsgEventFire(Msg);
//ProcessMoveinfoEventFire(MoveInfo.List);
Msg.Clear();
if (canRunning && mstart)
Msg.Clear();
}
}
LogUtil.info($"{DeviceName} 主线程已退出.");
......@@ -218,7 +219,13 @@ namespace DeviceLibrary
case MoveStep.H01_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.H02_HomeReset);
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.Exit_Close, IO_XRay_Type.Exit_Open);
SideMove_Z_Axis.HomeMove(ResetMoveInfo);
......@@ -226,14 +233,17 @@ namespace DeviceLibrary
break;
case MoveStep.H02_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);
IOMove(IO_XRay_Type.ExitLine_Reel_Run, IO_VALUE.HIGH);
SideMove_X_Axis.HomeMove(ResetMoveInfo);
ResetMoveInfo.log("正在回原");
break;
case MoveStep.H03_HomeReset:
ResetMoveInfo.NextMoveStep(MoveStep.HEND_HomeReset);
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.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);
......@@ -241,8 +251,10 @@ namespace DeviceLibrary
case MoveStep.HEND_HomeReset:
ResetMoveInfo.log("回源完成");
ResetMoveInfo.EndMove();
//MoveInfo.NewMove(MoveStep.Feeding_05_Goto_Xray);
runStatus = RunStatus.Running;
FeedingMoveinfo.EndMove();
MoveInfo.EndMove();
SideMoveInfo.EndMove();
break;
}
}
......
......@@ -159,7 +159,7 @@ namespace DeviceLibrary
int errorCount = Math.Abs(outCount - targetPosition);
if (isOk)
{
if (errorCount <= axis.CanErrorCountMax)
if (errorCount <= axis.CanErrorCountMax || GetLimitPositiveSingle(axis) == 1)
{
return true;
}
......@@ -200,6 +200,16 @@ namespace DeviceLibrary
}
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)
{
msg = "";
......
......@@ -44,10 +44,14 @@ namespace DeviceLibrary
set
{
_WareCode = value;
var w = _WareCode.Split('|');
if (w.Length == 5) {
PN = w[0];
ReeID = w[3];
if (!string.IsNullOrEmpty(_WareCode))
{
var w = _WareCode.Split('|');
if (w.Length == 5)
{
PN = w[0];
ReeID = w[3];
}
}
}
}
......
......@@ -50,8 +50,9 @@
<Reference Include="halcondotnet">
<HintPath>..\..\RC1271-DUOStore\dll\halcondotnet.dll</HintPath>
</Reference>
<Reference Include="HuichuanLibrary">
<HintPath>..\..\HuichuanLibrary\HuichuanLibrary\bin\Debug\HuichuanLibrary.dll</HintPath>
<Reference Include="HuichuanLibrary, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\HuichuanLibrary\HuichuanLibrary\bin\Debug\HuichuanLibrary.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
......
......@@ -12,82 +12,56 @@ using CodeLibrary;
using System.Drawing.Imaging;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Threading;
using System.Runtime.InteropServices;
using System.Drawing.Drawing2D;
using HalconDotNet;
using System.Web;
namespace DeviceLibrary
{
public class CodeManager
{
public static string CodeType = ConfigAppSettings.GetValue(Setting_Init.CodeType);
private static int QRCodeCount = ConfigAppSettings.GetIntValue(Setting_Init.QRCodeCount);
public static string CodeType = Setting_Init.Camera_CodeType;
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> codeTypeList = 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 = '#';
/// <summary>
/// 初始化摄像机名称和二维码类型
/// </summary>
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);
var cl = code_block_size_list.Split(',');
foreach (string s in cl)
{
int i;
if (int.TryParse(s, out i))
{
Code_Block_Size_List.Add(i);
}
}
if (Code_Block_Size_List.Count == 0)
Code_Block_Size_List.Add(19);
string nameStr = ConfigAppSettings.GetValue(Setting_Init.CameraName);
codeTypeList = new List<string>();
string[] codeArray = CodeType.Split(spiltChar);
foreach (string str in codeArray)
{
if (str.Trim().Equals(""))
{
continue;
}
string file = GetCodeParamFilePath(str.Trim());
LogUtil.info("加载到配置二维码类型:" + str.Trim() + ",配置文件:" + file);
codeTypeList.Add(str.Trim());
}
HDLogUtil.LogName = "RollingLogFileAppender";
try
{
string[] nameArray = nameStr.Split(spiltChar);
foreach (string str in nameArray)
LoadCamera(true);
codeTypeList = new List<string>();
string[] codeArray = CodeType.Split(spiltChar);
foreach (string str in codeArray)
{
if (str.Trim().Equals(""))
{
continue;
}
//LogUtil.info("加载到配置摄像机名称:" + str.Trim());
cameraNameList.Add(str.Trim());
string file = GetCodeParamFilePath(str.Trim());
LogUtil.info("加载到配置二维码类型:" + str.Trim() + ",配置文件:" + file);
codeTypeList.Add(str.Trim());
}
LoadCamera(false);
CodeLibrary.HDCodeLearnHelper.LoadConfig("", CodeType);
//如果未加载到配置相机,自动配置
if (cameraNameList.Count <= 0 && hikNameList.Count > 0)
{
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)
......@@ -95,7 +69,9 @@ namespace DeviceLibrary
LogUtil.error("解析摄像机配置出错:" + ex.StackTrace);
}
}
private static void LoadCamera(bool isReLoad)
public static void LoadCamera(bool isReLoad)
{
if (isReLoad || Camera._cam == null)
{
......@@ -141,252 +117,159 @@ namespace DeviceLibrary
{
Camera._cam.CloseAll();
}
public static List<CodeInfo> CameraScan(List<string> cameraNameList)
{
var x = CameraScan(cameraNameList, out Bitmap bitmap);
bitmap.Dispose();
return x;
}
[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>();
bitmap = null;
string bitmapfilename = "";
if (cameraNameList == null || cameraNameList.Count <= 0)
{
throw new Exception("CameraScan方法没有传入相机名称.");
}
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[i];
if (cameraName.Trim().Equals(""))
{
continue;
}
DateTime startTime = DateTime.Now;
LogUtil.info(" 【" + cameraName + "】开始取图片");
HalconDotNet.HObject ho_Image = null;
Bitmap bmp = null;
try
var cameraName = cameraNameList[ii];
var idx = ii;
cameraTask[ii] = Task.Run(new Action(() =>
{
bool nohalcon = false;
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp, nohalcon);
bitmap = Common.DeepClone(bmp);
if (ho_Image == null && !nohalcon)
int retrytime = 0;
retry:
LogUtil.info($"【" + cameraName + "】开始取图片");
if (cameraName.Trim().Equals(""))
{
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
CloseCamera(cameraName);
continue;
return;
}
LogUtil.info(" 【" + cameraName + "】取图片完成,开始扫码");
string r = "";
//foreach (int codesize in Code_Block_Size_List)
DateTime startTime = DateTime.Now;
HalconDotNet.HObject ho_Image = null;
Bitmap bmp = null;
try
{
List<CodeInfo> tlci = EyemDecode2.Decoder(ref bmp, null);
foreach (CodeInfo code in tlci)
bool nohalcon = true;
ho_Image = Camera._cam.CaptureOnImage(cameraName, out bmp, nohalcon);
if (bmp == null)
{
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 (retrytime > 2)
return;
retrytime++;
LoadCamera(true);
LogUtil.info($"bitmap为空重试第{retrytime}次");
Task.Delay(1500).Wait();
goto retry;
}
}
if (!nohalcon && codeList.Count==0)
{
//HalconDotNet.HOperatorSet.RotateImage()
if (ho_Image == null && !nohalcon)
{
LogUtil.error(" 【" + cameraName + "】取图片失败[" + Camera._cam.ErrInfo + "],关闭相机");
LoadCamera(true);
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>();
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);
}
LogUtil.info(" 【" + cameraName + "】[Halcon]" + codeType + "," + QRCodeCount + ","+ cc.Count);
foreach (CodeInfo c in cc)
cc.ForEach((c) =>
{
LogUtil.info(" 【" + cameraName + "】[Halcon]" + c.CodeType + "(X: " + c.X + ",Y: " + c.Y + ") " + c.CodeStr);
LogUtil.info(c.CodeStr);
c.CodeStr = CodeManager.ReplaceCode(c.CodeStr);
lock (codeList)
{
if (!codeList.Contains(c) && HasRightCode(c.CodeStr))
if (!codeList.Any(a=>a.CodeStr == c.CodeStr) && HasRightCode(c.CodeStr))
{
codeList.Add(c);
r = r + "##" + c.CodeStr;
}
}
}
});
}
else
{
bitmapfilename = SaveImageToFile("mimo", cameraName, bmp);
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
}
if (codeList.Count() != 1)
catch (AccessViolationException e)
{
SaveImageToFile("mimo"+ codeList.Count(), cameraName, bmp);
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
// GC.Collect();
}
LogUtil.info(" 【" + cameraName + "】" + " 扫码完成【" + FormUtil.GetSpanStr(DateTime.Now - startTime) + "】 :" + r);
}
catch (AccessViolationException e)
{
LogUtil.error(" 扫码出现AccessViolationException异常,关闭相机【" + cameraName + "】:" + e.ToString());
Camera._cam.Close(cameraName);
// GC.Collect();
}
catch (Exception ex)
{
LogUtil.error(" 扫码出错:" + ex.ToString());
}
finally
{
if (ho_Image != null)
catch (Exception ex)
{
ho_Image.Dispose();
LogUtil.error(" 扫码出错:" + ex.ToString());
}
if (bmp != null)
bmp.Dispose();
}
finally
{
if (ho_Image != null)
{
ho_Image.Dispose();
}
if (bmp != null)
bmp.Dispose();
}
}));
Task.Delay(ii * 700).Wait();
}
//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)
{
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++)
while (!cameraTask[0].IsCompleted)
{
var cameraName = cameraNameList[i];
if (cameraName.Trim().Equals(""))
{
continue;
}
LogUtil.info(" 【" + cameraName + "】开始取图片处理例程");
try
{
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)
{
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 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 dire = @"D:\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string dire = @"\image\" + deviceName.Trim().Replace('_', '-') + @"\" + cameraName.Trim().Replace('_', '-').Replace(':', '-') + @"\";
string iamgeName = date + ".bmp";
try
{
Bitmap bit = (Bitmap)bitmap.Clone();
if (Directory.Exists(dire).Equals(false))
{
Directory.CreateDirectory(dire);
}
bit.Save(dire + iamgeName, ImageFormat.Bmp);
bit.Dispose();
LogUtil.info(deviceName + " 【" + cameraName + "】扫码失败,保存图片到【" + dire + iamgeName + "】成功");
bitmap.Save(dire + iamgeName, ImageFormat.Bmp);
//bitmap.Dispose();
LogUtil.info(deviceName + " 【" + cameraName + "】扫码完成,保存图片到【" + dire + iamgeName + "】成功");
}
catch (Exception ex)
{
LogUtil.error("保存" + deviceName + " 【" + cameraName + "】的图片到【" + dire + iamgeName + "】出错" + ex.ToString());
}
return dire + iamgeName;
}
/// <summary>
......@@ -427,6 +310,21 @@ namespace DeviceLibrary
{
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)
{
//78.10222.20L-016651|-20200826|900|W78016651352000A6|SAMSUNG
......
......@@ -110,7 +110,7 @@ namespace DeviceLibrary
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)
{
......
......@@ -457,7 +457,6 @@ namespace AutoCountMachine
this.Controls.Add(this.btn_stop);
this.Controls.Add(this.btn_run);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Neo Counter X800";
......
......@@ -214,4 +214,7 @@
<Content Include="icon.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>start $(TargetDir)</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -361,7 +361,7 @@ namespace AutoCountMachine
RobotManage.xrayMachine.IOMove(IO_XRay_Type.Xray_Lock, IO_VALUE.HIGH);
Task.Delay(1000).Wait();
RobotManage.XRay.Start();
Task.Delay(2000).Wait();
Task.Delay(5000).Wait();
var b = RobotManage.xrayImage.GenerateTemplate(2);
b.Wait();
if (b.Result)
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!