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]");
} }
...@@ -266,7 +266,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -266,7 +266,7 @@ namespace OnlineStore.DeviceLibrary
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();
...@@ -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();
} }
...@@ -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>
...@@ -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
{ {
...@@ -682,7 +685,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -682,7 +685,7 @@ namespace OnlineStore.DeviceLibrary
//停止转动 ,阻挡上升 //停止转动 ,阻挡上升
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);
...@@ -760,7 +763,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -760,7 +763,7 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("AGV料架进入 出错:" ,ex); LogUtil.error("AGV料架进入 出错:", ex);
} }
finally finally
{ {
......
...@@ -36,9 +36,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -36,9 +36,9 @@ 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)
{ {
......
...@@ -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,13 +126,14 @@ namespace Asa.RFID ...@@ -88,13 +126,14 @@ 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()
{ {
try
{
//0 不带AFI //0 不带AFI
//1 带AFI //1 带AFI
//2 不带AFI,继续查询 //2 不带AFI,继续查询
...@@ -111,7 +150,10 @@ namespace Asa.RFID ...@@ -111,7 +150,10 @@ namespace Asa.RFID
//输出,标签数量 //输出,标签数量
byte cardNumber = 0; byte cardNumber = 0;
if (_uid == null)
{
_uid = new byte[8];
}
ErrCode = ReaderA.StaticClassReaderA.Inventory(ref addr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex); ErrCode = ReaderA.StaticClassReaderA.Inventory(ref addr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);
if (ErrCode == 0) if (ErrCode == 0)
{ {
...@@ -126,8 +168,12 @@ namespace Asa.RFID ...@@ -126,8 +168,12 @@ namespace Asa.RFID
for (int i = 0; i < _uid.Length; i++) for (int i = 0; i < _uid.Length; i++)
_uid[i] = 0; _uid[i] = 0;
IsExist = false; IsExist = false;
return false;
} }
}catch(Exception ex)
{
LOGGER.Error(IP + "FindRFID Error:" + ex.ToString());
}
return false;
} }
public byte[] Read(bool isNeedFind = false) public byte[] Read(bool isNeedFind = false)
...@@ -149,6 +195,8 @@ namespace Asa.RFID ...@@ -149,6 +195,8 @@ namespace Asa.RFID
} }
private void ReadRFID() private void ReadRFID()
{ {
try
{
//0 不带AFI //0 不带AFI
//1 带AFI //1 带AFI
//2 不带AFI,继续查询 //2 不带AFI,继续查询
...@@ -167,7 +215,10 @@ namespace Asa.RFID ...@@ -167,7 +215,10 @@ namespace Asa.RFID
//错误代码 //错误代码
byte errorCode = 0; 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); ErrCode = ReaderA.StaticClassReaderA.ReadMultipleBlock(ref addr, ref state, _uid, blockNum, blockCount, blockSecStatus, data, ref errorCode, portIndex);
if (ErrCode == 0) if (ErrCode == 0)
{ {
...@@ -181,6 +232,11 @@ namespace Asa.RFID ...@@ -181,6 +232,11 @@ namespace Asa.RFID
LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode); LOGGER.Info(IP + " ReadMultipleBlock: ErrCode: " + ErrCode);
} }
} }
catch (Exception ex)
{
LOGGER.Error(IP + "ReadRFID Error:" + ex.ToString());
}
}
private string byteToStr(byte[] data, int len) private string byteToStr(byte[] data, int len)
{ {
...@@ -197,38 +253,75 @@ namespace Asa.RFID ...@@ -197,38 +253,75 @@ namespace Asa.RFID
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)
{ {
try
{
foreach (var ip in ipArr) foreach (var ip in ipArr)
{ {
if (rfidMap.ContainsKey(ip)) if (rfidMap.ContainsKey(ip))
{ {
rfidMap[ip].Open(); rfidMap[ip].Open();
rfidMap[ip].FindMode();
} }
else else
{ {
RFID rfid = new RFID(ip); RFID rfid = new RFID(ip);
rfid.Received += Rfid_Received;
rfid.Open(); rfid.Open();
rfid.FindMode();
rfidMap.Add(ip, rfid); 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)) 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!