|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using Mesnac.Communication;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using Mesnac.Compressor.Entity;
|
|
|
|
|
|
|
|
|
|
namespace SocketProcess
|
|
|
|
|
{
|
|
|
|
|
public class SocketHandler
|
|
|
|
|
{
|
|
|
|
|
public EventHandler MesRecieved;
|
|
|
|
|
|
|
|
|
|
public SocketHandler()
|
|
|
|
|
{
|
|
|
|
|
SocketClient.Instance.OnMsgReceived += RecieveDataHandle;
|
|
|
|
|
this.Connect("");
|
|
|
|
|
//SocketClient.Instance.OnSended += SendDataDelegate;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RecieveDataHandle(string Msg)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//Console.WriteLine("数据读取:"+Msg);
|
|
|
|
|
DataHandler dhb = new DataHandler();
|
|
|
|
|
dhb.recieveEvent += MegSave;
|
|
|
|
|
ThreadPool.QueueUserWorkItem(new WaitCallback(dhb.DataAnylysis), Msg);
|
|
|
|
|
}
|
|
|
|
|
private void MegSave(FrameFormat frame)
|
|
|
|
|
{
|
|
|
|
|
if (frame.CompleteFlag)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
if (frame.Type == "BB")
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("解析成功,正在添加" + frame.data.Epc);
|
|
|
|
|
foreach (Station tl in TrayFactory.Instance.StationList)
|
|
|
|
|
{
|
|
|
|
|
if (tl.Ant == frame.data.ANT && tl.IP == frame.data.IP)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("比对成功,插入队列" + frame.data.Epc);
|
|
|
|
|
tl.InsertQueue(frame.data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//处理返回信息
|
|
|
|
|
SocketReturn(frame);
|
|
|
|
|
//界面处理函数
|
|
|
|
|
if (MesRecieved != null)
|
|
|
|
|
{
|
|
|
|
|
MesRecieved(null, null);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private void SocketReturn(FrameFormat frame)
|
|
|
|
|
{
|
|
|
|
|
int type=Convert.ToInt32(frame.Type,16);
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case (int)RfidWorkType.setAutoUp:
|
|
|
|
|
//返回此EPC不用再上传
|
|
|
|
|
DataHandler dh = new DataHandler();
|
|
|
|
|
string typed = "AC";
|
|
|
|
|
string flatEpc = dh.FrameConbine(frame.data, typed);
|
|
|
|
|
Console.WriteLine("返回EPC过滤信息:" + flatEpc);
|
|
|
|
|
Send(flatEpc);
|
|
|
|
|
break;
|
|
|
|
|
case (int)RfidWorkType.setFlatEpcReturn:
|
|
|
|
|
//这个不用管吧
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
//只要不是这两种模式,就设置为自动上报模式
|
|
|
|
|
string autoMode="A5 5a 00 09 AA 00 A3 0D 0A";
|
|
|
|
|
Send(autoMode);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SendDataDelegate(bool sendSuccess)
|
|
|
|
|
{
|
|
|
|
|
if (sendSuccess)
|
|
|
|
|
{
|
|
|
|
|
//MessageBox.Show("发送成功");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 发送数据
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="Msg"></param>
|
|
|
|
|
public void Send(string Msg)
|
|
|
|
|
{
|
|
|
|
|
SocketClient.Instance.Send(Msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 连接
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void Connect(object o)
|
|
|
|
|
{
|
|
|
|
|
SocketClient.Instance.Connect();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 断开连接
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void DisConnect()
|
|
|
|
|
{
|
|
|
|
|
SocketClient.Instance.Disconnect();
|
|
|
|
|
SocketClient.Instance.StopListenThread();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|