Commit 267ee1bb LN

rfid改为扫描模式

1 个父辈 87f37e53
......@@ -81,8 +81,9 @@
<Compile Include="bean\StoreStep.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="RFID\RFIDAuto.cs" />
<Compile Include="RFID\RFIDAutoReader.cs" />
<Compile Include="RFID\RFIDManager.cs" />
<Compile Include="RFID\RFIDReader.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Common\Common.csproj">
......
using log4net;
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Asa.RFID
{
public class RFID
public class RFIDAuto
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
......@@ -28,7 +30,7 @@ namespace Asa.RFID
/// </summary>
public event Received_Event Received;
public RFID(string ip)
public RFIDAuto(string ip)
{
this.IP = ip;
}
......@@ -57,14 +59,15 @@ namespace Asa.RFID
{
if (IsConnect)
{
LOGGER.Warn(" RFID [" + IP+"] is already connected, no need to start again");
LOGGER.Warn(" RFID [" + IP + "] is already connected, no need to start again");
return 0;
}
this.Received = OnReceive;
//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) {
if (!rtn)
{
LOGGER.Error(IP + " is error");
return -1;
}
......@@ -78,14 +81,24 @@ namespace Asa.RFID
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);
if (ErrCode == 0)
int ErrCode = 0;
for (int i = 1; i <= 3; i++)
{
ErrCode = OpenAutoScanMode(addr);
LOGGER.Info(" [" + IP + "] Open Auto Scan Mode:" + ErrCode);
Task.Factory.StartNew(AutoScan);
ErrCode = ReaderA.StaticClassReaderA.OpenNetPort(port, IP, ref addr, ref portIndex);
LOGGER.Info("Connect [" + IP + "] :" + ErrCode);
if (ErrCode == 0)
{
ErrCode = OpenAutoScanMode(addr);
LOGGER.Info(" [" + IP + "] Open Auto Scan Mode:" + ErrCode);
Task.Factory.StartNew(AutoScan);
break;
}
else if (i < 3)
{
LOGGER.Error("Connect [" + IP + "] " + ErrCode + ", StopAutoScan");
StopAutoScan();
}
Thread.Sleep(10);
}
return ErrCode;
}
......@@ -165,6 +178,11 @@ namespace Asa.RFID
{
LastOkTime = DateTime.Now;
string dataStr = byteToStr(data, len);
if (len > data.Length)
{
LOGGER.Info(IP + " Receive Code: " + ErrCode + " Len: " + len + " Data:" + dataStr);
}
LOGGER.Debug(IP + " Receive Code: " + ErrCode + " Len: " + len + " Data:" + dataStr);
byte[] temp = new byte[dataBuffer.Length + len];
......@@ -238,7 +256,7 @@ namespace Asa.RFID
else if (ErrCode == 14 && IsConnect)
{
LOGGER.Error(IP + " Receive Code: " + ErrCode + " 进行重连");
// LogUtil.error(IP + " Receive Code: " + ErrCode + " 进行重连");
LogUtil.error(IP + " Receive Code: " + ErrCode + " 进行重连");
StopAutoScan();
StartAutoScan(this.Received);
break;
......@@ -284,6 +302,10 @@ namespace Asa.RFID
private string byteToStr(byte[] data, int len)
{
if (data.Length <= len)
{
len = data.Length;
}
string s = "";
for (int i = 0; i < len; i++)
{
......
using log4net;
using OnlineStore.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static Asa.RFID.RFIDAuto;
namespace Asa.RFID
{
public class RFIDAutoReader
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
private static Dictionary<string, RFIDAuto> rfidMap = new Dictionary<string, RFIDAuto>();
public static Dictionary<string, int> rfidErrorMap = new Dictionary<string, int>();
/// <summary>
/// 打开所有
/// </summary>
/// <param name="ipArr"></param>
/// <param name="OnReceive"></param>
/// <param name="ip"></param>
public static void Open(Received_Event OnReceive, params string[] ipArr)
{
rfidErrorMap = new Dictionary<string, int>();
foreach (var ip in ipArr)
{
int code = 0;
if (rfidMap.ContainsKey(ip))
{
code = rfidMap[ip].StartAutoScan(OnReceive);
}
else
{
RFIDAuto rfid = new RFIDAuto(ip);
code = rfid.StartAutoScan(OnReceive);
rfidMap.Add(ip, rfid);
}
if (rfidErrorMap.ContainsKey(ip))
{
rfidErrorMap.Remove(ip);
}
rfidErrorMap.Add(ip, code);
if (code.Equals(0).Equals(false))
{
LogUtil.error("连接RFID【" + ip + "】ErrorCode=" + code);
}
}
}
public static void ReOpen(string ip)
{
LogUtil.error("ReOpen【" + ip + "】");
int code = 0;
if (rfidMap.ContainsKey(ip))
{
rfidMap[ip].StopAutoScan();
Thread.Sleep(200);
code = rfidMap[ip].StartAutoScan(null);
}
else
{
RFIDAuto rfid = new RFIDAuto(ip);
code = rfid.StartAutoScan(null);
rfidMap.Add(ip, rfid);
}
if (rfidErrorMap.ContainsKey(ip))
{
rfidErrorMap.Remove(ip);
}
rfidErrorMap.Add(ip, code);
if (code.Equals(0).Equals(false))
{
LogUtil.error("连接RFID【" + ip + "】ErrorCode=" + code);
}
}
/// <summary>
/// 获取最后读到的标签并清理
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public static byte[] ReadAndClear(string ip)
{
if (rfidMap.ContainsKey(ip))
{
return rfidMap[ip].ReadAndClear();
}
return null;
}
/// <summary>
/// 获取最后读到的标签
/// </summary>
/// <param name="ip"></param>
/// <returns></returns>
public static byte[] Read(string ip)
{
if (rfidMap.ContainsKey(ip))
{
return rfidMap[ip].Read();
}
return null;
}
/// <summary>
/// 关闭所有
/// </summary>
public static void CloseAll()
{
foreach (var rfid in rfidMap.Values)
{
rfid.StopAutoScan();
}
rfidMap = new Dictionary<string, RFIDAuto>();
}
}
}
......@@ -17,7 +17,7 @@ namespace OnlineStore.DeviceLibrary
{
try
{
RFIDReader.Open( iparray);
RFIDAutoReader.Open( null,iparray);
}catch(Exception ex)
{
LogUtil.error("Open 出错:" + ex.ToString());
......@@ -30,9 +30,15 @@ namespace OnlineStore.DeviceLibrary
{
if (String.IsNullOrEmpty(ip).Equals(false))
{
byte[] bdata = null;
bdata = RFIDReader.Read(ip, isClear);
byte[] bdata = null;
if (isClear)
{
bdata = RFIDAutoReader.ReadAndClear(ip);
}
else
{
bdata = RFIDAutoReader.Read(ip);
}
if (bdata == null)
{
LogUtil.error("RFID [ " + ip + " ] 读到数据=null");
......@@ -53,7 +59,7 @@ namespace OnlineStore.DeviceLibrary
{
try
{
RFIDReader.CloseAll();
RFIDAutoReader.CloseAll();
}
catch (Exception ex)
{
......@@ -111,7 +117,7 @@ namespace OnlineStore.DeviceLibrary
}
public string NumStr()
{
return "" + RFType + "" + Num.ToString().PadLeft(2, '0') + "";
return "" + RFType + "" + Num.ToString() + "";
}
}
}
......@@ -126,15 +126,16 @@ namespace OnlineStore.DeviceLibrary
public string GetRunInfo()
{
return "进料入口料架: " + LastInShelfId + " 进料出口料架: " + LastOutShelfId + "\r\n" +
"进料出口" + Config.InL_AgvName + ":" + AgvClient.GetAction(Config.InL_AgvName) + " 出料进口" + Config.OutL_AgvName + ":" + AgvClient.GetAction(Config.OutL_AgvName) + "\r\n"+
( IsSleep?"休眠中":"工作中");
return "进料线出口" + Config.InL_AgvName + ":" + AgvClient.GetAction(Config.InL_AgvName) + ",料架: " + LastInShelfId + "\r\n" +
"出料线进口" + Config.OutL_AgvName + ":" + AgvClient.GetAction(Config.OutL_AgvName) + ",料架: " + LastOutShelfId + "\r\n";
// "进料出口" + Config.InL_AgvName + ":" + AgvClient.GetAction(Config.InL_AgvName) + " 出料进口" + Config.OutL_AgvName + ":" + AgvClient.GetAction(Config.OutL_AgvName) + "\r\n"+
}
#endregion
#region 休眠处理
private bool IsSleep = false;
public bool IsSleep = false;
private DateTime LastBusyTime = DateTime.Now;
private Dictionary<string, IO_VALUE> lastDIValue = new Dictionary<string, IO_VALUE>();
......
......@@ -122,7 +122,7 @@ namespace OnlineStore.VMILineClient
return;
}
ReadIOList();
lblThisSta.Text = LineManager.GetRunStr(vmiLine.runStatus);
lblThisSta.Text = LineManager.GetRunStr(vmiLine.runStatus)+" "+(vmiLine.IsSleep ? "休眠中" :"");
lblWarnMsg.Text = vmiLine.WarnMsg;
lblInfo.Text = vmiLine.GetRunInfo();
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!