C#与RFID的初次邂逅
根据自己实际的情况,总结一下经验,不喜勿喷!
- RFID相关实体
using System;
using System.Collections.Generic;
namespace MODEL
{
public class RfidCommon
{
private static Dictionary<string, char> distinctData = new Dictionary<string, char>();
private static object _syncMsg = new object();
public static List<RfidData> handleData(string msg)
{
List<RfidData> list = new List<RfidData>();
string str = "";
lock (_syncMsg)
{
distinctData.Clear();
string[] strs = msg.Split(new string[] {
"\r\n" }, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < strs.Length; i++)
{
if (!string.IsNullOrEmpty(strs[i]))
{
str = strs[i];
if (!str.StartsWith("\0") && !distinctData.ContainsKey(str))
{
distinctData.Add(str, '0');
list.Add(convertToRfidData(str));
}
}
}
}
return list;
}
public static RfidData convertToRfidData(string msg)
{
RfidData m = new RfidData();
int inx = msg.IndexOf(',');
if (inx > 0)
{
m.Data = msg.Substring(0, inx);
m.Port = msg.Substring(inx + 1, msg.Length - inx - 1);
}
else
m.Data = msg;
return m;
}
}
pu