基本信息
源码名称:RFID 标签读写
源码大小:1.49M
文件格式:.rar
开发语言:C#
更新时间:2019-07-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 3 元×
微信扫码支付:3 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
本实例可用于读写RFID标签
{
if ((text_readadr.Text.Length != 4) || (text_readLen.Text.Length != 2) || (text_readpsd.Text.Length != 8))
{
MessageBox.Show("混合查询条件错误!!!");
return;
}
if (btIventoryG2.Text == "开始询查")
{
if (rb_mix.Checked)
{
ReadMem = (byte)com_MixMem.SelectedIndex;
ReadAdr = HexStringToByteArray(text_readadr.Text);
ReadLen = Convert.ToByte(text_readLen.Text, 16);
Psd = HexStringToByteArray(text_readpsd.Text);
}
lxLedControl1.Text = "0";
lxLedControl2.Text = "0";
lxLedControl3.Text = "0";
lxLedControl4.Text = "0";
lxLedControl5.Text = "0";
lxLedControl6.Text = "0";
epclist.Clear();
tidlist.Clear();
dataGridView1.DataSource = null;
lrtxtLog.Clear();
comboBox_EPC.Items.Clear();
text_epc.Text = "";
AA_times = 0;
Scantime = Convert.ToByte(com_scantime.SelectedIndex);
if (checkBox_rate.Checked)
Qvalue = Convert.ToByte(com_Q.SelectedIndex | 0x80);
else
Qvalue = Convert.ToByte(com_Q.SelectedIndex);
Session = Convert.ToByte(com_S.SelectedIndex);
if (Session == 4)
Session = 255;
if (rb_epc.Checked)
{
TIDFlag = 0;
}
else if (rb_fastid.Checked)
{
TIDFlag = 0;
Qvalue = Convert.ToByte(com_Q.SelectedIndex | 0x20);
}
else
{
TIDFlag = 1;
}
total_turns = 0;
total_tagnum = 0;
targettimes = Convert.ToInt32(text_target.Text);
total_time = System.Environment.TickCount;
fIsInventoryScan = false;
btIventoryG2.BackColor = Color.Indigo;
btIventoryG2.Text = "停止";
Array.Clear(antlist, 0, 4);
if (check_ant1.Checked)
{
antlist[0] = 1;
InAnt = 0x80;
}
if (check_ant2.Checked)
{
antlist[1] = 1;
InAnt = 0x81;
}
if (check_ant3.Checked)
{
antlist[2] = 1;
InAnt = 0x82;
}
if (check_ant4.Checked)
{
antlist[3] = 1;
InAnt = 0x83;
}
Target = (byte)com_Target.SelectedIndex;
toStopThread = false;
if (fIsInventoryScan == false)
{
mythread = new Thread(new ThreadStart(inventory));
mythread.IsBackground = true;
mythread.Start();
timer_answer.Enabled = true;
}
rb_mix.Enabled = false;
rb_epc.Enabled = false;
rb_tid.Enabled = false;
rb_fastid.Enabled = false;
}
else
{
toStopThread = true;
btIventoryG2.Enabled = false;
btIventoryG2.BackColor = Color.Transparent;
btIventoryG2.Text = "停止中";
}
}
#region ///EPC或TID查询
private void flash_G2()
{
byte Ant = 0;
int TagNum = 0;
int Totallen = 0;
int EPClen, m;
byte[] EPC = new byte[50000];
int CardIndex;
string temps, temp;
temp = "";
string sEPC;
byte MaskMem = 0;
byte[] MaskAdr = new byte[2];
byte MaskLen = 0;
byte[] MaskData = new byte[100];
byte MaskFlag = 0;
byte AdrTID = 0;
byte LenTID = 0;
AdrTID = 0;
LenTID = 6;
MaskFlag = 0;
int cbtime = System.Environment.TickCount;
CardNum = 0;
fCmdRet = RWDev.Inventory_G2(ref fComAdr, Qvalue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, Target, InAnt, Scantime, FastFlag, EPC, ref Ant, ref Totallen, ref TagNum, frmcomportindex);
int cmdTime = System.Environment.TickCount - cbtime;//命令时间
if ((fCmdRet == 0x30) || (fCmdRet == 0x37))
{
if (rb_tcp.Checked)
{
if ((frmcomportindex > 0) && (frmcomportindex<256))
{
fCmdRet = RWDev.CloseNetPort(frmcomportindex);
if (fCmdRet == 0) frmcomportindex = -1;
Thread.Sleep(1000);
}
fComAdr = 255;
string ipAddress = ipServerIP.IpAddressStr;
int nPort = Convert.ToInt32(tb_Port.Text);
fCmdRet = RWDev.OpenNetPort(nPort, ipAddress, ref fComAdr, ref frmcomportindex);
}
}
if (fCmdRet==0x30)
{
CardNum=0;
}
if (CardNum == 0)
{
if (Session > 1)
AA_times = AA_times 1;//没有得到标签只更新状态栏
}
else
AA_times = 0;
if ((fCmdRet == 1) || (fCmdRet == 2) || (fCmdRet == 0xFB) || (fCmdRet==0x26))
{
if (cmdTime > CommunicationTime)
cmdTime = cmdTime - CommunicationTime;//减去通讯时间等于标签的实际时间
if(cmdTime>0)
{
int tagrate = (CardNum * 1000) / cmdTime;//速度等于张数/时间
IntPtr ptrWnd = IntPtr.Zero;
ptrWnd = FindWindow(null, "UHFReader288 Demo V2.0");
if (ptrWnd != IntPtr.Zero) // 检查当前统计窗口是否打开
{
string para = tagrate.ToString() "," total_tagnum.ToString() "," cmdTime.ToString();
SendMessage(ptrWnd, WM_SENDTAGSTAT, IntPtr.Zero, para);
}
}
}
IntPtr ptrWnd1 = IntPtr.Zero;
ptrWnd1 = FindWindow(null, "UHFReader288 Demo V2.0");
if (ptrWnd1 != IntPtr.Zero) // 检查当前统计窗口是否打开
{
string para = fCmdRet.ToString();
SendMessage(ptrWnd1, WM_SENDSTATU, IntPtr.Zero, para);
}
ptrWnd1 = IntPtr.Zero;
}
#endregion
本实例可用于读写RFID标签
private void btIventoryG2_Click(object sender, EventArgs e)
{
if ((text_readadr.Text.Length != 4) || (text_readLen.Text.Length != 2) || (text_readpsd.Text.Length != 8))
{
MessageBox.Show("混合查询条件错误!!!");
return;
}
if (btIventoryG2.Text == "开始询查")
{
if (rb_mix.Checked)
{
ReadMem = (byte)com_MixMem.SelectedIndex;
ReadAdr = HexStringToByteArray(text_readadr.Text);
ReadLen = Convert.ToByte(text_readLen.Text, 16);
Psd = HexStringToByteArray(text_readpsd.Text);
}
lxLedControl1.Text = "0";
lxLedControl2.Text = "0";
lxLedControl3.Text = "0";
lxLedControl4.Text = "0";
lxLedControl5.Text = "0";
lxLedControl6.Text = "0";
epclist.Clear();
tidlist.Clear();
dataGridView1.DataSource = null;
lrtxtLog.Clear();
comboBox_EPC.Items.Clear();
text_epc.Text = "";
AA_times = 0;
Scantime = Convert.ToByte(com_scantime.SelectedIndex);
if (checkBox_rate.Checked)
Qvalue = Convert.ToByte(com_Q.SelectedIndex | 0x80);
else
Qvalue = Convert.ToByte(com_Q.SelectedIndex);
Session = Convert.ToByte(com_S.SelectedIndex);
if (Session == 4)
Session = 255;
if (rb_epc.Checked)
{
TIDFlag = 0;
}
else if (rb_fastid.Checked)
{
TIDFlag = 0;
Qvalue = Convert.ToByte(com_Q.SelectedIndex | 0x20);
}
else
{
TIDFlag = 1;
}
total_turns = 0;
total_tagnum = 0;
targettimes = Convert.ToInt32(text_target.Text);
total_time = System.Environment.TickCount;
fIsInventoryScan = false;
btIventoryG2.BackColor = Color.Indigo;
btIventoryG2.Text = "停止";
Array.Clear(antlist, 0, 4);
if (check_ant1.Checked)
{
antlist[0] = 1;
InAnt = 0x80;
}
if (check_ant2.Checked)
{
antlist[1] = 1;
InAnt = 0x81;
}
if (check_ant3.Checked)
{
antlist[2] = 1;
InAnt = 0x82;
}
if (check_ant4.Checked)
{
antlist[3] = 1;
InAnt = 0x83;
}
Target = (byte)com_Target.SelectedIndex;
toStopThread = false;
if (fIsInventoryScan == false)
{
mythread = new Thread(new ThreadStart(inventory));
mythread.IsBackground = true;
mythread.Start();
timer_answer.Enabled = true;
}
rb_mix.Enabled = false;
rb_epc.Enabled = false;
rb_tid.Enabled = false;
rb_fastid.Enabled = false;
}
else
{
toStopThread = true;
btIventoryG2.Enabled = false;
btIventoryG2.BackColor = Color.Transparent;
btIventoryG2.Text = "停止中";
}
}
#region ///EPC或TID查询
private void flash_G2()
{
byte Ant = 0;
int TagNum = 0;
int Totallen = 0;
int EPClen, m;
byte[] EPC = new byte[50000];
int CardIndex;
string temps, temp;
temp = "";
string sEPC;
byte MaskMem = 0;
byte[] MaskAdr = new byte[2];
byte MaskLen = 0;
byte[] MaskData = new byte[100];
byte MaskFlag = 0;
byte AdrTID = 0;
byte LenTID = 0;
AdrTID = 0;
LenTID = 6;
MaskFlag = 0;
int cbtime = System.Environment.TickCount;
CardNum = 0;
fCmdRet = RWDev.Inventory_G2(ref fComAdr, Qvalue, Session, MaskMem, MaskAdr, MaskLen, MaskData, MaskFlag, AdrTID, LenTID, TIDFlag, Target, InAnt, Scantime, FastFlag, EPC, ref Ant, ref Totallen, ref TagNum, frmcomportindex);
int cmdTime = System.Environment.TickCount - cbtime;//命令时间
if ((fCmdRet == 0x30) || (fCmdRet == 0x37))
{
if (rb_tcp.Checked)
{
if ((frmcomportindex > 0) && (frmcomportindex<256))
{
fCmdRet = RWDev.CloseNetPort(frmcomportindex);
if (fCmdRet == 0) frmcomportindex = -1;
Thread.Sleep(1000);
}
fComAdr = 255;
string ipAddress = ipServerIP.IpAddressStr;
int nPort = Convert.ToInt32(tb_Port.Text);
fCmdRet = RWDev.OpenNetPort(nPort, ipAddress, ref fComAdr, ref frmcomportindex);
}
}
if (fCmdRet==0x30)
{
CardNum=0;
}
if (CardNum == 0)
{
if (Session > 1)
AA_times = AA_times 1;//没有得到标签只更新状态栏
}
else
AA_times = 0;
if ((fCmdRet == 1) || (fCmdRet == 2) || (fCmdRet == 0xFB) || (fCmdRet==0x26))
{
if (cmdTime > CommunicationTime)
cmdTime = cmdTime - CommunicationTime;//减去通讯时间等于标签的实际时间
if(cmdTime>0)
{
int tagrate = (CardNum * 1000) / cmdTime;//速度等于张数/时间
IntPtr ptrWnd = IntPtr.Zero;
ptrWnd = FindWindow(null, "UHFReader288 Demo V2.0");
if (ptrWnd != IntPtr.Zero) // 检查当前统计窗口是否打开
{
string para = tagrate.ToString() "," total_tagnum.ToString() "," cmdTime.ToString();
SendMessage(ptrWnd, WM_SENDTAGSTAT, IntPtr.Zero, para);
}
}
}
IntPtr ptrWnd1 = IntPtr.Zero;
ptrWnd1 = FindWindow(null, "UHFReader288 Demo V2.0");
if (ptrWnd1 != IntPtr.Zero) // 检查当前统计窗口是否打开
{
string para = fCmdRet.ToString();
SendMessage(ptrWnd1, WM_SENDSTATU, IntPtr.Zero, para);
}
ptrWnd1 = IntPtr.Zero;
}
#endregion