Commit ccb39bb3 LN

rfid修改

1 个父辈 d2c26239
...@@ -17,7 +17,7 @@ namespace OnlineStore.ACPackingStore ...@@ -17,7 +17,7 @@ namespace OnlineStore.ACPackingStore
{ {
internal partial class FrmRFIPEdit : FrmBase internal partial class FrmRFIPEdit : FrmBase
{ {
internal FrmRFIPEdit( ) internal FrmRFIPEdit()
{ {
InitializeComponent(); InitializeComponent();
} }
...@@ -41,11 +41,7 @@ namespace OnlineStore.ACPackingStore ...@@ -41,11 +41,7 @@ namespace OnlineStore.ACPackingStore
if (StoreManager.Store.storeRunStatus <= StoreRunStatus.Wait) if (StoreManager.Store.storeRunStatus <= StoreRunStatus.Wait)
{ {
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Open");
RFIDManager.Open(List.ToArray()); RFIDManager.Open(List.ToArray());
});
} }
} }
...@@ -91,11 +87,7 @@ namespace OnlineStore.ACPackingStore ...@@ -91,11 +87,7 @@ namespace OnlineStore.ACPackingStore
{ {
if (StoreManager.Store.storeRunStatus <= StoreRunStatus.Wait) if (StoreManager.Store.storeRunStatus <= StoreRunStatus.Wait)
{ {
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Close");
RFIDManager.Close(); RFIDManager.Close();
});
} }
} }
} }
......
...@@ -234,15 +234,20 @@ namespace OnlineStore.ACPackingStore ...@@ -234,15 +234,20 @@ namespace OnlineStore.ACPackingStore
return; return;
} }
LogUtil.info(LOGGER, "开始启动"); LogUtil.info(LOGGER, "开始启动");
startTimer.Interval = 1; startTimer.Interval = 300;
startTimer.Elapsed += timer_Elapsed; startTimer.Elapsed += timer_Elapsed;
startTimer.AutoReset = false; startTimer.AutoReset = false;
startTimer.Enabled = true; startTimer.Enabled = true;
} }
private delegate void ShowFormDelegate(); private delegate void ShowFormDelegate();
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ {
startTimer.Enabled = false; startTimer.Enabled = false;
if (store.storeRunStatus > StoreRunStatus.Wait)
{
return;
}
if (store.StartRun()) if (store.StartRun())
{ {
BeginInvoke(new ShowFormDelegate(ShowStatus)); BeginInvoke(new ShowFormDelegate(ShowStatus));
......
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;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Asa.RFID namespace Asa.RFID
{ {
public class RFIDAuto public class RFIDAuto
{ {
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID"); public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
...@@ -57,14 +60,15 @@ namespace Asa.RFID ...@@ -57,14 +60,15 @@ namespace Asa.RFID
{ {
if (IsConnect) 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; return 0;
} }
this.Received = OnReceive; this.Received = OnReceive;
//IP合法 //IP合法
string pattern = @"^((2[0-4]\d|25[0-5]|[01]?\d\d?)\.){3}(2[0-4]\d|25[0-5]|[01]?\d\d?)$"; 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); bool rtn = System.Text.RegularExpressions.Regex.IsMatch(IP, pattern);
if (!rtn) { if (!rtn)
{
LOGGER.Error(IP + " is error"); LOGGER.Error(IP + " is error");
return -1; return -1;
} }
...@@ -79,15 +83,26 @@ namespace Asa.RFID ...@@ -79,15 +83,26 @@ namespace Asa.RFID
int port = 6000 + Convert.ToInt32(arr[3]); int port = 6000 + Convert.ToInt32(arr[3]);
portIndex = 0; portIndex = 0;
int ErrCode = ReaderA.StaticClassReaderA.OpenNetPort(port, IP, ref addr, ref portIndex); int ErrCode = 0;
LOGGER.Info("Connect [" + IP + "] :" + ErrCode); for (int i = 1; i <= 3; i++)
{
ErrCode = ReaderA.StaticClassReaderA.OpenNetPort(port, IP, ref addr, ref portIndex);
LOGGER.Info("Connect [" + IP + "] ["+i+"] :" + ErrCode);
if (ErrCode == 0) if (ErrCode == 0)
{ {
ErrCode = OpenAutoScanMode(addr); ErrCode = OpenAutoScanMode(addr);
LOGGER.Info(" [" + IP + "] Open Auto Scan Mode:" + ErrCode); LOGGER.Info(" [" + IP + "] Open Auto Scan Mode:" + ErrCode);
Task.Factory.StartNew(AutoScan); Task.Factory.StartNew(AutoScan);
break;
}
else
{
StopAutoScan();
}
Thread.Sleep(10);
} }
return ErrCode; return ErrCode;
} }
private int SetAutoScanMode(byte addr, byte scanMode) private int SetAutoScanMode(byte addr, byte scanMode)
...@@ -238,7 +253,7 @@ namespace Asa.RFID ...@@ -238,7 +253,7 @@ namespace Asa.RFID
else if (ErrCode == 14 && IsConnect) else if (ErrCode == 14 && IsConnect)
{ {
LOGGER.Error(IP + " Receive Code: " + ErrCode + " 进行重连"); LOGGER.Error(IP + " Receive Code: " + ErrCode + " 进行重连");
// LogUtil.error(IP + " Receive Code: " + ErrCode + " 进行重连"); LogUtil.error(IP + " Receive Code: " + ErrCode + " 进行重连");
StopAutoScan(); StopAutoScan();
StartAutoScan(this.Received); StartAutoScan(this.Received);
break; break;
...@@ -267,7 +282,7 @@ namespace Asa.RFID ...@@ -267,7 +282,7 @@ namespace Asa.RFID
{ {
byte[] data = lastData; byte[] data = lastData;
lastData = new byte[8]; lastData = new byte[8];
LOGGER.Info("Read and clear RFID[" + IP + "] data:" + byteToStr(data, data.Length)); LOGGER.Debug("Read and clear RFID[" + IP + "] data:" + byteToStr(data, data.Length));
return data; return data;
} }
......
...@@ -22,7 +22,7 @@ namespace Asa.RFID ...@@ -22,7 +22,7 @@ namespace Asa.RFID
/// <param name="ip"></param> /// <param name="ip"></param>
public static void Open(Received_Event OnReceive, params string[] ipArr) public static void Open(Received_Event OnReceive, params string[] ipArr)
{ {
foreach(var ip in ipArr) foreach (var ip in ipArr)
{ {
if (rfidMap.ContainsKey(ip)) if (rfidMap.ContainsKey(ip))
{ {
...@@ -71,7 +71,7 @@ namespace Asa.RFID ...@@ -71,7 +71,7 @@ namespace Asa.RFID
/// </summary> /// </summary>
public static void CloseAll() public static void CloseAll()
{ {
foreach(var rfid in rfidMap.Values) foreach (var rfid in rfidMap.Values)
{ {
rfid.StopAutoScan(); rfid.StopAutoScan();
} }
......
...@@ -15,14 +15,18 @@ namespace OnlineStore.DeviceLibrary ...@@ -15,14 +15,18 @@ namespace OnlineStore.DeviceLibrary
{ {
public static void Open(string[] iparray) public static void Open(string[] iparray)
{ {
Task.Factory.StartNew(delegate
{
LogUtil.info( "RFIDManager.Open");
try try
{ {
RFIDAutoReader.Open(null,iparray); RFIDAutoReader.Open(null, 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)
...@@ -60,6 +64,9 @@ namespace OnlineStore.DeviceLibrary ...@@ -60,6 +64,9 @@ namespace OnlineStore.DeviceLibrary
public static void Close() public static void Close()
{ {
Task.Factory.StartNew(delegate
{
LogUtil.info("RFIDManager.Close");
try try
{ {
RFIDAutoReader.CloseAll(); RFIDAutoReader.CloseAll();
...@@ -68,6 +75,7 @@ namespace OnlineStore.DeviceLibrary ...@@ -68,6 +75,7 @@ namespace OnlineStore.DeviceLibrary
{ {
LogUtil.error("关闭RFID出错:" + ex.ToString()); LogUtil.error("关闭RFID出错:" + ex.ToString());
} }
});
} }
} }
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!