Commit bf10fc86 LN

料架读取rfid改为查找方式

1 个父辈 f1de5b9b
......@@ -50,7 +50,7 @@
<add key ="OpenRFIDWrite" value ="1"/>
<add key="DefaultPWD" value ="123456"/>
<!--当前调试的设备ID,分号分割-->
<add key ="DebugDeviceId" value ="0"/>
<add key ="DebugDeviceId" value ="301"/>
<add key ="Server_Log_Open" value ="0"/>
<add key ="CodeCount" value ="3"/>
<add key ="DefaultTrayNum" value ="0"/>
......
......@@ -221,6 +221,7 @@
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "FrmRFIPEdit";
this.Text = "托盘编码";
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.FrmRFIPEdit_FormClosed);
this.Load += new System.EventHandler(this.FrmPwd_Load);
((System.ComponentModel.ISupportInitialize)(this.numNum)).EndInit();
this.groupBox2.ResumeLayout(false);
......
......@@ -45,6 +45,14 @@ namespace OnlineStore.AssemblyLine
comboxType.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();
}
......@@ -108,5 +116,17 @@ namespace OnlineStore.AssemblyLine
lblResult.Text = ("[" + 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
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)
{
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());
MessageBox.Show(exceptionobj.ToString(), type);
LOGGER.Error("【" + type + "】" + exceptionobj);
MessageBox.Show(exceptionobj, type);
}
}
}
......@@ -97,8 +97,8 @@
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="assemblyLine\EquipBase.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAuto.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="model\LineAlarm.cs">
<SubType>Code</SubType>
</Compile>
......
......@@ -30,8 +30,8 @@ namespace OnlineStore.DeviceLibrary
Init();
UseAxis = true;
Config.SetAxisParam();
UpdownAxis = new AxisBean( config.UpDown_Axis,Name);
BatchAxis = new AxisBean( config.Batch_Axis,Name);
UpdownAxis = new AxisBean(config.UpDown_Axis, Name);
BatchAxis = new AxisBean(config.Batch_Axis, Name);
MoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-Move]");
SecondMoveInfo = new LineMoveInfo(DeviceID, "[" + Name.Trim() + "-SMove]");
}
......@@ -266,7 +266,7 @@ namespace OnlineStore.DeviceLibrary
LogInfo("重置完成!");
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);
}
MoveEndS();
......@@ -356,9 +356,9 @@ namespace OnlineStore.DeviceLibrary
}
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();
}
......@@ -372,7 +372,8 @@ namespace OnlineStore.DeviceLibrary
if (Config.IsCanOut.Equals(0))
{
StartCheckFixture();
}else if (LineManager.Line.runStatus <= LineRunStatus.Wait)
}
else if (LineManager.Line.runStatus <= LineRunStatus.Wait)
{
StartCheckFixture();
}
......@@ -505,16 +506,17 @@ namespace OnlineStore.DeviceLibrary
/// <summary>
/// 升降盘是否在后退端
/// </summary>
public bool IsTrayLCylinderAfter( )
public bool IsTrayLCylinderAfter()
{
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_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 false;
}
return false;
}
/// <summary>
......@@ -579,9 +581,10 @@ namespace OnlineStore.DeviceLibrary
BatchAxis.SuddenStop();
BatchAxisStopCheck();
}
}catch(Exception ex)
}
catch (Exception ex)
{
LogUtil.error("CheckTimer_Elapsed出错:",ex);
LogUtil.error("CheckTimer_Elapsed出错:", ex);
}
finally
{
......@@ -682,7 +685,7 @@ namespace OnlineStore.DeviceLibrary
//停止转动 ,阻挡上升
IOMove(IO_Type.SL_OutLine_Run, 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
{
Thread.Sleep(2000);
......@@ -760,7 +763,7 @@ namespace OnlineStore.DeviceLibrary
}
catch (Exception ex)
{
LogUtil.error("AGV料架进入 出错:" ,ex);
LogUtil.error("AGV料架进入 出错:", ex);
}
finally
{
......
......@@ -36,9 +36,9 @@ namespace OnlineStore.DeviceLibrary
public static void Open()
{
RFIDReader.Open(ShelfIpList.ToArray());
// RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray());
RFIDAutoReader.Open(null, TrayIpList.ToArray());
RFIDReader.Open(ShelfIpList.ToArray());
}
/// <summary>
......@@ -94,7 +94,7 @@ namespace OnlineStore.DeviceLibrary
{
if (String.IsNullOrEmpty(ip).Equals(false) && ShelfIpList.Contains(ip))
{
byte[] bdata = RFIDReader.Read(ip, true);
byte[] bdata = RFIDReader.Read(ip, isClear);
if (bdata == null)
{
......
......@@ -12,8 +12,6 @@ namespace Asa.RFID
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private System.Threading.Thread tScan;
private bool loop;
private string IP = "";
private byte addr;
private int portIndex;
......@@ -22,18 +20,8 @@ namespace Asa.RFID
internal byte[] _buff; //8字节缓存
private byte[] _uid; //卡片ID
public bool IsExist = false;
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 int ErrCode = 0;
public RFID(string ip)
{
......@@ -44,7 +32,6 @@ namespace Asa.RFID
{
try
{
loop = false;
IsConnect = false;
int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex);
LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode);
......@@ -57,6 +44,7 @@ namespace Asa.RFID
return -1;
}
public int Open()
{
if (IsConnect)
......@@ -92,29 +80,6 @@ namespace Asa.RFID
OpenCloseRF(true);
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)
{
if (rtn)
......@@ -123,6 +88,7 @@ namespace Asa.RFID
ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex);
}
/// <summary>
/// 查找电子标签,扫描模式不能使用
/// </summary>
......@@ -181,7 +147,6 @@ namespace Asa.RFID
}
return null;
}
private void ReadRFID()
{
//0 不带AFI
......@@ -227,13 +192,13 @@ namespace Asa.RFID
return s;
}
}
public class RFIDReader
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private static Dictionary<string, RFID> rfidMap = new Dictionary<string, RFID>();
public static void Open(params string[] ipArr)
{
foreach (var ip in ipArr)
......@@ -250,7 +215,6 @@ namespace Asa.RFID
}
}
}
public static bool FindRFID(string ip)
{
if (rfidMap.ContainsKey(ip))
......
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -12,6 +13,8 @@ namespace Asa.RFID
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private System.Threading.Thread tScan;
private bool loop;
private string IP = "";
private byte addr;
private int portIndex;
......@@ -20,9 +23,19 @@ namespace Asa.RFID
internal byte[] _buff; //8字节缓存
private byte[] _uid; //卡片ID
public bool IsExist = false;
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)
{
this.IP = ip;
......@@ -32,6 +45,7 @@ namespace Asa.RFID
{
try
{
loop = false;
IsConnect = false;
int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex);
LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode);
......@@ -44,7 +58,6 @@ namespace Asa.RFID
return -1;
}
public int Open()
{
if (IsConnect)
......@@ -80,6 +93,31 @@ namespace Asa.RFID
OpenCloseRF(true);
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)
{
if (rtn)
......@@ -88,13 +126,14 @@ namespace Asa.RFID
ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex);
}
/// <summary>
/// 查找电子标签,扫描模式不能使用
/// </summary>
/// <returns></returns>
public bool FindRFID()
{
try
{
//0 不带AFI
//1 带AFI
//2 不带AFI,继续查询
......@@ -111,7 +150,10 @@ namespace Asa.RFID
//输出,标签数量
byte cardNumber = 0;
if (_uid == null)
{
_uid = new byte[8];
}
ErrCode = ReaderA.StaticClassReaderA.Inventory(ref addr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);
if (ErrCode == 0)
{
......@@ -126,8 +168,12 @@ namespace Asa.RFID
for (int i = 0; i < _uid.Length; i++)
_uid[i] = 0;
IsExist = false;
return false;
}
}catch(Exception ex)
{
LOGGER.Error(IP + "FindRFID Error:" + ex.ToString());
}
return false;
}
public byte[] Read(bool isNeedFind = false)
......@@ -149,6 +195,8 @@ namespace Asa.RFID
}
private void ReadRFID()
{
try
{
//0 不带AFI
//1 带AFI
//2 不带AFI,继续查询
......@@ -167,7 +215,10 @@ namespace Asa.RFID
//错误代码
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)
{
......@@ -181,6 +232,11 @@ namespace Asa.RFID
LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode);
}
}
catch (Exception ex)
{
LOGGER.Error(IP + "ReadRFID Error:" + ex.ToString());
}
}
private string byteToStr(byte[] data, int len)
{
......@@ -197,38 +253,75 @@ namespace Asa.RFID
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
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)
{
try
{
foreach (var ip in ipArr)
{
if (rfidMap.ContainsKey(ip))
{
rfidMap[ip].Open();
rfidMap[ip].FindMode();
}
else
{
RFID rfid = new RFID(ip);
rfid.Received += Rfid_Received;
rfid.Open();
rfid.FindMode();
rfidMap.Add(ip, rfid);
}
}
}
public static bool FindRFID(string ip)
catch (Exception ex)
{
if (rfidMap.ContainsKey(ip))
LOGGER.Error ("RFIDReader Open Error:" + ex.ToString());
}
}
private static void Rfid_Received(string ip, byte[] buff)
{
return rfidMap[ip].FindRFID();
if (buff == null)
{
return;
}
return false;
string dataStr = byteToStr(buff, buff.Length);
LOGGER.Info(ip + " Rfid_Received 保存数据:" + dataStr);
if (LastRfidData.ContainsKey(ip))
{
LastRfidData[ip] = buff;
}
else
{
LastRfidData.Add(ip, buff);
}
}
//public static bool FindRFID(string ip)
//{
// if (rfidMap.ContainsKey(ip))
// {
// return rfidMap[ip].FindRFID();
// }
// return false;
//}
public static byte[] Read(string ip, bool isNeedFind)
public static byte[] Read(string ip, bool isClear = false)
{
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;
}
......@@ -240,5 +333,14 @@ namespace Asa.RFID
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!