Commit 7fb1e0a4 LN

rfid修改

1 个父辈 c5ac6de8
此文件类型无法预览
...@@ -230,11 +230,6 @@ ...@@ -230,11 +230,6 @@
</summary> </summary>
<param name="s"></param> <param name="s"></param>
</member> </member>
<member name="E:Asa.Client2.GetRFID">
<summary>
服务端发送的RFID
</summary>
</member>
<member name="E:Asa.Client2.Arrive"> <member name="E:Asa.Client2.Arrive">
<summary> <summary>
小车到达,仅包装料仓 小车到达,仅包装料仓
...@@ -281,13 +276,6 @@ ...@@ -281,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>
拼接命令 拼接命令
...@@ -385,12 +373,12 @@ ...@@ -385,12 +373,12 @@
</member> </member>
<member name="F:Asa.ClientAction.MayEnter"> <member name="F:Asa.ClientAction.MayEnter">
<summary> <summary>
可以进入料架(包装料仓) 可以进入料架,Arrive事件使用,让小车开始对接
</summary> </summary>
</member> </member>
<member name="F:Asa.ClientAction.MayLeave"> <member name="F:Asa.ClientAction.MayLeave">
<summary> <summary>
可以出去料架(包装料仓) 可以出去料架,Arrive事件使用,让小车开始对接
</summary> </summary>
</member> </member>
<member name="F:Asa.ClientAction.NeedEnter"> <member name="F:Asa.ClientAction.NeedEnter">
...@@ -415,12 +403,12 @@ ...@@ -415,12 +403,12 @@
</member> </member>
<member name="F:Asa.ClientAction.Arrive"> <member name="F:Asa.ClientAction.Arrive">
<summary> <summary>
小车到达 小车到达,到达包装料仓门口,等待开门
</summary> </summary>
</member> </member>
<member name="F:Asa.ClientAction.Ready"> <member name="F:Asa.ClientAction.Ready">
<summary> <summary>
小车已准备 小车已准备,已对接上流水线
</summary> </summary>
</member> </member>
<member name="T:Asa.ClientLevel"> <member name="T:Asa.ClientLevel">
......
此文件类型无法预览
1.0.0.0 2019-11-19
1、钉盘上传
\ No newline at end of file \ No newline at end of file
...@@ -205,6 +205,7 @@ ...@@ -205,6 +205,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);
......
...@@ -36,9 +36,17 @@ namespace OnlineStore.ACPackingStore ...@@ -36,9 +36,17 @@ namespace OnlineStore.ACPackingStore
comboxType.SelectedIndex = 0; comboxType.SelectedIndex = 0;
comType.SelectedIndex = 0; comType.SelectedIndex = 0;
string hostN = Dns.GetHostName(); List<string> List = new List<string>();
IPAddress[] addresss = Dns.GetHostAddresses(hostN); List = new List<string>(rfMap.Values);
if (StoreManager.Store.storeRunStatus <= StoreRunStatus.Wait)
{
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Open");
RFIDManager.Open(List.ToArray());
});
}
} }
private void btnBack_Click(object sender, EventArgs e) private void btnBack_Click(object sender, EventArgs e)
...@@ -78,6 +86,17 @@ namespace OnlineStore.ACPackingStore ...@@ -78,6 +86,17 @@ namespace OnlineStore.ACPackingStore
txtIP.Text = V; txtIP.Text = V;
} }
} }
} }
private void FrmRFIPEdit_FormClosed(object sender, FormClosedEventArgs e)
{
if (StoreManager.Store.storeRunStatus <= StoreRunStatus.Wait)
{
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Close");
RFIDManager.Close();
});
}
}
} }
} }
...@@ -83,9 +83,8 @@ ...@@ -83,9 +83,8 @@
<Compile Include="device\PanasonicServo\ACCMDManager.cs" /> <Compile Include="device\PanasonicServo\ACCMDManager.cs" />
<Compile Include="device\PanasonicServo\ACServerManager.cs" /> <Compile Include="device\PanasonicServo\ACServerManager.cs" />
<Compile Include="device\PanasonicServo\ACServerManager_Partial.cs" /> <Compile Include="device\PanasonicServo\ACServerManager_Partial.cs" />
<Compile Include="device\RFID\RFIDAuto.cs" />
<Compile Include="device\RFID\RFIDManager.cs" /> <Compile Include="device\RFID\RFIDManager.cs" />
<Compile Include="device\RFID\RFIDAutoReader.cs" /> <Compile Include="device\RFID\RFIDReader.cs" />
<Compile Include="store\AutoInoutInfo.cs" /> <Compile Include="store\AutoInoutInfo.cs" />
<Compile Include="store\LineMoveP.cs" /> <Compile Include="store\LineMoveP.cs" />
<Compile Include="store\LineAlarm.cs"> <Compile Include="store\LineAlarm.cs">
......
...@@ -12,18 +12,19 @@ using System.Windows.Forms; ...@@ -12,18 +12,19 @@ using System.Windows.Forms;
namespace OnlineStore.DeviceLibrary namespace OnlineStore.DeviceLibrary
{ {
public class RFIDManager public class RFIDManager
{ {
public static void Open(string[] iparray) public static void Open(string[] iparray)
{ {
try try
{ {
RFIDAutoReader.Open(null, iparray); RFIDReader.Open(iparray);
}catch(Exception ex) }
catch (Exception ex)
{ {
LogUtil.error("Open 出错:" + ex.ToString()); LogUtil.error("Open 出错:" + ex.ToString());
} }
} }
public static RFIDData ReadRFID(string ip, bool isClear = false) public static RFIDData ReadRFID(string ip, bool isClear = false)
{ {
try try
...@@ -31,14 +32,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -31,14 +32,9 @@ namespace OnlineStore.DeviceLibrary
if (String.IsNullOrEmpty(ip).Equals(false)) if (String.IsNullOrEmpty(ip).Equals(false))
{ {
byte[] bdata = null; byte[] bdata = null;
if (isClear)
{ bdata = RFIDReader.Read(ip, isClear);
bdata = RFIDAutoReader.ReadAndClear(ip);
}
else
{
bdata = RFIDAutoReader.Read(ip);
}
if (bdata == null) if (bdata == null)
{ {
LogUtil.error("RFID [ " + ip + " ] 读到数据=null"); LogUtil.error("RFID [ " + ip + " ] 读到数据=null");
...@@ -59,25 +55,25 @@ namespace OnlineStore.DeviceLibrary ...@@ -59,25 +55,25 @@ namespace OnlineStore.DeviceLibrary
{ {
try try
{ {
RFIDAutoReader.CloseAll(); RFIDReader.CloseAll();
} }
catch (Exception ex) catch (Exception ex)
{ {
LogUtil.error("关闭RFID出错:" + ex.ToString()); LogUtil.error("关闭RFID出错:" + ex.ToString());
} }
} }
} }
public class RFIDData public class RFIDData
{ {
/// <summary> /// <summary>
/// RFID类型,区分是料架还是托盘,托盘E=69,包装料料架A=65,料串=B /// RFID类型,区分是料架还是托盘,托盘E=69,包装料料架A=65,料串=B
/// </summary> /// </summary>
public char RFType = '0'; public char RFType = '0';
public int Num = 0; public int Num = 0;
public RFIDData(int num=0, int t=0) public RFIDData(int num = 0, int t = 0)
{ {
if (t < 65) if (t < 65)
{ {
...@@ -120,5 +116,5 @@ namespace OnlineStore.DeviceLibrary ...@@ -120,5 +116,5 @@ namespace OnlineStore.DeviceLibrary
{ {
return "" + RFType + "" + Num.ToString().PadLeft(2, '0') + ""; return "" + RFType + "" + Num.ToString().PadLeft(2, '0') + "";
} }
} }
} }
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 System.Threading.Thread tScan;
private bool loop;
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;
/// <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;
}
public int Close()
{
try
{
loop = false;
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;
}
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)
ErrCode = ReaderA.StaticClassReaderA.OpenRf(ref addr, portIndex);
else
ErrCode = ReaderA.StaticClassReaderA.CloseRf(ref addr, portIndex);
}
/// <summary>
/// 查找电子标签,扫描模式不能使用
/// </summary>
/// <returns></returns>
public bool FindRFID()
{
try
{
//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;
if (_uid == null)
{
_uid = new byte[8];
}
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;
}
}catch(Exception ex)
{
LOGGER.Error(IP + "FindRFID Error:" + ex.ToString());
}
return false;
}
public byte[] Read(bool isNeedFind = false)
{
if (isNeedFind)
{
FindRFID();
}
if (IsExist)
{
ReadRFID();
return _buff;
}
else
{
LOGGER.Info(IP + " Read: IsExist=false ");
}
return null;
}
private void ReadRFID()
{
try
{
//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;
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());
}
}
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 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);
}
}
}
catch (Exception ex)
{
LOGGER.Error ("RFIDReader Open Error:" + ex.ToString());
}
}
private static void Rfid_Received(string ip, byte[] buff)
{
if (buff == null)
{
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);
}
}
//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 (LastRfidData.ContainsKey(ip))
{
byte[] data= LastRfidData[ip];
if (isClear)
{
LastRfidData.Remove(ip);
}
return data;
}
// return rfidMap[ip].Read(isNeedFind);
}
return null;
}
public static void CloseAll()
{
foreach (var rfid in rfidMap.Values)
{
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!