Commit bf10fc86 LN

料架读取rfid改为查找方式

1 个父辈 f1de5b9b
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
<add key ="OpenRFIDWrite" value ="1"/> <add key ="OpenRFIDWrite" value ="1"/>
<add key="DefaultPWD" value ="123456"/> <add key="DefaultPWD" value ="123456"/>
<!--当前调试的设备ID,分号分割--> <!--当前调试的设备ID,分号分割-->
<add key ="DebugDeviceId" value ="0"/> <add key ="DebugDeviceId" value ="301"/>
<add key ="Server_Log_Open" value ="0"/> <add key ="Server_Log_Open" value ="0"/>
<add key ="CodeCount" value ="3"/> <add key ="CodeCount" value ="3"/>
<add key ="DefaultTrayNum" value ="0"/> <add key ="DefaultTrayNum" value ="0"/>
......
...@@ -221,6 +221,7 @@ ...@@ -221,6 +221,7 @@
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.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FrmRFIPEdit_FormClosed);
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.groupBox2.ResumeLayout(false); this.groupBox2.ResumeLayout(false);
......
...@@ -45,6 +45,14 @@ namespace OnlineStore.AssemblyLine ...@@ -45,6 +45,14 @@ namespace OnlineStore.AssemblyLine
comboxType.SelectedIndex = 0; comboxType.SelectedIndex = 0;
comType.SelectedIndex = 0; comType.SelectedIndex = 0;
if (LineManager.Line.runStatus <= LineRunStatus.Wait)
{
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Open");
RFIDManager.Open();
});
}
string hostN = Dns.GetHostName(); string hostN = Dns.GetHostName();
} }
...@@ -108,5 +116,17 @@ namespace OnlineStore.AssemblyLine ...@@ -108,5 +116,17 @@ namespace OnlineStore.AssemblyLine
lblResult.Text = ("[" + ip + "]读取到数据:" + resul); lblResult.Text = ("[" + ip + "]读取到数据:" + resul);
LogUtil.info("点击RFID[" + ip + "]读取数据并清理测试,结果:" + resul); LogUtil.info("点击RFID[" + ip + "]读取数据并清理测试,结果:" + resul);
} }
private void FrmRFIPEdit_FormClosed(object sender, FormClosedEventArgs e)
{
if (LineManager.Line.runStatus <= LineRunStatus.Wait)
{
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Close");
RFIDManager.Close();
});
}
}
} }
} }
...@@ -112,19 +112,19 @@ namespace OnlineStore.AssemblyLine ...@@ -112,19 +112,19 @@ namespace OnlineStore.AssemblyLine
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
LogUnhandledException("CurrentDomain_UnhandledException", e); LogUnhandledException("CurrentDomain_UnhandledException", e.ToString() +""+e.ExceptionObject.ToString()+" ");
} }
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{ {
LogUnhandledException("Application_ThreadException", e); LogUnhandledException("Application_ThreadException", e.ToString() + "" + e.Exception.ToString() + " ");
} }
static void LogUnhandledException(string type, object exceptionobj) static void LogUnhandledException(string type, string exceptionobj)
{ {
//这里可以进一步地写日志 //这里可以进一步地写日志
LOGGER.Error("【" + type + "】" + exceptionobj.ToString()); LOGGER.Error("【" + type + "】" + exceptionobj);
MessageBox.Show(exceptionobj.ToString(), type); MessageBox.Show(exceptionobj, type);
} }
} }
} }
...@@ -97,8 +97,8 @@ ...@@ -97,8 +97,8 @@
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" /> <Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="assemblyLine\EquipBase.cs" /> <Compile Include="assemblyLine\EquipBase.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAuto.cs" /> <Compile Include="deviceLibrary\RFID\RFIDAuto.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" /> <Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="model\LineAlarm.cs"> <Compile Include="model\LineAlarm.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
......
...@@ -30,8 +30,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -30,8 +30,8 @@ namespace OnlineStore.DeviceLibrary
Init(); Init();
UseAxis = true; UseAxis = true;
Config.SetAxisParam(); Config.SetAxisParam();
UpdownAxis = new AxisBean( config.UpDown_Axis,Name); UpdownAxis = new AxisBean(config.UpDown_Axis, Name);
BatchAxis = new AxisBean( config.Batch_Axis,Name); BatchAxis = new AxisBean(config.Batch_Axis, Name);
MoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-Move]"); MoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-Move]");
SecondMoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-SMove]"); SecondMoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-SMove]");
} }
...@@ -41,7 +41,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -41,7 +41,7 @@ namespace OnlineStore.DeviceLibrary
/// 开始运行 /// 开始运行
/// </summary> /// </summary>
public override bool StartRun(bool isDebug = false) public override bool StartRun(bool isDebug = false)
{ {
if (CanStartRun().Equals(false)) if (CanStartRun().Equals(false))
{ {
return false; return false;
...@@ -80,7 +80,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -80,7 +80,7 @@ namespace OnlineStore.DeviceLibrary
} }
return false; return false;
} }
public override bool Reset() public override bool Reset()
{ {
StopMove(); StopMove();
...@@ -187,16 +187,16 @@ namespace OnlineStore.DeviceLibrary ...@@ -187,16 +187,16 @@ namespace OnlineStore.DeviceLibrary
CylinderMove(MoveInfo, IO_Type.SW_TopCylinder_Up, IO_Type.SW_TopCylinder_Down); CylinderMove(MoveInfo, IO_Type.SW_TopCylinder_Up, IO_Type.SW_TopCylinder_Down);
} }
break; break;
case LineMoveStep.FR_03_CylinderUp: case LineMoveStep.FR_03_CylinderUp:
MoveInfo.NextMoveStep(LineMoveStep.FR_04_UpdownAxisHome); MoveInfo.NextMoveStep(LineMoveStep.FR_04_UpdownAxisHome);
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 升降伺服回原点"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 升降伺服回原点");
UpdownAxis.HomeMove(MoveInfo); UpdownAxis.HomeMove(MoveInfo);
break; break;
case LineMoveStep.FR_04_UpdownAxisHome: case LineMoveStep.FR_04_UpdownAxisHome:
MoveInfo.NextMoveStep(LineMoveStep.FR_05_UpdownAxis_P1); MoveInfo.NextMoveStep(LineMoveStep.FR_05_UpdownAxis_P1);
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 升降伺服到P1"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 升降伺服到P1");
UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed); UpdownAxis.AbsMove(MoveInfo, Config.UpDownAxisP1, Config.UpdownAxis_P1Speed);
break; break;
case LineMoveStep.FR_05_UpdownAxis_P1: case LineMoveStep.FR_05_UpdownAxis_P1:
if (MoveCylineCanTakeOrGive()) if (MoveCylineCanTakeOrGive())
...@@ -226,7 +226,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -226,7 +226,7 @@ namespace OnlineStore.DeviceLibrary
MoveInfo.TimeOutSeconds = 120; MoveInfo.TimeOutSeconds = 120;
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":提升伺服回原点"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":提升伺服回原点");
BatchAxis.HomeMove(MoveInfo); BatchAxis.HomeMove(MoveInfo);
break; break;
case LineMoveStep.FR_11_BatchAxisHome: case LineMoveStep.FR_11_BatchAxisHome:
MoveInfo.NextMoveStep(LineMoveStep.FR_12_BatchAxisToP2); MoveInfo.NextMoveStep(LineMoveStep.FR_12_BatchAxisToP2);
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":提升伺服下降到P2点,"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":提升伺服下降到P2点,");
...@@ -234,7 +234,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -234,7 +234,7 @@ namespace OnlineStore.DeviceLibrary
BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed); BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP2, Config.BatchAxis_P2Speed);
break; break;
case LineMoveStep.FR_12_BatchAxisToP2: case LineMoveStep.FR_12_BatchAxisToP2:
MoveInfo.NextMoveStep(LineMoveStep.FR_13_LocationDown); MoveInfo.NextMoveStep(LineMoveStep.FR_13_LocationDown);
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 放开定位气缸,升降伺服到P1"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ": 放开定位气缸,升降伺服到P1");
TrayLCylinderAfter(MoveInfo); TrayLCylinderAfter(MoveInfo);
Thread.Sleep(50); Thread.Sleep(50);
...@@ -244,8 +244,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -244,8 +244,8 @@ namespace OnlineStore.DeviceLibrary
case LineMoveStep.FR_13_LocationDown: case LineMoveStep.FR_13_LocationDown:
MoveInfo.NextMoveStep(LineMoveStep.FR_14_TopDown); MoveInfo.NextMoveStep(LineMoveStep.FR_14_TopDown);
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":SL1定位气缸下降SOL,出口顶升气缸下降,夹紧气缸放松"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":SL1定位气缸下降SOL,出口顶升气缸下降,夹紧气缸放松");
CylinderMove(MoveInfo, IO_Type.SL_LocationCylinder_Up, IO_Type.SL_LocationCylinder_Down); CylinderMove(MoveInfo, IO_Type.SL_LocationCylinder_Up, IO_Type.SL_LocationCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SL_OutTopCylinder_Up, IO_Type.SL_OutTopCylinder_Down); CylinderMove(MoveInfo, IO_Type.SL_OutTopCylinder_Up, IO_Type.SL_OutTopCylinder_Down);
CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Tighten, IO_Type.SL_MoveCylinder_Slack); CylinderMove(MoveInfo, IO_Type.SL_MoveCylinder_Tighten, IO_Type.SL_MoveCylinder_Slack);
break; break;
case LineMoveStep.FR_14_TopDown: case LineMoveStep.FR_14_TopDown:
...@@ -254,19 +254,19 @@ namespace OnlineStore.DeviceLibrary ...@@ -254,19 +254,19 @@ namespace OnlineStore.DeviceLibrary
//判断定位工位是否有料架 //判断定位工位是否有料架
if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.SL_Location_Check).Equals(IO_VALUE.HIGH))
{ {
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":定位工位有料架,提升伺服不需要到P1"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":定位工位有料架,提升伺服不需要到P1");
} }
else else
{ {
LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":定位工位无料架,提升伺服上升到P1点"); LogInfo(MoveInfo.MoveType + ":" + MoveInfo.SLog + ":定位工位无料架,提升伺服上升到P1点");
BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP1, Config.BatchAxis_P1Speed); BatchAxis.AbsMove(MoveInfo, Config.BatchAxisP1, Config.BatchAxis_P1Speed);
} }
break; break;
case LineMoveStep.FR_15_BatchAxisToP1: case LineMoveStep.FR_15_BatchAxisToP1:
LogInfo("重置完成!"); LogInfo("重置完成!");
if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.SL_Out_Check).Equals(IO_VALUE.HIGH))
{ {
LogInfo("重置完成,出口检测到有料架,调用 "+Config.AgvOutName+" AgvClient.NeedLeave"); LogInfo("重置完成,出口检测到有料架,调用 " + Config.AgvOutName + " AgvClient.NeedLeave");
AgvClient.NeedLeave(Config.AgvOutName); AgvClient.NeedLeave(Config.AgvOutName);
} }
MoveEndS(); MoveEndS();
...@@ -314,7 +314,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -314,7 +314,7 @@ namespace OnlineStore.DeviceLibrary
mainTimer.Enabled = false; mainTimer.Enabled = false;
} }
StopMove(); StopMove();
} }
...@@ -329,7 +329,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -329,7 +329,7 @@ namespace OnlineStore.DeviceLibrary
} }
return; return;
} }
if (IOValue(IO_Type.SL_Reset_BTN).Equals(IO_VALUE.HIGH)) if (IOValue(IO_Type.SL_Reset_BTN).Equals(IO_VALUE.HIGH))
{ {
if (NoAlarm()) if (NoAlarm())
...@@ -356,9 +356,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -356,9 +356,9 @@ namespace OnlineStore.DeviceLibrary
} }
BusyMoveProcess(); BusyMoveProcess();
//判断流水线打开了才可以运行 //判断流水线打开了才可以运行
if (MoveInfo.MoveType.Equals(LineMoveType.None)&&NoErrorAlarm()) if (MoveInfo.MoveType.Equals(LineMoveType.None) && NoErrorAlarm())
{ {
if ( Config.IsCanOut.Equals(0)) if (Config.IsCanOut.Equals(0))
{ {
StartInStoreP(); StartInStoreP();
} }
...@@ -372,7 +372,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -372,7 +372,8 @@ namespace OnlineStore.DeviceLibrary
if (Config.IsCanOut.Equals(0)) if (Config.IsCanOut.Equals(0))
{ {
StartCheckFixture(); StartCheckFixture();
}else if (LineManager.Line.runStatus <= LineRunStatus.Wait) }
else if (LineManager.Line.runStatus <= LineRunStatus.Wait)
{ {
StartCheckFixture(); StartCheckFixture();
} }
...@@ -417,7 +418,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -417,7 +418,7 @@ namespace OnlineStore.DeviceLibrary
CylinderMove(null, IO_Type.FL_TopCylinder_Up, IO_Type.FL_TopCylinder_Down); CylinderMove(null, IO_Type.FL_TopCylinder_Up, IO_Type.FL_TopCylinder_Down);
} }
else else
{ {
LogInfo(" 上升横移机构 "); LogInfo(" 上升横移机构 ");
} }
CylinderMove(null, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up); CylinderMove(null, IO_Type.SL_MoveCylinder_Down, IO_Type.SL_MoveCylinder_Up);
...@@ -505,16 +506,17 @@ namespace OnlineStore.DeviceLibrary ...@@ -505,16 +506,17 @@ namespace OnlineStore.DeviceLibrary
/// <summary> /// <summary>
/// 升降盘是否在后退端 /// 升降盘是否在后退端
/// </summary> /// </summary>
public bool IsTrayLCylinderAfter( ) public bool IsTrayLCylinderAfter()
{ {
if (IOValue(IO_Type.SL_TrayLocation1_After).Equals(IO_VALUE.HIGH) && if (IOValue(IO_Type.SL_TrayLocation1_After).Equals(IO_VALUE.HIGH) &&
IOValue(IO_Type.SL_TrayLocation1_Before).Equals(IO_VALUE.LOW) && IOValue(IO_Type.SL_TrayLocation1_Before).Equals(IO_VALUE.LOW) &&
IOValue(IO_Type.SL_TrayLocation2_After).Equals(IO_VALUE.HIGH) && IOValue(IO_Type.SL_TrayLocation2_After).Equals(IO_VALUE.HIGH) &&
IOValue(IO_Type.SL_TrayLocation2_Before).Equals(IO_VALUE.LOW) ) IOValue(IO_Type.SL_TrayLocation2_Before).Equals(IO_VALUE.LOW))
{ {
return true; return true;
}return false; }
return false;
} }
/// <summary> /// <summary>
...@@ -555,14 +557,14 @@ namespace OnlineStore.DeviceLibrary ...@@ -555,14 +557,14 @@ namespace OnlineStore.DeviceLibrary
} }
private bool BatchAxisStopCheck() private bool BatchAxisStopCheck()
{ {
if (!(axisCheckTimer == null)) if (!(axisCheckTimer == null))
{ {
axisCheckTimer.Stop(); axisCheckTimer.Stop();
} }
return true; return true;
} }
private bool IsInProcess = false; private bool IsInProcess = false;
private DateTime lastOkTime = DateTime.Now; private DateTime lastOkTime = DateTime.Now;
private void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) private void CheckTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
...@@ -570,7 +572,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -570,7 +572,7 @@ namespace OnlineStore.DeviceLibrary
if (IsInProcess && pan.TotalMilliseconds < 300) { return; } if (IsInProcess && pan.TotalMilliseconds < 300) { return; }
try try
{ {
IsInProcess = true; IsInProcess = true;
lastOkTime = DateTime.Now; lastOkTime = DateTime.Now;
if (IOValue(TargetIoType).Equals(TargetIoValue)) if (IOValue(TargetIoType).Equals(TargetIoValue))
...@@ -579,9 +581,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -579,9 +581,10 @@ namespace OnlineStore.DeviceLibrary
BatchAxis.SuddenStop(); BatchAxis.SuddenStop();
BatchAxisStopCheck(); BatchAxisStopCheck();
} }
}catch(Exception ex) }
catch (Exception ex)
{ {
LogUtil.error("CheckTimer_Elapsed出错:",ex); LogUtil.error("CheckTimer_Elapsed出错:", ex);
} }
finally finally
{ {
...@@ -593,7 +596,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -593,7 +596,7 @@ namespace OnlineStore.DeviceLibrary
#endregion #endregion
#region AGV #region AGV
internal bool AgvCanEnter(string nodeId, RFIDData data) internal bool AgvCanEnter(string nodeId, RFIDData data)
{ {
string logN = Name + "收到 AgvCanEnter 事件 [" + nodeId + "] [" + data.ToData() + "] "; string logN = Name + "收到 AgvCanEnter 事件 [" + nodeId + "] [" + data.ToData() + "] ";
bool usable = false; bool usable = false;
...@@ -604,7 +607,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -604,7 +607,7 @@ namespace OnlineStore.DeviceLibrary
usable = false; usable = false;
} }
else else
{ {
//入料口无料架即可进入 //入料口无料架即可进入
usable = (runStatus >= LineRunStatus.Runing usable = (runStatus >= LineRunStatus.Runing
&& ProcessShelfEnter.Equals(false) && ProcessShelfEnter.Equals(false)
...@@ -631,7 +634,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -631,7 +634,7 @@ namespace OnlineStore.DeviceLibrary
else if (nodeId.Equals(Config.AgvOutName)) else if (nodeId.Equals(Config.AgvOutName))
{ {
} }
LogUtil.info(logN + ":" + "暂无处理"); LogUtil.info(logN + ":" + "暂无处理");
} }
internal void AgvReady(string nodeId, RFIDData data) internal void AgvReady(string nodeId, RFIDData data)
...@@ -654,13 +657,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -654,13 +657,13 @@ namespace OnlineStore.DeviceLibrary
LogUtil.info(logN + " ,未检测到出口有料架,暂不处理"); LogUtil.info(logN + " ,未检测到出口有料架,暂不处理");
} }
ShelfOutProcess(); ShelfOutProcess();
} }
} }
private bool ProcessShelfEnter = false; private bool ProcessShelfEnter = false;
private bool ProcessShelfOut = false; private bool ProcessShelfOut = false;
internal void ShelfOutProcess() internal void ShelfOutProcess()
{ {
//AGV已到达,将料架送入AGV中 //AGV已到达,将料架送入AGV中
Task.Factory.StartNew(delegate Task.Factory.StartNew(delegate
{ {
...@@ -676,13 +679,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -676,13 +679,13 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.HIGH); IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.HIGH);
if (WaitIo(IO_Type.SL_Out_Check, IO_VALUE.LOW, 6000)) if (WaitIo(IO_Type.SL_Out_Check, IO_VALUE.LOW, 6000))
{ {
//再转动2000 //再转动2000
Thread.Sleep(3000); Thread.Sleep(3000);
//停止转动 ,阻挡上升 //停止转动 ,阻挡上升
IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW); IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);
IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW); IOMove(IO_Type.SL_Out_StopDown, IO_VALUE.LOW);
AgvClient.SetStatus(Config.AgvOutName,"",ClientAction.FinishLeave); AgvClient.SetStatus(Config.AgvOutName, "", ClientAction.FinishLeave);
Task.Factory.StartNew(delegate Task.Factory.StartNew(delegate
{ {
Thread.Sleep(2000); Thread.Sleep(2000);
...@@ -690,12 +693,12 @@ namespace OnlineStore.DeviceLibrary ...@@ -690,12 +693,12 @@ namespace OnlineStore.DeviceLibrary
}); });
ProcessShelfOut = false; ProcessShelfOut = false;
LogUtil.info(Name + "料架送入AGV 结束"); LogUtil.info(Name + "料架送入AGV 结束");
} }
else else
{ {
LogUtil.info(Name + "料架送入AGV 等待SL_Out_Check=LOW超时"); LogUtil.info(Name + "料架送入AGV 等待SL_Out_Check=LOW超时");
} }
} }
} }
catch (TimeoutException te) catch (TimeoutException te)
...@@ -711,10 +714,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -711,10 +714,10 @@ namespace OnlineStore.DeviceLibrary
IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW); IOMove(IO_Type.SL_OutLine_Run, IO_VALUE.LOW);
ProcessShelfOut = false; ProcessShelfOut = false;
} }
}); });
} }
internal void ShelfEnterProcess() internal void ShelfEnterProcess()
{ {
Task.Factory.StartNew(delegate Task.Factory.StartNew(delegate
{ {
try try
...@@ -726,7 +729,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -726,7 +729,7 @@ namespace OnlineStore.DeviceLibrary
ProcessShelfEnter = true; ProcessShelfEnter = true;
////进料阻挡上升 ////进料阻挡上升
//IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW); //IOMove(IO_Type.SL_Entry_StopDown, IO_VALUE.LOW);
//转动线体 //转动线体
IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH); IOMove(IO_Type.SL_Line_Run, IO_VALUE.HIGH);
...@@ -740,8 +743,8 @@ namespace OnlineStore.DeviceLibrary ...@@ -740,8 +743,8 @@ namespace OnlineStore.DeviceLibrary
//料架可离开 //料架可离开
AgvClient.FinishEnter(Config.AgvInName); AgvClient.FinishEnter(Config.AgvInName);
Task.Factory.StartNew(delegate Task.Factory.StartNew(delegate
{ {
Thread.Sleep(2000); Thread.Sleep(2000);
AgvClient.SetStatus(Config.AgvInName, "", ClientAction.None); AgvClient.SetStatus(Config.AgvInName, "", ClientAction.None);
}); });
ProcessShelfEnter = false; ProcessShelfEnter = false;
...@@ -751,7 +754,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -751,7 +754,7 @@ namespace OnlineStore.DeviceLibrary
{ {
LogUtil.info(Name + "AGV料架进入 等待SL_Stop_Check=High超时"); LogUtil.info(Name + "AGV料架进入 等待SL_Stop_Check=High超时");
} }
} }
} }
catch (TimeoutException te) catch (TimeoutException te)
...@@ -760,15 +763,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -760,15 +763,15 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("AGV料架进入 出错:" ,ex); LogUtil.error("AGV料架进入 出错:", ex);
} }
finally finally
{ {
IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW); IOMove(IO_Type.SL_Line_Run, IO_VALUE.LOW);
ProcessShelfEnter = false; ProcessShelfEnter = false;
} }
}); });
} }
private bool UpdateShelfId() private bool UpdateShelfId()
{ {
...@@ -779,7 +782,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -779,7 +782,7 @@ namespace OnlineStore.DeviceLibrary
CurrShelfId = rfidD.NumStr(); CurrShelfId = rfidD.NumStr();
//发送料架信息给调度系统 //发送料架信息给调度系统
// AgvClient.SendRFID(Config.AgvInName, CurrShelfId); // AgvClient.SendRFID(Config.AgvInName, CurrShelfId);
LogUtil.info(Name + "读取到料架编号:" + CurrShelfId); LogUtil.info(Name + "读取到料架编号:" + CurrShelfId);
} }
catch (Exception ex) catch (Exception ex)
......
...@@ -35,10 +35,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -35,10 +35,10 @@ namespace OnlineStore.DeviceLibrary
} }
public static void Open() public static void Open()
{ {
RFIDReader.Open(ShelfIpList.ToArray());
// RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray()); // RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray());
RFIDAutoReader.Open(null, TrayIpList.ToArray()); RFIDAutoReader.Open(null, TrayIpList.ToArray());
RFIDReader.Open(ShelfIpList.ToArray());
} }
/// <summary> /// <summary>
...@@ -94,7 +94,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -94,7 +94,7 @@ namespace OnlineStore.DeviceLibrary
{ {
if (String.IsNullOrEmpty(ip).Equals(false) && ShelfIpList.Contains(ip)) if (String.IsNullOrEmpty(ip).Equals(false) && ShelfIpList.Contains(ip))
{ {
byte[] bdata = RFIDReader.Read(ip, true); byte[] bdata = RFIDReader.Read(ip, isClear);
if (bdata == null) if (bdata == null)
{ {
...@@ -207,7 +207,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -207,7 +207,7 @@ namespace OnlineStore.DeviceLibrary
RFType = (char)data[1]; RFType = (char)data[1];
} }
Num = (int)(data[2]); Num = (int)(data[2]);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -12,8 +12,6 @@ namespace Asa.RFID ...@@ -12,8 +12,6 @@ namespace Asa.RFID
{ {
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID"); public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private System.Threading.Thread tScan;
private bool loop;
private string IP = ""; private string IP = "";
private byte addr; private byte addr;
private int portIndex; private int portIndex;
...@@ -22,18 +20,8 @@ namespace Asa.RFID ...@@ -22,18 +20,8 @@ namespace Asa.RFID
internal byte[] _buff; //8字节缓存 internal byte[] _buff; //8字节缓存
private byte[] _uid; //卡片ID private byte[] _uid; //卡片ID
public bool IsExist = false; public bool IsExist = false;
public int ErrCode = 0;
/// <summary> public int ErrCode = 0;
/// 接收事件
/// </summary>
/// <param name="ip"></param>
/// <param name="buff"></param>
public delegate void Received_Event(string ip, byte[] buff);
/// <summary>
/// 接收数据
/// </summary>
public event Received_Event Received;
public RFID(string ip) public RFID(string ip)
{ {
...@@ -44,7 +32,6 @@ namespace Asa.RFID ...@@ -44,7 +32,6 @@ namespace Asa.RFID
{ {
try try
{ {
loop = false;
IsConnect = false; IsConnect = false;
int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex); int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex);
LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode); LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode);
...@@ -57,6 +44,7 @@ namespace Asa.RFID ...@@ -57,6 +44,7 @@ namespace Asa.RFID
return -1; return -1;
} }
public int Open() public int Open()
{ {
if (IsConnect) if (IsConnect)
...@@ -92,29 +80,6 @@ namespace Asa.RFID ...@@ -92,29 +80,6 @@ namespace Asa.RFID
OpenCloseRF(true); OpenCloseRF(true);
return ErrCode; return ErrCode;
} }
public void FindMode()
{
loop = true;
tScan = new System.Threading.Thread(new System.Threading.ThreadStart(Scan));
tScan.Start();
}
private void Scan()
{
while (loop)
{
bool rtn = FindRFID();
if (rtn)
{
ReadRFID();
byte[] bb = new byte[] { _buff[1], _buff[2] };
Received?.Invoke(IP, bb);
}
System.Threading.Thread.Sleep(100);
}
}
private void OpenCloseRF(bool rtn) private void OpenCloseRF(bool rtn)
{ {
if (rtn) if (rtn)
...@@ -123,6 +88,7 @@ namespace Asa.RFID ...@@ -123,6 +88,7 @@ namespace Asa.RFID
ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex); ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex);
} }
/// <summary> /// <summary>
/// 查找电子标签,扫描模式不能使用 /// 查找电子标签,扫描模式不能使用
/// </summary> /// </summary>
...@@ -181,7 +147,6 @@ namespace Asa.RFID ...@@ -181,7 +147,6 @@ namespace Asa.RFID
} }
return null; return null;
} }
private void ReadRFID() private void ReadRFID()
{ {
//0 不带AFI //0 不带AFI
...@@ -227,13 +192,13 @@ namespace Asa.RFID ...@@ -227,13 +192,13 @@ namespace Asa.RFID
return s; return s;
} }
} }
public class RFIDReader public class RFIDReader
{ {
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID"); public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private static Dictionary<string, RFID> rfidMap = new Dictionary<string, RFID>(); private static Dictionary<string, RFID> rfidMap = new Dictionary<string, RFID>();
public static void Open(params string[] ipArr) public static void Open(params string[] ipArr)
{ {
foreach (var ip in ipArr) foreach (var ip in ipArr)
...@@ -250,7 +215,6 @@ namespace Asa.RFID ...@@ -250,7 +215,6 @@ namespace Asa.RFID
} }
} }
} }
public static bool FindRFID(string ip) public static bool FindRFID(string ip)
{ {
if (rfidMap.ContainsKey(ip)) if (rfidMap.ContainsKey(ip))
......
using log4net; using log4net;
using OnlineStore.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
...@@ -12,6 +13,8 @@ namespace Asa.RFID ...@@ -12,6 +13,8 @@ namespace Asa.RFID
{ {
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID"); public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private System.Threading.Thread tScan;
private bool loop;
private string IP = ""; private string IP = "";
private byte addr; private byte addr;
private int portIndex; private int portIndex;
...@@ -20,9 +23,19 @@ namespace Asa.RFID ...@@ -20,9 +23,19 @@ namespace Asa.RFID
internal byte[] _buff; //8字节缓存 internal byte[] _buff; //8字节缓存
private byte[] _uid; //卡片ID private byte[] _uid; //卡片ID
public bool IsExist = false; public bool IsExist = false;
public int ErrCode = 0; public int ErrCode = 0;
/// <summary>
/// 接收事件
/// </summary>
/// <param name="ip"></param>
/// <param name="buff"></param>
public delegate void Received_Event(string ip, byte[] buff);
/// <summary>
/// 接收数据
/// </summary>
public event Received_Event Received;
public RFID(string ip) public RFID(string ip)
{ {
this.IP = ip; this.IP = ip;
...@@ -32,6 +45,7 @@ namespace Asa.RFID ...@@ -32,6 +45,7 @@ namespace Asa.RFID
{ {
try try
{ {
loop = false;
IsConnect = false; IsConnect = false;
int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex); int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex);
LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode); LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode);
...@@ -44,7 +58,6 @@ namespace Asa.RFID ...@@ -44,7 +58,6 @@ namespace Asa.RFID
return -1; return -1;
} }
public int Open() public int Open()
{ {
if (IsConnect) if (IsConnect)
...@@ -80,6 +93,31 @@ namespace Asa.RFID ...@@ -80,6 +93,31 @@ namespace Asa.RFID
OpenCloseRF(true); OpenCloseRF(true);
return ErrCode; return ErrCode;
} }
public void FindMode()
{
loop = true;
tScan = new System.Threading.Thread(new System.Threading.ThreadStart(Scan));
tScan.Start();
}
private void Scan()
{
while (loop)
{
bool rtn = FindRFID();
if (rtn)
{
ReadRFID();
byte[] bb = new byte[] { _buff[0], _buff[1], _buff[2] };
string dataStr = byteToStr(bb, bb.Length);
LOGGER.Info(IP + " Scan Data:" + dataStr);
Received?.Invoke(IP, bb);
}
System.Threading.Thread.Sleep(100);
}
}
private void OpenCloseRF(bool rtn) private void OpenCloseRF(bool rtn)
{ {
if (rtn) if (rtn)
...@@ -88,46 +126,54 @@ namespace Asa.RFID ...@@ -88,46 +126,54 @@ namespace Asa.RFID
ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex); ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex);
} }
/// <summary> /// <summary>
/// 查找电子标签,扫描模式不能使用 /// 查找电子标签,扫描模式不能使用
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public bool FindRFID() public bool FindRFID()
{ {
//0 不带AFI try
//1 带AFI {
//2 不带AFI,继续查询 //0 不带AFI
//3 带AFI,继续查询 //1 带AFI
//6 不带AFI,新的查询 //2 不带AFI,继续查询
//7 带AFI,新的查询 //3 带AFI,继续查询
byte state = 0; //6 不带AFI,新的查询
//7 带AFI,新的查询
//Select模式需要AFI byte state = 0;
byte AFI = 0;
//输出,1字节DSFID,8字节UID //Select模式需要AFI
byte[] DSFIDAndUID = new byte[9]; byte AFI = 0;
//输出,标签数量 //输出,1字节DSFID,8字节UID
byte cardNumber = 0; byte[] DSFIDAndUID = new byte[9];
ErrCode = ReaderA.StaticClassReaderA.Inventory(ref addr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex); //输出,标签数量
if (ErrCode == 0) byte cardNumber = 0;
{ if (_uid == null)
//查询时间 {
//fCmdRet = StaticClassReaderA.GetInventoryTime(ref n_time, portIndex); _uid = new byte[8];
Array.Copy(DSFIDAndUID, 1, _uid, 0, 8); }
IsExist = true; ErrCode = ReaderA.StaticClassReaderA.Inventory(ref addr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);
return true; if (ErrCode == 0)
} {
else //查询时间
//fCmdRet = StaticClassReaderA.GetInventoryTime(ref n_time, portIndex);
Array.Copy(DSFIDAndUID, 1, _uid, 0, 8);
IsExist = true;
return true;
}
else
{
for (int i = 0; i < _uid.Length; i++)
_uid[i] = 0;
IsExist = false;
}
}catch(Exception ex)
{ {
for (int i = 0; i < _uid.Length; i++) LOGGER.Error(IP + "FindRFID Error:" + ex.ToString());
_uid[i] = 0;
IsExist = false;
return false;
} }
return false;
} }
public byte[] Read(bool isNeedFind = false) public byte[] Read(bool isNeedFind = false)
...@@ -149,36 +195,46 @@ namespace Asa.RFID ...@@ -149,36 +195,46 @@ namespace Asa.RFID
} }
private void ReadRFID() private void ReadRFID()
{ {
//0 不带AFI try
//1 带AFI
//2 不带AFI,继续查询
//3 带AFI,继续查询
//6 不带AFI,新的查询
//7 带AFI,新的查询
byte state = 0;
//起始块号
byte blockNum = 0;
//块数量
byte blockCount = 2;
//输出,块内安全信息,长度为BlockCount个字节
byte[] blockSecStatus = new byte[blockCount];
//输出,块内数据信息,长度为块的大小(4或8字节)乘以BlockCount个字节
byte[] data = new byte[4 * blockCount];
//错误代码
byte errorCode = 0;
ErrCode = ReaderA.StaticClassReaderA.ReadMultipleBlock(ref addr, ref state, _uid, blockNum, blockCount, blockSecStatus, data, ref errorCode, portIndex);
if (ErrCode == 0)
{
Array.Copy(data, 0, _buff, 0, data.Length);
string dataStr = byteToStr(data, data.Length);
LOGGER.Info(IP + " ReadMultipleBlock: Length: " + data.Length + " Data:" + dataStr);
}
else
{ {
//0 不带AFI
//1 带AFI
//2 不带AFI,继续查询
//3 带AFI,继续查询
//6 不带AFI,新的查询
//7 带AFI,新的查询
byte state = 0;
//起始块号
byte blockNum = 0;
//块数量
byte blockCount = 2;
//输出,块内安全信息,长度为BlockCount个字节
byte[] blockSecStatus = new byte[blockCount];
//输出,块内数据信息,长度为块的大小(4或8字节)乘以BlockCount个字节
byte[] data = new byte[4 * blockCount];
LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode); //错误代码
byte errorCode = 0;
if (_buff == null)
{
_buff = new byte[8];
}
ErrCode = ReaderA.StaticClassReaderA.ReadMultipleBlock(ref addr, ref state, _uid, blockNum, blockCount, blockSecStatus, data, ref errorCode, portIndex);
if (ErrCode == 0)
{
Array.Copy(data, 0, _buff, 0, data.Length);
string dataStr = byteToStr(data, data.Length);
LOGGER.Info(IP + " ReadMultipleBlock: Length: " + data.Length + " Data:" + dataStr);
}
else
{
LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode);
}
}
catch (Exception ex)
{
LOGGER.Error(IP + "ReadRFID Error:" + ex.ToString());
} }
} }
...@@ -191,44 +247,81 @@ namespace Asa.RFID ...@@ -191,44 +247,81 @@ namespace Asa.RFID
} }
return s; return s;
} }
} }
public class RFIDReader public class RFIDReader
{ {
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID"); public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private static Dictionary<string, RFID> rfidMap = new Dictionary<string, RFID>(); private static Dictionary<string, RFID> rfidMap = new Dictionary<string, RFID>();
private static Dictionary<string, byte[]> LastRfidData = new Dictionary<string, byte[]>();
public static void Open(params string[] ipArr) public static void Open(params string[] ipArr)
{ {
foreach (var ip in ipArr) try
{ {
if (rfidMap.ContainsKey(ip)) foreach (var ip in ipArr)
{
rfidMap[ip].Open();
}
else
{ {
RFID rfid = new RFID(ip); if (rfidMap.ContainsKey(ip))
rfid.Open(); {
rfidMap.Add(ip, rfid); rfidMap[ip].Open();
rfidMap[ip].FindMode();
}
else
{
RFID rfid = new RFID(ip);
rfid.Received += Rfid_Received;
rfid.Open();
rfid.FindMode();
rfidMap.Add(ip, rfid);
}
} }
} }
catch (Exception ex)
{
LOGGER.Error ("RFIDReader Open Error:" + ex.ToString());
}
} }
public static bool FindRFID(string ip)
private static void Rfid_Received(string ip, byte[] buff)
{ {
if (rfidMap.ContainsKey(ip)) if (buff == null)
{ {
return rfidMap[ip].FindRFID(); return;
}
string dataStr = byteToStr(buff, buff.Length);
LOGGER.Info(ip + " Rfid_Received 保存数据:" + dataStr);
if (LastRfidData.ContainsKey(ip))
{
LastRfidData[ip] = buff;
}
else
{
LastRfidData.Add(ip, buff);
} }
return false;
} }
public static byte[] Read(string ip, bool isNeedFind) //public static bool FindRFID(string ip)
//{
// if (rfidMap.ContainsKey(ip))
// {
// return rfidMap[ip].FindRFID();
// }
// return false;
//}
public static byte[] Read(string ip, bool isClear = false)
{ {
if (rfidMap.ContainsKey(ip)) if (rfidMap.ContainsKey(ip))
{ {
return rfidMap[ip].Read(isNeedFind); if (LastRfidData.ContainsKey(ip))
{
byte[] data= LastRfidData[ip];
if (isClear)
{
LastRfidData.Remove(ip);
}
return data;
}
// return rfidMap[ip].Read(isNeedFind);
} }
return null; return null;
} }
...@@ -240,5 +333,14 @@ namespace Asa.RFID ...@@ -240,5 +333,14 @@ namespace Asa.RFID
rfid.Close(); rfid.Close();
} }
} }
private static string byteToStr(byte[] data, int len)
{
string s = "";
for (int i = 0; i < len; i++)
{
s += data[i].ToString("X2") + " ";
}
return s;
}
} }
} }
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!