Commit 3078ab8b LN

1

1 个父辈 cf79dc62
...@@ -39,16 +39,9 @@ ...@@ -39,16 +39,9 @@
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.numNum = new System.Windows.Forms.NumericUpDown(); this.numNum = new System.Windows.Forms.NumericUpDown();
this.txtSearchIp = new System.Windows.Forms.TextBox();
this.btnSearch = new System.Windows.Forms.Button();
this.cmbLocalIp = new System.Windows.Forms.ComboBox();
this.label5 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label6 = new System.Windows.Forms.Label();
this.groupBox2 = new System.Windows.Forms.GroupBox(); this.groupBox2 = new System.Windows.Forms.GroupBox();
this.lblResult = new System.Windows.Forms.Label(); this.lblResult = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numNum)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numNum)).BeginInit();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
...@@ -168,75 +161,6 @@ ...@@ -168,75 +161,6 @@
this.numNum.Size = new System.Drawing.Size(120, 26); this.numNum.Size = new System.Drawing.Size(120, 26);
this.numNum.TabIndex = 283; this.numNum.TabIndex = 283;
// //
// txtSearchIp
//
this.txtSearchIp.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.txtSearchIp.Location = new System.Drawing.Point(196, 87);
this.txtSearchIp.Name = "txtSearchIp";
this.txtSearchIp.Size = new System.Drawing.Size(233, 26);
this.txtSearchIp.TabIndex = 286;
//
// btnSearch
//
this.btnSearch.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnSearch.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnSearch.Location = new System.Drawing.Point(446, 68);
this.btnSearch.Name = "btnSearch";
this.btnSearch.Size = new System.Drawing.Size(120, 45);
this.btnSearch.TabIndex = 287;
this.btnSearch.Text = "搜索IP";
this.btnSearch.UseVisualStyleBackColor = false;
this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
//
// cmbLocalIp
//
this.cmbLocalIp.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbLocalIp.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.cmbLocalIp.FormattingEnabled = true;
this.cmbLocalIp.Location = new System.Drawing.Point(196, 38);
this.cmbLocalIp.Name = "cmbLocalIp";
this.cmbLocalIp.Size = new System.Drawing.Size(233, 28);
this.cmbLocalIp.TabIndex = 288;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label5.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label5.Location = new System.Drawing.Point(81, 38);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(106, 20);
this.label5.TabIndex = 289;
this.label5.Text = "请选择本地IP:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.cmbLocalIp);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.txtSearchIp);
this.groupBox1.Controls.Add(this.btnSearch);
this.groupBox1.Location = new System.Drawing.Point(22, 12);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(614, 138);
this.groupBox1.TabIndex = 290;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "搜索RFID";
this.groupBox1.Visible = false;
//
// label6
//
this.label6.AutoSize = true;
this.label6.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label6.ImageAlign = System.Drawing.ContentAlignment.MiddleRight;
this.label6.Location = new System.Drawing.Point(108, 90);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(79, 20);
this.label6.TabIndex = 290;
this.label6.Text = "搜素结果:";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// groupBox2 // groupBox2
// //
this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
...@@ -253,9 +177,9 @@ ...@@ -253,9 +177,9 @@
this.groupBox2.Controls.Add(this.label3); this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label4); this.groupBox2.Controls.Add(this.label4);
this.groupBox2.Controls.Add(this.comType); this.groupBox2.Controls.Add(this.comType);
this.groupBox2.Location = new System.Drawing.Point(22, 12); this.groupBox2.Location = new System.Drawing.Point(22, 6);
this.groupBox2.Name = "groupBox2"; this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(489, 325); this.groupBox2.Size = new System.Drawing.Size(505, 331);
this.groupBox2.TabIndex = 291; this.groupBox2.TabIndex = 291;
this.groupBox2.TabStop = false; this.groupBox2.TabStop = false;
this.groupBox2.Text = "读取RFID"; this.groupBox2.Text = "读取RFID";
...@@ -278,14 +202,11 @@ ...@@ -278,14 +202,11 @@
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(560, 361); this.ClientSize = new System.Drawing.Size(560, 361);
this.Controls.Add(this.groupBox2); this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FrmRFIPEdit"; this.Name = "FrmRFIPEdit";
this.Text = "托盘编码"; this.Text = "托盘编码";
this.Load += new System.EventHandler(this.FrmPwd_Load); this.Load += new System.EventHandler(this.FrmPwd_Load);
((System.ComponentModel.ISupportInitialize)(this.numNum)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numNum)).EndInit();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);
this.groupBox2.PerformLayout(); this.groupBox2.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
...@@ -304,13 +225,7 @@ ...@@ -304,13 +225,7 @@
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label4;
private System.Windows.Forms.NumericUpDown numNum; private System.Windows.Forms.NumericUpDown numNum;
private System.Windows.Forms.TextBox txtSearchIp;
private System.Windows.Forms.Button btnSearch;
private System.Windows.Forms.ComboBox cmbLocalIp;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label lblResult; private System.Windows.Forms.Label lblResult;
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -38,18 +38,7 @@ namespace OnlineStore.ACPackingStore ...@@ -38,18 +38,7 @@ namespace OnlineStore.ACPackingStore
string hostN = Dns.GetHostName(); string hostN = Dns.GetHostName();
IPAddress[] addresss = Dns.GetHostAddresses(hostN); IPAddress[] addresss = Dns.GetHostAddresses(hostN);
cmbLocalIp.Items.Clear();
if (addresss != null && addresss.Length > 0)
{
foreach (IPAddress ip in addresss)
{
if (ip.AddressFamily.Equals(AddressFamily.InterNetwork))
{
cmbLocalIp.Items.Add(ip.ToString());
}
}
cmbLocalIp.SelectedIndex = 0;
}
} }
private void btnBack_Click(object sender, EventArgs e) private void btnBack_Click(object sender, EventArgs e)
...@@ -90,14 +79,5 @@ namespace OnlineStore.ACPackingStore ...@@ -90,14 +79,5 @@ namespace OnlineStore.ACPackingStore
} }
} }
} }
private void btnSearch_Click(object sender, EventArgs e)
{
string text = cmbLocalIp.Text;
// string ip = RFIDManager.SearchIP(text);
// txtSearchIp.Text = ip;
}
} }
} }
...@@ -110,7 +110,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -110,7 +110,7 @@ namespace OnlineStore.DeviceLibrary
if (!wait.IsEnd && span.TotalSeconds > 10) if (!wait.IsEnd && span.TotalSeconds > 10)
{ {
//如果是等待AGV到达,等待有料架信号也算结束 //如果是等待AGV到达,等待有料架信号也算结束
if (wait.TargetPosition.Equals((int)Asa.Actions.Arrive)&&MoveInfo.MoveStep.Equals(StoreMoveStep.BI_01_ReadyShelf)) if (wait.TargetPosition.Equals((int)Asa.Actions.Arrive) && MoveInfo.MoveStep.Equals(StoreMoveStep.BI_01_ReadyShelf))
{ {
if (IOValue(IO_Type.LineTake_Check).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.LineTake_Check).Equals(IO_VALUE.HIGH))
{ {
...@@ -206,7 +206,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -206,7 +206,7 @@ namespace OnlineStore.DeviceLibrary
|| (!MoveInfo.MoveType.Equals(StoreMoveType.None))) || (!MoveInfo.MoveType.Equals(StoreMoveType.None)))
{ {
LogUtil.error(Name + " 启动出库出错,忙碌或报警中 ,storeStatus=" + storeRunStatus + ",MoveType=" + MoveInfo.MoveType + ",isInSuddenDown=" + isInSuddenDown + ",isNoAirCheck" + isNoAirCheck); LogUtil.error(Name + " 启动出库出错,忙碌或报警中 ,storeStatus=" + storeRunStatus + ",MoveType=" + MoveInfo.MoveType + ",isInSuddenDown=" + isInSuddenDown + ",isNoAirCheck" + isNoAirCheck);
return ; return;
} }
if (!StoreManager.LoadInoutParam(param, true, this)) if (!StoreManager.LoadInoutParam(param, true, this))
...@@ -216,7 +216,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -216,7 +216,7 @@ namespace OnlineStore.DeviceLibrary
} }
param.NeedEnterShelf = false; param.NeedEnterShelf = false;
param.NeedOutShelf = false; param.NeedOutShelf = false;
LogInfo(" 启动入库【" + param.ToStr() + "】,压紧点P2【"+ param.MoveP.ComPress_P2+"】压紧前点P3【"+ param.MoveP.ComPress_P3+"】"); LogInfo(" 启动入库【" + param.ToStr() + "】,压紧点P2【" + param.MoveP.ComPress_P2 + "】压紧前点P3【" + param.MoveP.ComPress_P3 + "】");
storeRunStatus = StoreRunStatus.Busy; storeRunStatus = StoreRunStatus.Busy;
storeStatus = StoreStatus.InStoreExecute; storeStatus = StoreStatus.InStoreExecute;
MoveInfo.NewMove(StoreMoveType.InStore, param); MoveInfo.NewMove(StoreMoveType.InStore, param);
...@@ -224,7 +224,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -224,7 +224,7 @@ namespace OnlineStore.DeviceLibrary
//新的料架库位 //新的料架库位
MoveInfo.NextMoveStep(StoreMoveStep.BI_11_InoutToP1); MoveInfo.NextMoveStep(StoreMoveStep.BI_11_InoutToP1);
MoveInfo.SingleInstore = true; MoveInfo.SingleInstore = true;
InOutStoreLog("料架取料:"+MoveInfo.SLog+" 叉子后退到待机点P1, 重置盘信息"); InOutStoreLog("料架取料:" + MoveInfo.SLog + " 叉子后退到待机点P1, 重置盘信息");
ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed); ACAxisMove(Config.InOut_Axis, Config.InOutAxis_P1_Position, Config.InOutAxis_P1_Speed);
ClearLastTrayInfo(); ClearLastTrayInfo();
} }
...@@ -237,7 +237,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -237,7 +237,7 @@ namespace OnlineStore.DeviceLibrary
{ {
bool canStart = (storeRunStatus.Equals(StoreRunStatus.Runing) bool canStart = (storeRunStatus.Equals(StoreRunStatus.Runing)
&& MoveInfo.MoveType.Equals(StoreMoveType.None) ); && MoveInfo.MoveType.Equals(StoreMoveType.None));
if (!canStart || isInSuddenDown || isNoAirCheck || (alarmType.Equals(StoreAlarmType.None).Equals(false))) if (!canStart || isInSuddenDown || isNoAirCheck || (alarmType.Equals(StoreAlarmType.None).Equals(false)))
{ {
return; return;
...@@ -280,7 +280,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -280,7 +280,7 @@ namespace OnlineStore.DeviceLibrary
private void UpdateShelfId() private void UpdateShelfId()
{ {
//读取RFID //读取RFID
RFIDData data = RFIDManager.ReadRFID(Config.RFID_IP,true); RFIDData data = RFIDManager.ReadRFID(Config.RFID_IP, true);
LogUtil.info(Name + "更新当前料架号【" + data.NumStr() + "】"); LogUtil.info(Name + "更新当前料架号【" + data.NumStr() + "】");
//TODO 判断料架是否正确 //TODO 判断料架是否正确
if (data.RFType.Equals("A")) if (data.RFType.Equals("A"))
...@@ -288,16 +288,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -288,16 +288,12 @@ namespace OnlineStore.DeviceLibrary
CurrShelfID = data.NumStr(); CurrShelfID = data.NumStr();
AgvClient.SendRFID(Config.AgvNodeName, CurrShelfID); AgvClient.SendRFID(Config.AgvNodeName, CurrShelfID);
} }
//else
//{
// LogUtil.error(Name + "检测到入料口有料架,读取RFID数据错误:" + data.NumStr());
//}
} }
private void StartMoveToBag() private void StartMoveToBag()
{ {
MoveInfo.NextMoveStep(StoreMoveStep.BI_51_MoveToBag); MoveInfo.NextMoveStep(StoreMoveStep.BI_51_MoveToBag);
InOutStoreLog("入库 " + MoveInfo.SLog + ":移动到库位点,旋转轴至P2( 库位点)轴2(上下) 至P3(库位入库前点)"); InOutStoreLog("入库 " + MoveInfo.SLog + ":到库位点,旋转轴至P2( 库位点)轴2(上下) 至P3(库位入库前点)");
ACAxisMove(Config.Middle_Axis, MoveInfo.MoveParam.MoveP.Middle_P2, Config.MiddleAxis_P2_Speed); ACAxisMove(Config.Middle_Axis, MoveInfo.MoveParam.MoveP.Middle_P2, Config.MiddleAxis_P2_Speed);
ACAxisMove(Config.UpDown_Axis, MoveInfo.MoveParam.MoveP.UpDown_P3, Config.UpDownAxis_P3_Speed); ACAxisMove(Config.UpDown_Axis, MoveInfo.MoveParam.MoveP.UpDown_P3, Config.UpDownAxis_P3_Speed);
} }
...@@ -345,7 +341,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -345,7 +341,7 @@ namespace OnlineStore.DeviceLibrary
else if (MoveInfo.MoveStep.Equals(StoreMoveStep.BI_11_InoutToP1)) else if (MoveInfo.MoveStep.Equals(StoreMoveStep.BI_11_InoutToP1))
{ {
MoveInfo.NextMoveStep(StoreMoveStep.BI_12_MoveToShelf); MoveInfo.NextMoveStep(StoreMoveStep.BI_12_MoveToShelf);
InOutStoreLog("料架取料 " + MoveInfo.SLog + ":升降轴移动到P101低点,旋转轴移动到P101点,压紧轴到压紧前点"); InOutStoreLog("料架取料 " + MoveInfo.SLog + ":升降轴到P101低点,旋转轴到P101点,压紧轴到压紧前点");
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_LP101, Config.UpDownAxis_P101_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_LP101, Config.UpDownAxis_P101_Speed);
ACAxisMove(Config.Middle_Axis, moveP.Middle_P101, Config.MiddleAxis_P101_Speed); ACAxisMove(Config.Middle_Axis, moveP.Middle_P101, Config.MiddleAxis_P101_Speed);
ACAxisMove(Config.Comp_Axis, Config.CompAxis_Max_P3, Config.CompAxis_P3_Speed); ACAxisMove(Config.Comp_Axis, Config.CompAxis_Max_P3, Config.CompAxis_P3_Speed);
...@@ -367,7 +363,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -367,7 +363,7 @@ namespace OnlineStore.DeviceLibrary
if (MoveInfo.SingleInstore) if (MoveInfo.SingleInstore)
{ {
MoveInfo.NextMoveStep(StoreMoveStep.BI_16_ComDownMove); MoveInfo.NextMoveStep(StoreMoveStep.BI_16_ComDownMove);
InOutStoreLog("单盘入库,料架取料 " + MoveInfo.SLog + ":压紧轴走到压紧点P2: "+MoveInfo.MoveParam.MoveP.ComPress_P2); InOutStoreLog("单盘入库,料架取料 " + MoveInfo.SLog + ":压紧轴走到压紧点P2: " + MoveInfo.MoveParam.MoveP.ComPress_P2);
ACAxisMove(Config.Comp_Axis, MoveInfo.MoveParam.MoveP.ComPress_P2, Config.CompAxis_P2_Speed); ACAxisMove(Config.Comp_Axis, MoveInfo.MoveParam.MoveP.ComPress_P2, Config.CompAxis_P2_Speed);
} }
else else
...@@ -390,7 +386,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -390,7 +386,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.MoveParam.MoveP.ComPress_P2 = targetP; MoveInfo.MoveParam.MoveP.ComPress_P2 = targetP;
MoveInfo.MoveParam.MoveP.ComPress_P3 = targetP + Config.CompAxis_P3_P2_Value; MoveInfo.MoveParam.MoveP.ComPress_P3 = targetP + Config.CompAxis_P3_P2_Value;
InOutStoreLog("料架取料 " + MoveInfo.SLog + ":检测到Compress_Check,盘高【" + LastHeight + "】,向下压紧 [" + Config.CompAxis_Down_Position + "] 目标 [" + targetP + InOutStoreLog("料架取料 " + MoveInfo.SLog + ":检测到Compress_Check,盘高【" + LastHeight + "】,向下压紧 [" + Config.CompAxis_Down_Position + "] 目标 [" + targetP +
"]记录ComP2["+ targetP + "]ComP3["+ MoveInfo.MoveParam.MoveP.ComPress_P3 + "]"); "]记录ComP2[" + targetP + "]ComP3[" + MoveInfo.MoveParam.MoveP.ComPress_P3 + "]");
ACAxisMove(Config.Comp_Axis, targetP, Config.CompAxis_P1_Speed); ACAxisMove(Config.Comp_Axis, targetP, Config.CompAxis_P1_Speed);
...@@ -411,7 +407,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -411,7 +407,7 @@ namespace OnlineStore.DeviceLibrary
else else
{ {
MoveInfo.NextMoveStep(StoreMoveStep.BI_21_ToScanPosition); MoveInfo.NextMoveStep(StoreMoveStep.BI_21_ToScanPosition);
InOutStoreLog("扫码 " + MoveInfo.SLog + ":升降轴移动到P2,旋转轴移动到P1"); InOutStoreLog("扫码 " + MoveInfo.SLog + ":升降轴到P2,旋转轴到P1");
ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P2, Config.UpDownAxis_P2_Speed); ACAxisMove(Config.UpDown_Axis, moveP.UpDown_P2, Config.UpDownAxis_P2_Speed);
ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed); ACAxisMove(Config.Middle_Axis, moveP.Middle_P1, Config.MiddleAxis_P1_Speed);
} }
...@@ -869,7 +865,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -869,7 +865,7 @@ namespace OnlineStore.DeviceLibrary
} }
else else
{ {
string msg = StoreManager.UpdateTrayLoc(Name, MoveInfo.MoveParam.WareCode, CurrShelfID+"@"+ posLoc.ToString()); string msg = StoreManager.UpdateTrayLoc(Name, MoveInfo.MoveParam.WareCode, CurrShelfID + "@" + posLoc.ToString());
if (String.IsNullOrEmpty(msg).Equals(false)) if (String.IsNullOrEmpty(msg).Equals(false))
{ {
LogUtil.error(Name + "【" + MoveInfo.MoveParam.WareCode + "】【" + CurrShelfID + "】【" + posLoc + "】UpdateTrayLoc 结果:" + msg); LogUtil.error(Name + "【" + MoveInfo.MoveParam.WareCode + "】【" + CurrShelfID + "】【" + posLoc + "】UpdateTrayLoc 结果:" + msg);
......
using CodeLibrary;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
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
{
public class CodeManager
{
public static List<string> codeTypeList = new List<string>();
public static List<string> balserNameList = new List<string>();
public static List<string> hikNameList = new List<string>();
private static char spiltChar = '#';
/// <summary>
/// 初始化摄像机名称和二维码类型
/// </summary>
public static void LoadConfig()
{
string codeStr = ConfigAppSettings.GetValue(Setting_Init.CodeType);
codeTypeList = new List<string>();
HDLogUtil.LogName = "RollingLogFileAppender";
try
{
string[] codeArray = codeStr.Split(spiltChar);
foreach (string str in codeArray)
{
if (str.Trim().Equals(""))
{
continue;
}
LogUtil.info("加载到配置二维码类型:" + str.Trim());
codeTypeList.Add(str.Trim());
}
LoadCamera(false);
CodeLibrary.HDCodeLearnHelper.LoadConfig("", codeStr);
}
catch (Exception ex)
{
LogUtil.error("解析摄像机配置出错:" + ex.StackTrace);
}
}
private static void LoadCamera(bool isReLoad)
{
if (isReLoad)
{
try
{
CodeLibrary.HIKCManager.Load();
}
catch (Exception ex)
{
LogUtil.error("加载HIK相机出错:" + ex.ToString());
}
try
{
CodeLibrary.BaslerCManager.Load();
}
catch (Exception ex)
{
LogUtil.error("加载Basler相机出错:" + ex.ToString());
}
}
string[] names = CodeLibrary.HIKCManager.CameraName;
if (names != null)
{
hikNameList.AddRange(names);
foreach (string name in hikNameList)
{
LogUtil.info("加载到HIK相机:" + name);
}
}
names = CodeLibrary.BaslerCManager.CameraName;
if (names != null)
{
balserNameList.AddRange(names);
foreach (string name in balserNameList)
{
LogUtil.info("加载到Balser相机:" + name);
}
}
}
public static void CloseCamera(string name)
{
try
{
//BaslerCamera.Instance.Close();
//HIKCamera.Instance.Close();
if (HIKCManager.CameraName.Contains(name))
{
HIKCManager.Close(name);
}
else
{
BaslerCManager.Close(name);
}
}catch(Exception ex)
{
LogUtil.error("CloseCamera[" + name + "]出错:" + ex.ToString());
}
}
public static void CloseAllCamera()
{
HIKCManager.CloseAll();
BaslerCManager.CloseAll();
}
public static Bitmap GetCamerImage(string cameraName)
{
Bitmap bitm = null;
try
{
if (balserNameList.Contains(cameraName))
{
bool result = true;
if (!BaslerCManager.IsOpen(cameraName))
{
result = BaslerCManager.Open(cameraName);
}
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if (result)
{
bitm = BaslerCManager.GrabOne(cameraName);
}
else
{
LogUtil.error("相机【" + cameraName + "】打开失败:" + BaslerCamera.Instance.ErrInfo);
}
}
else if (hikNameList.Contains(cameraName))
{
bool result = true;
if (!HIKCManager.IsOpen(cameraName))
{
result = HIKCManager.Open(cameraName);
}
// LogUtil.info("打开相机:" + cameraName + "(" + result + ")");
if (result)
{
bitm = HIKCManager.GrabOne(cameraName);
}
else
{
LogUtil.error("相机【" + cameraName + "】打开失败:" + HIKCamera.Instance.ErrInfo);
}
}
else
{
LogUtil.info("未找到相机【" + cameraName + "】无法获取图片");
//若未加载到相机,需要重新加载相机
if (balserNameList.Count <= 0 && hikNameList.Count <= 0)
{
LogUtil.error("获取图片时发现未加载到相机,重新加载相机");
LoadCamera(true);
}
}
}
catch (Exception ex)
{
LogUtil.error("从相机【" + cameraName + "】获取图片出错:" + ex.ToString());
}
return bitm;
}
[HandleProcessCorruptedStateExceptions]
public static List<string> CameraScan(List<string> cameraNameList)
{
List<string> codeList = new List<string>();
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))
{
if (bitmap == null)
{
LogUtil.error(" 摄像机【" + cameraName + "】获取图片失败,关闭相机");
CloseCamera(cameraName);
return;
}
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)
{
Task<List<CodeInfo>> typeDeCode = Task.Factory.StartNew(delegate ()
{
return DeCode(ho_Image, codeType);
});
taskList.Add(typeDeCode);
}
}
});
}
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;
}
}
}
}
catch (AccessViolationException e)
{
LogUtil.error("扫码出现AccessViolationException异常:" + e.ToString());
GC.Collect();
}
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)
{
string appPath = Application.StartupPath;
string path = appPath + ConfigAppSettings.GetValue(Setting_Init.CodeParamPath);
string filePath = path + codePath + ".dcm";
if (File.Exists(filePath))
{
return filePath;
}
else
{
return "";
}
}
/// <summary>
/// 处理接收后的二维码
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
private static string ReplaceCode(string message)
{
message = message.Trim();
message = message.Replace("\r", "");
message = message.Replace("\n", "");
char a = (char)02;
message = message.Replace(a.ToString(), "");
message = message.Trim();
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
byte[] bytes = asciiEncoding.GetBytes(message);
List<byte> newBytes = new List<byte>();
foreach (byte by in bytes)
{
if (!by.Equals(24))
{
newBytes.Add(by);
}
}
message = asciiEncoding.GetString(newBytes.ToArray());
return message;
}
public static string ProcessCode(List<string> codeList)
{
string code = "";
foreach (string cc in codeList)
{
if (string.IsNullOrEmpty(cc))
{
continue;
}
code += cc + "##";
}
return ReplaceCode(code);
}
}
}
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!