UserControl1.cs
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RFID_Debug
{
public partial class UserControl1 : UserControl
{
private Asa.RFID.HFReader read;
public UserControl1()
{
InitializeComponent();
}
public UserControl1(string ip) : this()
{
CboType.SelectedIndex = 0;
read = new Asa.RFID.HFReader(ip);
read.Received += Read_Received;
read.Open(false);
if (read.IsConn)
{
read.AutoScanMode(false);
groupBox2.Enabled = true;
groupBox3.Enabled = true;
BtnFind.Enabled = true;
}
else
{
groupBox2.Enabled = false;
groupBox3.Enabled = false;
BtnFind.Enabled = false;
LblID.Text = "无法连接";
}
}
private void Read_Received(string ip, byte[] buff)
{
string s = (char)buff[1] + buff[2].ToString();
this.Invoke(new Action(() => { TxtRead.AppendText(s); }));
}
private void BtnFind_Click(object sender, EventArgs e)
{
bool rtn = read.FindRFID();
if (!rtn)
LblID.Text = "无法连接";
else
LblID.Text = "ID: " + read.ID;
}
private void BtnReadAll_Click(object sender, EventArgs e)
{
byte[] bb = read.Read();
if (bb == null)
{
TxtRead.Text = "";
}
else
{
string s = "";
for (int i = 0; i < bb.Length; i++)
s += bb[i].ToString("X2") + " ";
TxtRead.Text = s;
}
}
private void BtnReadOne_Click(object sender, EventArgs e)
{
byte[] bb = read.Read();
if (bb == null)
{
TxtRead.Text = "";
}
else
{
if (bb[0] == 0x5A && bb[5] == 0x4A)
{
TxtRead.Text = ((char)bb[1]).ToString() + bb[2];
}
else
{
TxtRead.Text = "格式不正确";
}
}
}
private void BtnWrite_Click(object sender, EventArgs e)
{
byte[] bb = new byte[8];
bb[0] = 0x5A;
bb[1] = Convert.ToByte(65 + CboType.SelectedIndex);
bb[2] = Convert.ToByte(NudNumber.Value);
bb[5] = 0x4A;
int sum = 0;
for (int i = 0; i < 6; i++)
sum += bb[i];
byte[] cc = BitConverter.GetBytes(sum);
bb[6] = cc[0];
bb[7] = cc[1];
bool rtn = read.Write(bb);
if (rtn)
label3.Text = ((char)bb[1]).ToString() + bb[2] + " OK";
else
label3.Text = "NG";
}
private void BtnNumMinus_Click(object sender, EventArgs e)
{
if (NudNumber.Value > NudNumber.Minimum)
NudNumber.Value--;
}
private void BtnNumAdd_Click(object sender, EventArgs e)
{
if (NudNumber.Value < NudNumber.Maximum)
NudNumber.Value++;
}
private void BtnClose_Click(object sender, EventArgs e)
{
read.Close();
Parent.Parent.Controls.Remove(Parent);
Parent.Dispose();
Dispose();
}
private void button1_Click(object sender, EventArgs e)
{
read.OpenCloseRF(false);
System.Threading.Thread.Sleep(100);
read.OpenCloseRF(true);
}
}
}