Commit ccb39bb3 LN

rfid修改

1 个父辈 d2c26239
......@@ -16,9 +16,9 @@ using System.Windows.Forms;
namespace OnlineStore.ACPackingStore
{
internal partial class FrmRFIPEdit : FrmBase
{
internal FrmRFIPEdit( )
{
{
internal FrmRFIPEdit()
{
InitializeComponent();
}
private Dictionary<string, string> rfMap = new Dictionary<string, string>();
......@@ -32,7 +32,7 @@ namespace OnlineStore.ACPackingStore
rfMap.Add(key, value);
comboxType.Items.Add(key);
}
comboxType.SelectedIndex = 0;
comType.SelectedIndex = 0;
......@@ -41,13 +41,9 @@ namespace OnlineStore.ACPackingStore
if (StoreManager.Store.storeRunStatus <= StoreRunStatus.Wait)
{
Task.Factory.StartNew(delegate
{
LogUtil.info(Name + "RFIDManager.Open");
RFIDManager.Open(List.ToArray());
});
RFIDManager.Open(List.ToArray());
}
}
}
private void btnBack_Click(object sender, EventArgs e)
{
......@@ -73,7 +69,7 @@ namespace OnlineStore.ACPackingStore
}
lblResult.Text = resul;
MessageBox.Show("读取到数据:" + resul);
}
private void comboxType_SelectedIndexChanged(object sender, EventArgs e)
......@@ -91,11 +87,7 @@ namespace OnlineStore.ACPackingStore
{
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
return;
}
LogUtil.info(LOGGER, "开始启动");
startTimer.Interval = 1;
startTimer.Interval = 300;
startTimer.Elapsed += timer_Elapsed;
startTimer.AutoReset = false;
startTimer.Enabled = true;
}
private delegate void ShowFormDelegate();
void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
startTimer.Enabled = false;
if (store.storeRunStatus > StoreRunStatus.Wait)
{
return;
}
if (store.StartRun())
{
BeginInvoke(new ShowFormDelegate(ShowStatus));
......
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 RFIDAuto
{
public static readonly ILog LOGGER = LogManager.GetLogger("TheRFID");
......@@ -57,14 +60,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;
}
......@@ -79,15 +83,26 @@ namespace Asa.RFID
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 + "] ["+i+"] :" + ErrCode);
if (ErrCode == 0)
{
ErrCode = OpenAutoScanMode(addr);
LOGGER.Info(" [" + IP + "] Open Auto Scan Mode:" + ErrCode);
Task.Factory.StartNew(AutoScan);
break;
}
else
{
StopAutoScan();
}
Thread.Sleep(10);
}
return ErrCode;
}
private int SetAutoScanMode(byte addr, byte scanMode)
......@@ -238,7 +253,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;
......@@ -267,7 +282,7 @@ namespace Asa.RFID
{
byte[] data = lastData;
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;
}
......@@ -281,7 +296,7 @@ namespace Asa.RFID
byte scanMode = 1;
return SetAutoScanMode(addr, scanMode);
}
private string byteToStr(byte[] data, int len)
{
string s = "";
......
......@@ -20,9 +20,9 @@ namespace Asa.RFID
/// <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(Received_Event OnReceive, params string[] ipArr)
{
foreach(var ip in ipArr)
foreach (var ip in ipArr)
{
if (rfidMap.ContainsKey(ip))
{
......@@ -71,10 +71,10 @@ namespace Asa.RFID
/// </summary>
public static void CloseAll()
{
foreach(var rfid in rfidMap.Values)
foreach (var rfid in rfidMap.Values)
{
rfid.StopAutoScan();
}
}
}
}
}
......@@ -15,14 +15,18 @@ namespace OnlineStore.DeviceLibrary
{
public static void Open(string[] iparray)
{
try
Task.Factory.StartNew(delegate
{
RFIDAutoReader.Open(null,iparray);
}
catch (Exception ex)
{
LogUtil.error("Open 出错:" + ex.ToString());
}
LogUtil.info( "RFIDManager.Open");
try
{
RFIDAutoReader.Open(null, iparray);
}
catch (Exception ex)
{
LogUtil.error("Open 出错:" + ex.ToString());
}
});
}
public static RFIDData ReadRFID(string ip, bool isClear = false)
......@@ -60,14 +64,18 @@ namespace OnlineStore.DeviceLibrary
public static void Close()
{
try
Task.Factory.StartNew(delegate
{
RFIDAutoReader.CloseAll();
}
catch (Exception ex)
{
LogUtil.error("关闭RFID出错:" + ex.ToString());
}
LogUtil.info("RFIDManager.Close");
try
{
RFIDAutoReader.CloseAll();
}
catch (Exception ex)
{
LogUtil.error("关闭RFID出错:" + ex.ToString());
}
});
}
}
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!