Commit 01c8f861 LN

料架修改

1 个父辈 52d7b130
此文件类型无法预览
...@@ -276,13 +276,6 @@ ...@@ -276,13 +276,6 @@
<param name="action"></param> <param name="action"></param>
<param name="level"></param> <param name="level"></param>
</member> </member>
<member name="M:Asa.Client2.Reconnect">
<summary>
发送RFID
</summary>
<param name="name"></param>
<param name="content"></param>
</member>
<member name="M:Asa.Client2.Splice(Asa.ClientNode)"> <member name="M:Asa.Client2.Splice(Asa.ClientNode)">
<summary> <summary>
拼接命令 拼接命令
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmLineStore)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmLineStore));
this.tabControl1 = new System.Windows.Forms.TabControl(); this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage(); this.tabPage1 = new System.Windows.Forms.TabPage();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.logBox = new System.Windows.Forms.RichTextBox(); this.logBox = new System.Windows.Forms.RichTextBox();
this.lblCID = new System.Windows.Forms.Label(); this.lblCID = new System.Windows.Forms.Label();
this.groupBox3 = new System.Windows.Forms.GroupBox(); this.groupBox3 = new System.Windows.Forms.GroupBox();
...@@ -98,7 +99,6 @@ ...@@ -98,7 +99,6 @@
this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator8 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem();
this.timer1 = new System.Windows.Forms.Timer(this.components); this.timer1 = new System.Windows.Forms.Timer(this.components);
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.tabControl1.SuspendLayout(); this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout(); this.tabPage1.SuspendLayout();
this.groupBox3.SuspendLayout(); this.groupBox3.SuspendLayout();
...@@ -141,6 +141,20 @@ ...@@ -141,6 +141,20 @@
this.tabPage1.Text = "状态信息"; this.tabPage1.Text = "状态信息";
this.tabPage1.UseVisualStyleBackColor = true; this.tabPage1.UseVisualStyleBackColor = true;
// //
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Checked = true;
this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox1.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.checkBox1.Location = new System.Drawing.Point(478, 137);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(119, 24);
this.checkBox1.TabIndex = 198;
this.checkBox1.Text = "启用agvClient";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// logBox // logBox
// //
this.logBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.logBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
...@@ -599,7 +613,7 @@ ...@@ -599,7 +613,7 @@
// 扫码测试ToolStripMenuItem // 扫码测试ToolStripMenuItem
// //
this.扫码测试ToolStripMenuItem.Name = "扫码测试ToolStripMenuItem"; this.扫码测试ToolStripMenuItem.Name = "扫码测试ToolStripMenuItem";
this.扫码测试ToolStripMenuItem.Size = new System.Drawing.Size(180, 26); this.扫码测试ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.扫码测试ToolStripMenuItem.Text = "扫码测试"; this.扫码测试ToolStripMenuItem.Text = "扫码测试";
this.扫码测试ToolStripMenuItem.Visible = false; this.扫码测试ToolStripMenuItem.Visible = false;
this.扫码测试ToolStripMenuItem.Click += new System.EventHandler(this.扫码测试ToolStripMenuItem_Click); this.扫码测试ToolStripMenuItem.Click += new System.EventHandler(this.扫码测试ToolStripMenuItem_Click);
...@@ -607,61 +621,61 @@ ...@@ -607,61 +621,61 @@
// toolStripSeparator6 // toolStripSeparator6
// //
this.toolStripSeparator6.Name = "toolStripSeparator6"; this.toolStripSeparator6.Name = "toolStripSeparator6";
this.toolStripSeparator6.Size = new System.Drawing.Size(177, 6); this.toolStripSeparator6.Size = new System.Drawing.Size(173, 6);
this.toolStripSeparator6.Visible = false; this.toolStripSeparator6.Visible = false;
// //
// 二维码学习ToolStripMenuItem // 二维码学习ToolStripMenuItem
// //
this.二维码学习ToolStripMenuItem.Name = "二维码学习ToolStripMenuItem"; this.二维码学习ToolStripMenuItem.Name = "二维码学习ToolStripMenuItem";
this.二维码学习ToolStripMenuItem.Size = new System.Drawing.Size(180, 26); this.二维码学习ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.二维码学习ToolStripMenuItem.Text = "二维码学习"; this.二维码学习ToolStripMenuItem.Text = "二维码学习";
this.二维码学习ToolStripMenuItem.Click += new System.EventHandler(this.二维码学习ToolStripMenuItem_Click); this.二维码学习ToolStripMenuItem.Click += new System.EventHandler(this.二维码学习ToolStripMenuItem_Click);
// //
// toolStripSeparator7 // toolStripSeparator7
// //
this.toolStripSeparator7.Name = "toolStripSeparator7"; this.toolStripSeparator7.Name = "toolStripSeparator7";
this.toolStripSeparator7.Size = new System.Drawing.Size(177, 6); this.toolStripSeparator7.Size = new System.Drawing.Size(173, 6);
// //
// 托盘初始化ToolStripMenuItem // 托盘初始化ToolStripMenuItem
// //
this.托盘初始化ToolStripMenuItem.Name = "托盘初始化ToolStripMenuItem"; this.托盘初始化ToolStripMenuItem.Name = "托盘初始化ToolStripMenuItem";
this.托盘初始化ToolStripMenuItem.Size = new System.Drawing.Size(180, 26); this.托盘初始化ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.托盘初始化ToolStripMenuItem.Text = "托盘编码"; this.托盘初始化ToolStripMenuItem.Text = "托盘编码";
this.托盘初始化ToolStripMenuItem.Click += new System.EventHandler(this.托盘初始化ToolStripMenuItem_Click); this.托盘初始化ToolStripMenuItem.Click += new System.EventHandler(this.托盘初始化ToolStripMenuItem_Click);
// //
// toolStripSeparator9 // toolStripSeparator9
// //
this.toolStripSeparator9.Name = "toolStripSeparator9"; this.toolStripSeparator9.Name = "toolStripSeparator9";
this.toolStripSeparator9.Size = new System.Drawing.Size(177, 6); this.toolStripSeparator9.Size = new System.Drawing.Size(173, 6);
// //
// iO模块状态ToolStripMenuItem // iO模块状态ToolStripMenuItem
// //
this.iO模块状态ToolStripMenuItem.Name = "iO模块状态ToolStripMenuItem"; this.iO模块状态ToolStripMenuItem.Name = "iO模块状态ToolStripMenuItem";
this.iO模块状态ToolStripMenuItem.Size = new System.Drawing.Size(180, 26); this.iO模块状态ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.iO模块状态ToolStripMenuItem.Text = "IO模块状态"; this.iO模块状态ToolStripMenuItem.Text = "IO模块状态";
this.iO模块状态ToolStripMenuItem.Click += new System.EventHandler(this.iO模块状态ToolStripMenuItem_Click); this.iO模块状态ToolStripMenuItem.Click += new System.EventHandler(this.iO模块状态ToolStripMenuItem_Click);
// //
// toolStripSeparator13 // toolStripSeparator13
// //
this.toolStripSeparator13.Name = "toolStripSeparator13"; this.toolStripSeparator13.Name = "toolStripSeparator13";
this.toolStripSeparator13.Size = new System.Drawing.Size(177, 6); this.toolStripSeparator13.Size = new System.Drawing.Size(173, 6);
// //
// toolStripMenuItem2 // toolStripMenuItem2
// //
this.toolStripMenuItem2.Name = "toolStripMenuItem2"; this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(180, 26); this.toolStripMenuItem2.Size = new System.Drawing.Size(176, 26);
this.toolStripMenuItem2.Text = "AGV调试"; this.toolStripMenuItem2.Text = "AGV调试";
this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click); this.toolStripMenuItem2.Click += new System.EventHandler(this.toolStripMenuItem2_Click);
// //
// toolStripSeparator12 // toolStripSeparator12
// //
this.toolStripSeparator12.Name = "toolStripSeparator12"; this.toolStripSeparator12.Name = "toolStripSeparator12";
this.toolStripSeparator12.Size = new System.Drawing.Size(177, 6); this.toolStripSeparator12.Size = new System.Drawing.Size(173, 6);
// //
// 清空托盘信息ToolStripMenuItem // 清空托盘信息ToolStripMenuItem
// //
this.清空托盘信息ToolStripMenuItem.Name = "清空托盘信息ToolStripMenuItem"; this.清空托盘信息ToolStripMenuItem.Name = "清空托盘信息ToolStripMenuItem";
this.清空托盘信息ToolStripMenuItem.Size = new System.Drawing.Size(180, 26); this.清空托盘信息ToolStripMenuItem.Size = new System.Drawing.Size(176, 26);
this.清空托盘信息ToolStripMenuItem.Text = "清空托盘信息"; this.清空托盘信息ToolStripMenuItem.Text = "清空托盘信息";
this.清空托盘信息ToolStripMenuItem.Click += new System.EventHandler(this.清空托盘信息ToolStripMenuItem_Click); this.清空托盘信息ToolStripMenuItem.Click += new System.EventHandler(this.清空托盘信息ToolStripMenuItem_Click);
// //
...@@ -750,18 +764,6 @@ ...@@ -750,18 +764,6 @@
this.timer1.Interval = 2000; this.timer1.Interval = 2000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick); this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
// //
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.checkBox1.Location = new System.Drawing.Point(478, 137);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(119, 24);
this.checkBox1.TabIndex = 198;
this.checkBox1.Text = "启用agvClient";
this.checkBox1.UseVisualStyleBackColor = true;
this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
//
// FrmLineStore // FrmLineStore
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
......
...@@ -107,23 +107,23 @@ namespace OnlineStore.AssemblyLine ...@@ -107,23 +107,23 @@ namespace OnlineStore.AssemblyLine
private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e) private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
{ {
LogUnhandledException("CurrentDomain_FirstChanceException", e); // LogUnhandledException("CurrentDomain_FirstChanceException", e);
} }
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
LogUnhandledException("CurrentDomain_UnhandledException",e); LogUnhandledException("CurrentDomain_UnhandledException", e);
} }
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);
} }
static void LogUnhandledException(string type,Exception exceptionobj) static void LogUnhandledException(string type, object exceptionobj)
{ {
//这里可以进一步地写日志 //这里可以进一步地写日志
LOGGER.Error("【"+ type + "】"+exceptionobj.ToString()); LOGGER.Error("【" + type + "】" + exceptionobj.ToString());
MessageBox.Show(exceptionobj.ToString(), type); MessageBox.Show(exceptionobj.ToString(), type);
} }
} }
......
...@@ -96,7 +96,6 @@ ...@@ -96,7 +96,6 @@
<Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" /> <Compile Include="deviceLibrary\PanasonicServo\ACServerManager.cs" />
<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\RFID.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAuto.cs" /> <Compile Include="deviceLibrary\RFID\RFIDAuto.cs" />
<Compile Include="deviceLibrary\RFID\RFIDReader.cs" /> <Compile Include="deviceLibrary\RFID\RFIDReader.cs" />
<Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" /> <Compile Include="deviceLibrary\RFID\RFIDAutoReader.cs" />
......
...@@ -20,7 +20,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -20,7 +20,7 @@ namespace OnlineStore.DeviceLibrary
public partial class LineBean : KTK_Store public partial class LineBean : KTK_Store
{ {
public bool IsDebug = false; public bool IsDebug = false;
public bool UseAgvClient = false; public bool UseAgvClient = true;
/// <summary> /// <summary>
/// 灯闪烁定时器 /// 灯闪烁定时器
/// </summary> /// </summary>
...@@ -166,7 +166,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -166,7 +166,7 @@ namespace OnlineStore.DeviceLibrary
LogUtil.error(Name + "加载调试设备出错:",ex); LogUtil.error(Name + "加载调试设备出错:",ex);
} }
} }
RFIDManager.Init();
Task.Factory.StartNew(delegate Task.Factory.StartNew(delegate
{ {
LogUtil.info(Name + "开始连接IO模块 "); LogUtil.info(Name + "开始连接IO模块 ");
......
...@@ -16,9 +16,10 @@ namespace OnlineStore.DeviceLibrary ...@@ -16,9 +16,10 @@ namespace OnlineStore.DeviceLibrary
public static List<string> ShelfIpList = new List<string>(); public static List<string> ShelfIpList = new List<string>();
public static List<string> TrayIpList = new List<string>(); public static List<string> TrayIpList = new List<string>();
private static int DefaultTrayNum = ConfigAppSettings.GetIntValue(Setting_Init.DefaultTrayNum); private static int DefaultTrayNum = ConfigAppSettings.GetIntValue(Setting_Init.DefaultTrayNum);
public static void Init()
public static void Open()
{ {
TrayIpList = new List<string>();
ShelfIpList = new List<string>();
Dictionary<string, string> rfidMap = DeviceConfig.ProRFIpMap; Dictionary<string, string> rfidMap = DeviceConfig.ProRFIpMap;
foreach (string key in rfidMap.Keys) foreach (string key in rfidMap.Keys)
{ {
...@@ -31,7 +32,13 @@ namespace OnlineStore.DeviceLibrary ...@@ -31,7 +32,13 @@ namespace OnlineStore.DeviceLibrary
TrayIpList.Add(rfidMap[key]); TrayIpList.Add(rfidMap[key]);
} }
} }
RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray()); }
public static void Open()
{
// RFIDAutoReader.Open(null, new List<string>(rfidMap.Values).ToArray());
RFIDAutoReader.Open(null, TrayIpList.ToArray());
RFIDReader.Open(ShelfIpList.ToArray());
} }
/// <summary> /// <summary>
...@@ -78,16 +85,26 @@ namespace OnlineStore.DeviceLibrary ...@@ -78,16 +85,26 @@ namespace OnlineStore.DeviceLibrary
public static RFIDData GetShelfId(int subType) public static RFIDData GetShelfId(int subType)
{ {
string ip = GetRFIP(subType, 1); string ip = GetRFIP(subType, 1);
RFIDData data = ReadRFID(ip, true); return ReadRFID(ip, true);
return data;
} }
public static RFIDData ReadRFID(string ip, bool isClear = false) public static RFIDData ReadRFID(string ip, bool isClear = false)
{ {
try try
{ {
if (String.IsNullOrEmpty(ip).Equals(false) ) if (String.IsNullOrEmpty(ip).Equals(false) && ShelfIpList.Contains(ip))
{
byte[] bdata = RFIDReader.Read(ip, true);
if (bdata == null)
{
LogUtil.error("RFID [ " + ip + " ] 读到数据=null");
}
RFIDData data = new RFIDData(bdata);
return data;
}
else
//if (String.IsNullOrEmpty(ip).Equals(false) && LineManager.Line.rfidList.Contains(ip)) //if (String.IsNullOrEmpty(ip).Equals(false) && LineManager.Line.rfidList.Contains(ip))
{ {
byte[] bdata = null; byte[] bdata = null;
...@@ -112,7 +129,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -112,7 +129,7 @@ namespace OnlineStore.DeviceLibrary
{ {
//LogUtil.error("ReadRFID["+ip+"]出错:",ex); //LogUtil.error("ReadRFID["+ip+"]出错:",ex);
} }
return new RFIDData( ); return new RFIDData();
} }
public static string GetRFIP(int subType, int rtType = 0) public static string GetRFIP(int subType, int rtType = 0)
...@@ -138,7 +155,15 @@ namespace OnlineStore.DeviceLibrary ...@@ -138,7 +155,15 @@ namespace OnlineStore.DeviceLibrary
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("关闭RFID出错:", ex); LogUtil.error("RFIDAutoReader.CloseAll()出错:", ex);
}
try
{
RFIDReader.CloseAll();
}
catch (Exception ex)
{
LogUtil.error("RFIDReader.CloseAll()出错:", ex);
} }
} }
} }
......
...@@ -8,164 +8,4 @@ using System.Threading.Tasks; ...@@ -8,164 +8,4 @@ using System.Threading.Tasks;
namespace Asa.RFID 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;
}
}
} }
...@@ -8,6 +8,179 @@ using static Asa.RFID.RFIDAuto; ...@@ -8,6 +8,179 @@ using static Asa.RFID.RFIDAuto;
namespace Asa.RFID 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);
// 在 OpenNetPort 后面使用
System.Threading.Thread.Sleep(100);
OpenCloseRF(false);
System.Threading.Thread.Sleep(100);
OpenCloseRF(true);
return ErrCode;
}
private void OpenCloseRF(bool rtn)
{
if (rtn)
ErrCode = ReaderA.StaticClassReaderA.OpenRf(ref addr, portIndex);
else
ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex);
}
/// <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;
}
}
public class RFIDReader public class RFIDReader
{ {
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID"); public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
...@@ -15,9 +188,9 @@ namespace Asa.RFID ...@@ -15,9 +188,9 @@ namespace Asa.RFID
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)
{ {
if (rfidMap.ContainsKey(ip)) if (rfidMap.ContainsKey(ip))
{ {
...@@ -40,7 +213,7 @@ namespace Asa.RFID ...@@ -40,7 +213,7 @@ namespace Asa.RFID
return false; return false;
} }
public static byte[] Read(string ip,bool isNeedFind) public static byte[] Read(string ip, bool isNeedFind)
{ {
if (rfidMap.ContainsKey(ip)) if (rfidMap.ContainsKey(ip))
{ {
...@@ -51,7 +224,7 @@ namespace Asa.RFID ...@@ -51,7 +224,7 @@ namespace Asa.RFID
public static void CloseAll() public static void CloseAll()
{ {
foreach(var rfid in rfidMap.Values) foreach (var rfid in rfidMap.Values)
{ {
rfid.Close(); rfid.Close();
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!