Commit ef93496b LN

rfid

1 个父辈 a8f58955
......@@ -40,7 +40,7 @@ namespace OnlineStore.AssemblyLine
lblRFID.Text = "RFID信息:\r\n";
msg = "";
List<string> rfidList = new List<string>(LineManager.Line. rfidList);
List<string> rfidList = new List<string>(DeviceConfig.ProRFIpMap.Values);
foreach (string ip in rfidList)
{
string con = RFIDManager.ReadRFID(ip) .NumStr() ;
......
......@@ -96,6 +96,7 @@
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" />
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="assemblyLine\EquipBase.cs" />
<Compile Include="deviceLibrary\RFID\RFID.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAuto.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" />
......
......@@ -47,7 +47,7 @@ namespace OnlineStore.DeviceLibrary
#region 初始化
public List<string> cioList = new List<string>( );
public List<string> rfidList = new List<string>();
// public List<string> rfidList = new List<string>();
private bool canStart = false;
public LineBean(Line_Config lineConfig, Dictionary<int, MoveEquip_Config> configList, Dictionary<int, FeedingEquip_Config> feedMap,
......@@ -123,7 +123,6 @@ namespace OnlineStore.DeviceLibrary
cioList = new List<string>(ioList);
string ids = ConfigAppSettings.GetValue(Setting_Init.DebugDeviceId);
rfidList = new List<string>(DeviceConfig.ProRFIpMap.Values);
// rfidList = new List<string>();
if (IsDebug)
{
......@@ -264,7 +263,7 @@ namespace OnlineStore.DeviceLibrary
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Open");
RFIDManager.Open(rfidList.ToArray());
RFIDManager.Open();
});
Thread.Sleep(5);
//连接AGV调度
......
......@@ -13,18 +13,25 @@ namespace OnlineStore.DeviceLibrary
{
public class RFIDManager
{
public static List<string> ShelfIpList = new List<string>();
public static List<string> TrayIpList = new List<string>();
private static int DefaultTrayNum = ConfigAppSettings.GetIntValue(Setting_Init.DefaultTrayNum);
static RFIDManager()
public static void Open()
{
}
public static void Open(string[] iparray)
Dictionary<string, string> rfidMap = DeviceConfig.ProRFIpMap;
foreach (string key in rfidMap.Keys)
{
RFIDAutoReader.Open(null, iparray);
if (key.EndsWith("-1"))
{
ShelfIpList.Add(rfidMap[key]);
}
private static void RfidReader_GetValue(string s)
else
{
LogUtil.info("RfidReader_GetValue:" + s);
TrayIpList.Add(rfidMap[key]);
}
}
RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray());
}
/// <summary>
......@@ -72,15 +79,7 @@ namespace OnlineStore.DeviceLibrary
{
string ip = GetRFIP(subType, 1);
RFIDData data = ReadRFID(ip, true);
//此处料串为B料架
//bytedata = data.ToData();
//if (data.RFType.Equals('B'))
//{
// return data.RFType.ToString() + "" + data.Num.ToString().PadLeft(2, '0');
//}else if (data.Num > 0)
//{
// LogUtil.error("RFID [ " + ip + " ] 读到数据 " + data.ToStr() + " 返回料架号为空");
//}
return data;
}
......@@ -88,7 +87,8 @@ namespace OnlineStore.DeviceLibrary
{
try
{
if (String.IsNullOrEmpty(ip).Equals(false) && LineManager.Line.rfidList.Contains(ip))
if (String.IsNullOrEmpty(ip).Equals(false) )
//if (String.IsNullOrEmpty(ip).Equals(false) && LineManager.Line.rfidList.Contains(ip))
{
byte[] bdata = null;
if (isClear)
......
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Asa.RFID
{
public class RFID
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private string IP = "";
private byte addr;
private int portIndex;
private bool IsConnect = false;
private byte[] lastData = new byte[8];
internal byte[] _buff; //8字节缓存
private byte[] _uid; //卡片ID
public bool IsExist = false;
public int ErrCode = 0;
public RFID(string ip)
{
this.IP = ip;
}
public int Close()
{
try
{
IsConnect = false;
int ErrCode = ReaderA.StaticClassReaderA.CloseNetPort(portIndex);
LOGGER.Info("Close RFID [" + IP + "]:" + ErrCode);
return ErrCode;
}
catch (Exception e)
{
LOGGER.Error("Close RFID[" + IP + "] has error", e);
}
return -1;
}
public int Open()
{
if (IsConnect)
{
LOGGER.Warn(" RFID [" + IP + "] is already connected, no need to start again");
return 0;
}
//IP合法
string pattern = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$";
bool rtn = System.Text.RegularExpressions.Regex.IsMatch(IP, pattern);
if (!rtn)
{
LOGGER.Error(IP + " is error");
return -1;
}
string[] arr = IP.Split('.');
if (arr.Length != 4)
{
LOGGER.Error(IP + " length is not 4");
return -1;
}
addr = Convert.ToByte(arr[3]);
int port = 6000 + Convert.ToInt32(arr[3]);
portIndex = 0;
int ErrCode = ReaderA.StaticClassReaderA.OpenNetPort(port, IP, ref addr, ref portIndex);
LOGGER.Info("Connect [" + IP + "] :" + ErrCode);
return ErrCode;
}
/// <summary>
/// 查找电子标签,扫描模式不能使用
/// </summary>
/// <returns></returns>
public bool FindRFID()
{
//0 不带AFI
//1 带AFI
//2 不带AFI,继续查询
//3 带AFI,继续查询
//6 不带AFI,新的查询
//7 带AFI,新的查询
byte state = 0;
//Select模式需要AFI
byte AFI = 0;
//输出,1字节DSFID,8字节UID
byte[] DSFIDAndUID = new byte[9];
//输出,标签数量
byte cardNumber = 0;
ErrCode = ReaderA.StaticClassReaderA.Inventory(ref addr, ref state, ref AFI, DSFIDAndUID, ref cardNumber, portIndex);
if (ErrCode == 0)
{
//查询时间
//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;
return false;
}
}
public byte[] Read(bool isNeedFind = false )
{
if (isNeedFind)
{
FindRFID();
}
if (IsExist)
{
ReadRFID();
return _buff;
}
return null;
}
private void ReadRFID()
{
//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];
//错误代码
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);
}
}
private string byteToStr(byte[] data, int len)
{
string s = "";
for (int i = 0; i < len; i++)
{
s += data[i].ToString("X2") + " ";
}
return s;
}
}
}
......@@ -12,68 +12,48 @@ namespace Asa.RFID
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private static Dictionary<string, RFIDAuto> rfidMap = new Dictionary<string, RFIDAuto>();
private static Dictionary<string, RFID> rfidMap = new Dictionary<string, RFID>();
/// <summary>
/// 打开所有
/// </summary>
/// <param name="ipArr"></param>
/// <param name="OnReceive"></param>
/// <param name="ip"></param>
public static void Open(Received_Event OnReceive, params string[] ipArr)
public static void Open( params string[] ipArr)
{
foreach(var ip in ipArr)
{
if (rfidMap.ContainsKey(ip))
{
rfidMap[ip].StartAutoScan(OnReceive);
rfidMap[ip].Open();
}
else
{
RFIDAuto rfid = new RFIDAuto(ip);
rfid.StartAutoScan(OnReceive);
RFID rfid = new RFID(ip);
rfid.Open();
rfidMap.Add(ip, rfid);
}
}
}
/// <summary>
/// 获取最后读到的标签并清理
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public static byte[] ReadAndClear(string ip)
public static bool FindRFID(string ip)
{
if (rfidMap.ContainsKey(ip))
{
return rfidMap[ip].ReadAndClear();
return rfidMap[ip].FindRFID();
}
return null;
return false;
}
/// <summary>
/// 获取最后读到的标签
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public static byte[] Read(string ip)
public static byte[] Read(string ip,bool isNeedFind)
{
if (rfidMap.ContainsKey(ip))
{
return rfidMap[ip].Read();
return rfidMap[ip].Read(isNeedFind);
}
return null;
}
/// <summary>
/// 关闭所有
/// </summary>
public static void CloseAll()
{
foreach(var rfid in rfidMap.Values)
{
rfid.StopAutoScan();
rfid.Close();
}
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!