Commit 227f7be8 LN

fuwei

1 个父辈 8f31be6a
此文件类型无法预览
此文件太大,无法显示。
......@@ -38,6 +38,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>true</Prefer32Bit>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
......
......@@ -106,7 +106,8 @@ namespace OnlineStore.AssemblyLine
{
if (equipBase.runStatus >= LineRunStatus.HomeMoving)
{
equipBase.StopRun();
equipBase.StopRun();
FormStatus(false);
}
else
{
......
......@@ -127,9 +127,9 @@
this.groupBox1.Controls.Add(this.txtWriteTime);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.groupBox1.Location = new System.Drawing.Point(3, 488);
this.groupBox1.Location = new System.Drawing.Point(3, 527);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(394, 158);
this.groupBox1.Size = new System.Drawing.Size(394, 169);
this.groupBox1.TabIndex = 105;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "DO写入";
......@@ -276,7 +276,7 @@
this.groupBox4.Controls.Add(this.tableLayoutPanel2);
this.groupBox4.Location = new System.Drawing.Point(488, 6);
this.groupBox4.Name = "groupBox4";
this.groupBox4.Size = new System.Drawing.Size(240, 475);
this.groupBox4.Size = new System.Drawing.Size(240, 519);
this.groupBox4.TabIndex = 104;
this.groupBox4.TabStop = false;
this.groupBox4.Text = "DO列表";
......@@ -293,7 +293,7 @@
this.tableLayoutPanel2.RowCount = 2;
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel2.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel2.Size = new System.Drawing.Size(229, 455);
this.tableLayoutPanel2.Size = new System.Drawing.Size(229, 499);
this.tableLayoutPanel2.TabIndex = 103;
//
// groupBox3
......@@ -303,7 +303,7 @@
this.groupBox3.Controls.Add(this.tableLayoutPanel1);
this.groupBox3.Location = new System.Drawing.Point(6, 6);
this.groupBox3.Name = "groupBox3";
this.groupBox3.Size = new System.Drawing.Size(240, 475);
this.groupBox3.Size = new System.Drawing.Size(240, 519);
this.groupBox3.TabIndex = 103;
this.groupBox3.TabStop = false;
this.groupBox3.Text = "DI列表";
......@@ -320,7 +320,7 @@
this.tableLayoutPanel1.RowCount = 2;
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel1.Size = new System.Drawing.Size(229, 455);
this.tableLayoutPanel1.Size = new System.Drawing.Size(229, 499);
this.tableLayoutPanel1.TabIndex = 102;
//
// groupBox5
......@@ -345,7 +345,7 @@
this.groupBox5.Controls.Add(this.btnFeedSideWay);
this.groupBox5.Location = new System.Drawing.Point(974, 6);
this.groupBox5.Name = "groupBox5";
this.groupBox5.Size = new System.Drawing.Size(338, 475);
this.groupBox5.Size = new System.Drawing.Size(338, 519);
this.groupBox5.TabIndex = 255;
this.groupBox5.TabStop = false;
this.groupBox5.Text = "IO操作测试";
......@@ -657,10 +657,10 @@
| System.Windows.Forms.AnchorStyles.Right)));
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(5, 69);
this.tabControl1.Location = new System.Drawing.Point(5, 64);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(1327, 687);
this.tabControl1.Size = new System.Drawing.Size(1327, 731);
this.tabControl1.TabIndex = 257;
//
// tabPage1
......@@ -675,7 +675,7 @@
this.tabPage1.Location = new System.Drawing.Point(4, 26);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(1319, 657);
this.tabPage1.Size = new System.Drawing.Size(1319, 701);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = " IO列表 ";
this.tabPage1.UseVisualStyleBackColor = true;
......@@ -688,9 +688,9 @@
this.groupBox6.Controls.Add(this.lblAgvInfo);
this.groupBox6.Controls.Add(this.lblInstoreList);
this.groupBox6.Controls.Add(this.lblThisSta);
this.groupBox6.Location = new System.Drawing.Point(403, 488);
this.groupBox6.Location = new System.Drawing.Point(403, 527);
this.groupBox6.Name = "groupBox6";
this.groupBox6.Size = new System.Drawing.Size(909, 160);
this.groupBox6.Size = new System.Drawing.Size(909, 171);
this.groupBox6.TabIndex = 278;
this.groupBox6.TabStop = false;
this.groupBox6.Text = "消息";
......@@ -711,7 +711,7 @@
this.lblAgvInfo.AutoSize = true;
this.lblAgvInfo.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblAgvInfo.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.lblAgvInfo.Location = new System.Drawing.Point(237, 29);
this.lblAgvInfo.Location = new System.Drawing.Point(248, 25);
this.lblAgvInfo.Name = "lblAgvInfo";
this.lblAgvInfo.Size = new System.Drawing.Size(61, 17);
this.lblAgvInfo.TabIndex = 276;
......@@ -736,7 +736,7 @@
this.groupBox7.Controls.Add(this.tableLayoutPanel3);
this.groupBox7.Location = new System.Drawing.Point(247, 6);
this.groupBox7.Name = "groupBox7";
this.groupBox7.Size = new System.Drawing.Size(240, 475);
this.groupBox7.Size = new System.Drawing.Size(240, 519);
this.groupBox7.TabIndex = 279;
this.groupBox7.TabStop = false;
this.groupBox7.Text = "DI列表";
......@@ -753,7 +753,7 @@
this.tableLayoutPanel3.RowCount = 2;
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel3.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel3.Size = new System.Drawing.Size(229, 455);
this.tableLayoutPanel3.Size = new System.Drawing.Size(229, 499);
this.tableLayoutPanel3.TabIndex = 102;
//
// groupBox8
......@@ -763,7 +763,7 @@
this.groupBox8.Controls.Add(this.tableLayoutPanel4);
this.groupBox8.Location = new System.Drawing.Point(728, 6);
this.groupBox8.Name = "groupBox8";
this.groupBox8.Size = new System.Drawing.Size(240, 475);
this.groupBox8.Size = new System.Drawing.Size(240, 519);
this.groupBox8.TabIndex = 280;
this.groupBox8.TabStop = false;
this.groupBox8.Text = "DO列表";
......@@ -780,7 +780,7 @@
this.tableLayoutPanel4.RowCount = 2;
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel4.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 17F));
this.tableLayoutPanel4.Size = new System.Drawing.Size(229, 455);
this.tableLayoutPanel4.Size = new System.Drawing.Size(229, 499);
this.tableLayoutPanel4.TabIndex = 103;
//
// tabPage2
......@@ -1082,7 +1082,7 @@
this.panel1.Controls.Add(this.btnReset);
this.panel1.Location = new System.Drawing.Point(2, 1);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(1326, 68);
this.panel1.Size = new System.Drawing.Size(1326, 62);
this.panel1.TabIndex = 258;
//
// chbMoveStop
......@@ -1126,7 +1126,7 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 17F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1338, 762);
this.ClientSize = new System.Drawing.Size(1338, 797);
this.Controls.Add(this.panel1);
this.Controls.Add(this.tabControl1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
......
......@@ -258,7 +258,7 @@ namespace OnlineStore.AssemblyLine
IOManager.instance.CloseAllConnection();
//AIManager.CloseConnect();
ACServerManager.CloseAllPort();
CodeManager.CloseAllCamera();
// CodeManager.CloseAllCamera();
RFIDManager.CloseAllConnection();
//this.Close();
System.Environment.Exit(System.Environment.ExitCode);
......
......@@ -140,9 +140,8 @@ namespace OnlineStore.AssemblyLine
string[] ip = RFIDManager.SearchIP(text);
foreach(string ipstr in ip)
{
txtSearchIp.Text += ipstr + "\n";
listView1.Items.Add(ipstr);
}
// txtSearchIp.Text = ip;
}
private void btnConnect_Click(object sender, EventArgs e)
......
......@@ -8,9 +8,9 @@ PRO,0,上料流水线入口AGV小车站号名称,AgvInName,D1,,,,,
PRO,0,上料流水线出口AGV小车站号名称,AgvOutName,D2,,,,,
,,,,,,,,,
AXIS,0,提升上料轴,Batch_Axis,5,COM5,0,,,
PRO,0,提升上料轴上升待机点 P1,BatchAxisP1,10000,,,,,
PRO,0,提升上料轴下降位置P2,BatchAxisP2,-2000,,,,,
PRO,0,提升上料缓慢上升目标位置P3,BatchAxisP3,10000,,,,,
PRO,0,提升上料轴上升待机点 P1,BatchAxisP1,23453414,,,,,
PRO,0,提升上料轴下降位置P2,BatchAxisP2,0,,,,,
PRO,0,提升上料缓慢上升目标位置P3,BatchAxisP3,22283118,,,,,
PRO,0,提升上料轴目标速度,BatchAxis_TargetSpeed,1500,,,,,
PRO,0,提升上料轴加速度,BatchAxis_AddSpeed,400,,,,,
PRO,0,提升上料轴减速度,BatchAxis_DelSpeed,400,,,,,
......@@ -24,8 +24,8 @@ PRO,0,提升上料轴高度转换系数(1mm对应的脉冲),Height_ChangeValue,5000,,,,,
,,,,,,,,,
AXIS,0,移栽上下轴,UpDown_Axis,6,COM5,0,,,
PRO,0,移栽上下轴待机点 P1,UpDownAxisP1,2000,,,,,
PRO,0,移栽上下轴P2移栽机构下降位置,UpDownP2List,0=180000;,,,,,
PRO,0,移栽上下轴P3取料位置,UpDownAxisP3,20000,,,,,
PRO,0,移栽上下轴P2移栽机构下降位置,UpDownP2List,0=180000,,,,,
PRO,0,移栽上下轴P3取料位置,UpDownAxisP3,310000,,,,,
PRO,0,移栽上下轴目标速度,UpdownAxis_TargetSpeed,150,,,,,
PRO,0,移栽上下轴加速度,UpdownAxis_AddSpeed,400,,,,,
PRO,0,移栽上下轴减速度,UpdownAxis_DelSpeed,400,,,,,
......
......@@ -130,7 +130,7 @@ namespace OnlineStore.DeviceLibrary
lastProTimer = DateTime.Now;
try
{
if (IsDebug)
if (IsDebug&&runStatus<=LineRunStatus.Wait)
{
isInPro = false;
return;
......@@ -461,6 +461,8 @@ namespace OnlineStore.DeviceLibrary
msg += "preTrayNum:".PadRight(tLength, ' ') + preTrayNum + "\n";
msg += "currTrayNum:".PadRight(tLength, ' ') + currTrayNum + "\n";
msg += "runStatus:".PadRight(tLength, ' ') + runStatus + "\n";
msg += "lineStatus:".PadRight(tLength, ' ') + lineStatus + "\n";
msg += "MoveType:".PadRight(tLength, ' ') + MoveInfo.MoveType+"\n";
msg += "MoveStep:".PadRight(tLength, ' ') + MoveInfo.MoveStep + "\n";
msg += "SMoveType:".PadRight(tLength, ' ') + SecondMoveInfo.MoveType + "\n";
......
......@@ -64,8 +64,10 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.NewMove(LineMoveType.ReturnHome);
StartReset();
if (isDebug)
{
LogInfo("开始调试,启动定时器 ");
mainTimer.Start();
}
return true;
......@@ -138,12 +140,14 @@ namespace OnlineStore.DeviceLibrary
break;
case LineMoveStep.FR_01_MoveCylinder_Up:
MoveInfo.NextMoveStep(LineMoveStep.FR_02_BatchAxisHome);
MoveInfo.TimeOutSeconds = 120;
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.MoveStep + ":提升伺服回原点,升降伺服回原点,所有阻挡气缸上升");
BatchAxis.HomeMove(MoveInfo);
UpdownAxis.HomeMove(MoveInfo);
break;
case LineMoveStep.FR_02_BatchAxisHome:
LogInfo(MoveInfo.MoveType + ":FR_03_BatchAxisToP2:提升伺服下降到P2点,升降伺服上升到待机点");
MoveInfo.TimeOutSeconds = 120;
MoveInfo.NextMoveStep(LineMoveStep.FR_03_BatchAxisToP2);
BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
......@@ -182,9 +186,9 @@ namespace OnlineStore.DeviceLibrary
case LineMoveStep.FR_08_MoveCylinder_Slack:
if (MoveCylineCanTakeOrGive())
{
LogInfo(MoveInfo.MoveType + ":FR_09_MoveCylinder_Take: 上料横移气缸取料端SOL");
MoveInfo.NextMoveStep(LineMoveStep.FR_09_MoveCylinder_Take);
CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Give, IO_Type.SL_MoveCylinder_Take);
LogInfo(MoveInfo.MoveType + ":FR_09_MoveCylinder_Give: 上料横移气缸放料端SOL");
MoveInfo.NextMoveStep(LineMoveStep.FR_09_MoveCylinder_Give);
CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Take, IO_Type.SL_MoveCylinder_Give);
}
else
{
......@@ -193,7 +197,7 @@ namespace OnlineStore.DeviceLibrary
CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up);
}
break;
case LineMoveStep.FR_09_MoveCylinder_Take:
case LineMoveStep.FR_09_MoveCylinder_Give:
LogInfo(MoveInfo.MoveType + ":FR_10_OutTopCylinder_Down: 出口顶升下降SOL");
MoveInfo.NextMoveStep(LineMoveStep.FR_10_OutTopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SL_OutTopCylinder_Up, IO_Type.SL_OutTopCylinder_Down);
......@@ -201,6 +205,7 @@ namespace OnlineStore.DeviceLibrary
case LineMoveStep.FR_10_OutTopCylinder_Down:
LogInfo("重置完成!");
runStatus = LineRunStatus.Runing;
lineStatus = LineStatus.StoreOnline;
MoveInfo.EndMove();
break;
default: break;
......@@ -283,7 +288,7 @@ namespace OnlineStore.DeviceLibrary
{
StartCheckFixture();
}
if (MoveInfo.MoveType.Equals(LineMoveType.None) && Config.IsCanOut.Equals(false))
if ( Config.IsCanOut.Equals(false))
{
StartInStoreP();
}
......
......@@ -212,15 +212,20 @@ namespace OnlineStore.DeviceLibrary
public string CanStart()
{
if (MoveEquipMap == null)
{
return "启动失败:未加载到移栽信息";
}
if (IsDebug)
{
return "";
}
if (!canStart)
{
return "启动失败:设备未初始化完成" ;
}
if (MoveEquipMap == null)
{
return "启动失败:未加载到移栽信息";
}
if (IOValue(IO_Type.SuddenStop_BTN).Equals(IO_VALUE.LOW))
{
return "启动失败:急停未开";
......
......@@ -14,7 +14,7 @@ namespace OnlineStore.DeviceLibrary
public bool LineCanRun()
{
if (IOValue(IO_Type.Line_Run).Equals(IO_VALUE.HIGH))
//if (IOValue(IO_Type.Line_Run).Equals(IO_VALUE.HIGH))
{
return true;
}
......@@ -23,6 +23,10 @@ namespace OnlineStore.DeviceLibrary
public bool CanProcessLine(bool isCheckSleep = true)
{
if (IsDebug)
{
return true;
}
if (LineCanRun() &&
IOManager.IOValue(IO_Type.DriveMotor_Run1, 0).Equals(IO_VALUE.HIGH) &&
IOManager.IOValue(IO_Type.DriveMotor_Run2, 0).Equals(IO_VALUE.HIGH) &&
......
using CodeLibrary;
using CodeLibrary;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
......@@ -6,7 +6,7 @@ using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
using System.Text;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
......@@ -53,7 +53,7 @@ namespace OnlineStore.DeviceLibrary
{
try
{
CodeLibrary.HIKCManager.Load();
CodeLibrary.HIKCamera.Instance.Load();
}
catch (Exception ex)
{
......@@ -61,14 +61,14 @@ namespace OnlineStore.DeviceLibrary
}
try
{
CodeLibrary.BaslerCManager.Load();
CodeLibrary.BaslerCamera.Instance.Load();
}
catch (Exception ex)
{
LogUtil.error("加载Basler相机出错:" + ex.ToString());
}
}
string[] names = CodeLibrary.HIKCManager.CameraName;
string[] names = CodeLibrary.HIKCamera.Instance.CameraName;
if (names != null)
......@@ -79,7 +79,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info("加载到HIK相机:" + name);
}
}
names = CodeLibrary.BaslerCManager.CameraName;
names = CodeLibrary.BaslerCamera.Instance.CameraName;
if (names != null)
{
balserNameList.AddRange(names);
......@@ -89,23 +89,10 @@ namespace OnlineStore.DeviceLibrary
}
}
}
public static void CloseCamera(string name)
public static void CloseCamera()
{
//BaslerCamera.Instance.Close();
//HIKCamera.Instance.Close();
if (HIKCManager.CameraName.Contains(name))
{
HIKCManager.Close(name);
}
else
{
BaslerCManager.Close(name);
}
}
public static void CloseAllCamera()
{
HIKCManager.CloseAll();
BaslerCManager.CloseAll();
BaslerCamera.Instance.Close();
HIKCamera.Instance.Close();
}
public static Bitmap GetCamerImage(string cameraName)
......@@ -115,15 +102,13 @@ namespace OnlineStore.DeviceLibrary
{
if (balserNameList.Contains(cameraName))
{
bool result = true;
if (!BaslerCManager.IsOpen(cameraName))
{
result = BaslerCManager.Open(cameraName);
}
bool result = BaslerCamera.Instance.Open(cameraName);
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if (result)
{
bitm= BaslerCManager.GrabOne(cameraName);
BaslerCamera.Instance.GrabOne();
bitm = BaslerCamera.Instance.Image;
BaslerCamera.Instance.Close();
}
else
{
......@@ -132,16 +117,13 @@ namespace OnlineStore.DeviceLibrary
}
else if (hikNameList.Contains(cameraName))
{
bool result = true;
if (!HIKCManager.IsOpen(cameraName))
{
result = HIKCManager.Open(cameraName);
}
bool result = HIKCamera.Instance.Open(cameraName);
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if (result)
{
bitm = HIKCManager.GrabOne(cameraName);
HIKCamera.Instance.GrabOne();
bitm = HIKCamera.Instance.Image;
HIKCamera.Instance.Close();
}
else
{
......@@ -167,56 +149,54 @@ namespace OnlineStore.DeviceLibrary
}
[HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(List<string> cameraNameList )
public static List<string> CameraScan(List<string> cameraNameList = null)
{
List<string> codeList = new List<string>();
List<string> codeList = new List<string>();
//List<CodeInfo> allCodeList = new List<CodeInfo>();
if (cameraNameList == null)
{
return codeList;
}
try
{
List<Task<List<CodeInfo>>> taskList = new List<Task<List<CodeInfo>>>();
foreach (string cameraName in cameraNameList)
{
Task.Factory.StartNew(delegate ()
using (Bitmap bitmap = GetCamerImage(cameraName))
{
using (Bitmap bitmap = GetCamerImage(cameraName))
if (bitmap == null)
{
if (bitmap == null)
LogUtil.error(" 摄像机【" + cameraName + "】获取图片失败,关闭相机");
CloseCamera();
continue;
}
LogUtil.debug(" 摄像机【" + cameraName + "】获取图片完成");
System.Threading.Thread.Sleep(1);
HalconDotNet.HObject ho_Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
LogUtil.debug(" 摄像机【" + cameraName + "】转换图片完成,开始扫码");
List<CodeInfo> cc = new List<CodeInfo>();
foreach (string codeType in codeTypeList)
{
//判断是否是一维码
if (codeType.ToLower().Equals("barcode"))
{
LogUtil.error(" 摄像机【" + cameraName + "】获取图片失败,关闭相机");
CloseCamera(cameraName);
return;
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
LogUtil.debug(" 摄像机【" + cameraName + "】获取图片完成");
System.Threading.Thread.Sleep(1);
HalconDotNet.HObject ho_Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
LogUtil.debug(" 摄像机【" + cameraName + "】转换图片完成,开始扫码");
List<CodeInfo> cc = new List<CodeInfo>();
foreach (string codeType in codeTypeList)
else
{
Task<List<CodeInfo>> typeDeCode = new Task<List<CodeInfo>>(delegate ()
cc = HDCodeHelper.DecodeCode(ho_Image, 1, GetCodeParamFilePath(codeType), codeType);
}
if (cc.Count > 0)
{
string r = "";
foreach (CodeInfo c in cc)
{
return DeCode(ho_Image, codeType);
});
taskList.Add(typeDeCode);
typeDeCode.Start();
codeList.Add(c.CodeStr);
r = r + "##" + c.CodeStr;
}
LogUtil.debug(" 【" + cameraName + "】【" + codeType + "】扫码完成:"+r);
}
}
});
}
Task.WaitAll(taskList.ToArray());
foreach (Task<List<CodeInfo>> t in taskList)
{
List<CodeInfo> cc = t.Result;
if (cc.Count > 0)
{
string r = "";
foreach (CodeInfo c in cc)
{
codeList.Add(c.CodeStr);
r = r + "##" + c.CodeStr;
}
}
}
}
......@@ -228,34 +208,10 @@ namespace OnlineStore.DeviceLibrary
catch (Exception ex)
{
LogUtil.error("扫码出错:" + ex.ToString());
}
}
return codeList;
}
private static List<CodeInfo> DeCode(HalconDotNet.HObject ho_Image,string codeType)
{
List<CodeInfo> cc = new List<CodeInfo>();
//判断是否是一维码
if (codeType.ToLower().Equals("barcode"))
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, 1, GetCodeParamFilePath(codeType), codeType);
}
//if (cc.Count > 0)
//{
// string r = "";
// foreach (CodeInfo c in cc)
// {
// codeList.Add(c.CodeStr);
// r = r + "##" + c.CodeStr;
// }
// LogUtil.debug(" 【" + cameraName + "】【" + codeType + "】扫码完成:" + r);
//}
return cc;
}
public static string GetCodeParamFilePath(string codePath)
{
......
using CodeLibrary;
using CodeLibrary;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
......@@ -6,7 +6,7 @@ using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary
......@@ -53,7 +53,7 @@ namespace OnlineStore.DeviceLibrary
{
try
{
CodeLibrary.HIKCamera.Instance.Load();
CodeLibrary.HIKCManager.Load();
}
catch (Exception ex)
{
......@@ -61,14 +61,14 @@ namespace OnlineStore.DeviceLibrary
}
try
{
CodeLibrary.BaslerCamera.Instance.Load();
CodeLibrary.BaslerCManager.Load();
}
catch (Exception ex)
{
LogUtil.error("加载Basler相机出错:" + ex.ToString());
}
}
string[] names = CodeLibrary.HIKCamera.Instance.CameraName;
string[] names = CodeLibrary.HIKCManager.CameraName;
if (names != null)
......@@ -79,7 +79,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info("加载到HIK相机:" + name);
}
}
names = CodeLibrary.BaslerCamera.Instance.CameraName;
names = CodeLibrary.BaslerCManager.CameraName;
if (names != null)
{
balserNameList.AddRange(names);
......@@ -89,10 +89,23 @@ namespace OnlineStore.DeviceLibrary
}
}
}
public static void CloseCamera()
public static void CloseCamera(string name)
{
BaslerCamera.Instance.Close();
HIKCamera.Instance.Close();
//BaslerCamera.Instance.Close();
//HIKCamera.Instance.Close();
if (HIKCManager.CameraName.Contains(name))
{
HIKCManager.Close(name);
}
else
{
BaslerCManager.Close(name);
}
}
public static void CloseAllCamera()
{
HIKCManager.CloseAll();
BaslerCManager.CloseAll();
}
public static Bitmap GetCamerImage(string cameraName)
......@@ -102,13 +115,15 @@ namespace OnlineStore.DeviceLibrary
{
if (balserNameList.Contains(cameraName))
{
bool result = BaslerCamera.Instance.Open(cameraName);
bool result = true;
if (!BaslerCManager.IsOpen(cameraName))
{
result = BaslerCManager.Open(cameraName);
}
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if (result)
{
BaslerCamera.Instance.GrabOne();
bitm = BaslerCamera.Instance.Image;
BaslerCamera.Instance.Close();
bitm= BaslerCManager.GrabOne(cameraName);
}
else
{
......@@ -117,13 +132,16 @@ namespace OnlineStore.DeviceLibrary
}
else if (hikNameList.Contains(cameraName))
{
bool result = HIKCamera.Instance.Open(cameraName);
bool result = true;
if (!HIKCManager.IsOpen(cameraName))
{
result = HIKCManager.Open(cameraName);
}
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if (result)
{
HIKCamera.Instance.GrabOne();
bitm = HIKCamera.Instance.Image;
HIKCamera.Instance.Close();
bitm = HIKCManager.GrabOne(cameraName);
}
else
{
......@@ -149,54 +167,56 @@ namespace OnlineStore.DeviceLibrary
}
[HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(List<string> cameraNameList = null)
public static List<string> CameraScan(List<string> cameraNameList )
{
List<string> codeList = new List<string>();
//List<CodeInfo> allCodeList = new List<CodeInfo>();
if (cameraNameList == null)
{
return codeList;
}
List<string> codeList = new List<string>();
try
{
List<Task<List<CodeInfo>>> taskList = new List<Task<List<CodeInfo>>>();
foreach (string cameraName in cameraNameList)
{
using (Bitmap bitmap = GetCamerImage(cameraName))
Task.Factory.StartNew(delegate ()
{
if (bitmap == null)
using (Bitmap bitmap = GetCamerImage(cameraName))
{
LogUtil.error(" 摄像机【" + cameraName + "】获取图片失败,关闭相机");
CloseCamera();
continue;
}
LogUtil.debug(" 摄像机【" + cameraName + "】获取图片完成");
System.Threading.Thread.Sleep(1);
HalconDotNet.HObject ho_Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
LogUtil.debug(" 摄像机【" + cameraName + "】转换图片完成,开始扫码");
List<CodeInfo> cc = new List<CodeInfo>();
foreach (string codeType in codeTypeList)
{
//判断是否是一维码
if (codeType.ToLower().Equals("barcode"))
if (bitmap == null)
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
LogUtil.error(" 摄像机【" + cameraName + "】获取图片失败,关闭相机");
CloseCamera(cameraName);
return;
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, 1, GetCodeParamFilePath(codeType), codeType);
}
if (cc.Count > 0)
LogUtil.debug(" 摄像机【" + cameraName + "】获取图片完成");
System.Threading.Thread.Sleep(1);
HalconDotNet.HObject ho_Image = HDCodeHelper.Bitmap2HObjectBpp24(bitmap);
LogUtil.debug(" 摄像机【" + cameraName + "】转换图片完成,开始扫码");
List<CodeInfo> cc = new List<CodeInfo>();
foreach (string codeType in codeTypeList)
{
string r = "";
foreach (CodeInfo c in cc)
Task<List<CodeInfo>> typeDeCode = new Task<List<CodeInfo>>(delegate ()
{
codeList.Add(c.CodeStr);
r = r + "##" + c.CodeStr;
}
LogUtil.debug(" 【" + cameraName + "】【" + codeType + "】扫码完成:"+r);
return DeCode(ho_Image, codeType);
});
taskList.Add(typeDeCode);
typeDeCode.Start();
}
}
});
}
Task.WaitAll(taskList.ToArray());
foreach (Task<List<CodeInfo>> t in taskList)
{
List<CodeInfo> cc = t.Result;
if (cc.Count > 0)
{
string r = "";
foreach (CodeInfo c in cc)
{
codeList.Add(c.CodeStr);
r = r + "##" + c.CodeStr;
}
}
}
}
......@@ -208,10 +228,34 @@ namespace OnlineStore.DeviceLibrary
catch (Exception ex)
{
LogUtil.error("扫码出错:" + ex.ToString());
}
}
return codeList;
}
private static List<CodeInfo> DeCode(HalconDotNet.HObject ho_Image,string codeType)
{
List<CodeInfo> cc = new List<CodeInfo>();
//判断是否是一维码
if (codeType.ToLower().Equals("barcode"))
{
cc = HDCodeHelper.DecodeBarCode(ho_Image);
}
else
{
cc = HDCodeHelper.DecodeCode(ho_Image, 1, GetCodeParamFilePath(codeType), codeType);
}
//if (cc.Count > 0)
//{
// string r = "";
// foreach (CodeInfo c in cc)
// {
// codeList.Add(c.CodeStr);
// r = r + "##" + c.CodeStr;
// }
// LogUtil.debug(" 【" + cameraName + "】【" + codeType + "】扫码完成:" + r);
//}
return cc;
}
public static string GetCodeParamFilePath(string codePath)
{
......
......@@ -507,7 +507,7 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
///上料装置:上料横移气缸取料端SOL
/// </summary>
FR_09_MoveCylinder_Take = 10009,
FR_09_MoveCylinder_Give = 10009,
/// <summary>
///上料装置:出口顶升下降SOL
/// </summary>
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!