FrmMain.cs
4.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RFID_Debug
{
public partial class FrmMain : Form
{
private bool[] _open;
private string[] _ip;
private Asa.RFID.HFReader[] reader;
private Asa.RFID.HFReaderAll readerAll;
private int sum = 0;
private string currIP = "";
//private Dictionary<string, string> buffer = new Dictionary<string, string>();
private System.Threading.Thread tSave;
private System.Collections.Concurrent.ConcurrentQueue<string> info = new System.Collections.Concurrent.ConcurrentQueue<string>();
public FrmMain()
{
InitializeComponent();
}
private void FrmMain_Load(object sender, EventArgs e)
{
CboLocal.Items.AddRange(Asa.RFID.IP.GetLocal());
if (CboLocal.Items.Count > 0)
CboLocal.SelectedIndex = 0;
}
private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (tSave != null)
tSave.Abort();
if (reader != null)
{
for (int i = 0; i < reader.Length; i++)
{
reader[i].Close();
System.Threading.Thread.Sleep(10);
}
}
if (readerAll != null)
{
readerAll.Close();
readerAll = null;
}
}
private void BtnGetIP_Click(object sender, EventArgs e)
{
LstIP.Items.Clear();
_ip = Asa.RFID.IP.Find(CboLocal.Text);
LstIP.Items.AddRange(_ip);
_open = new bool[_ip.Length];
}
private void BtnChangeIP_Click(object sender, EventArgs e)
{
if (LstIP.SelectedIndex == -1) return;
bool rtn = Asa.RFID.IP.Modify(CboLocal.Text, LstIP.Text, textBox1.Text);
if (rtn)
MessageBox.Show("修改完成");
else
MessageBox.Show("修改失败", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void BtnOpen_Click(object sender, EventArgs e)
{
if (LstIP.SelectedIndex == -1) return;
//if (_open[LstIP.SelectedIndex]) return;
TabPage tab = new TabPage { Text = LstIP.Text };
UserControl1 ctl = new UserControl1(LstIP.Text);
tab.Controls.Add(ctl);
tabControl1.Controls.Add(tab);
//_open[LstIP.SelectedIndex] = true;
}
private void LstIP_SelectedIndexChanged(object sender, EventArgs e)
{
textBox1.Text = LstIP.Text;
}
private void button1_Click(object sender, EventArgs e)
{
string[] ip = new string[LstIP.Items.Count];
for (int i = 0; i < ip.Length; i++)
ip[i] = LstIP.Items[i].ToString();
readerAll = new Asa.RFID.HFReaderAll();
readerAll.LogPath = Application.StartupPath;
readerAll.GetValue += Ra_GetValue;
readerAll.Open(ip);
//readerAll.Open("192.168.210.114", "192.168.210.117");
}
private void Ra_GetValue(string s)
{
Invoke(new Action(() =>
{
if (s.Contains(LstIP.Items[0].ToString()))
textBox2.AppendText("======\r\n");
textBox2.AppendText(s + "\r\n");
}));
}
private void Reader_Received(string ip, byte[] buff)
{
try
{
//string val = (char)buff[1] + buff[2].ToString();
//if (ip == currIP) return;
//currIP = ip;
//string s = "";
//if (ip == LstIP.Items[0].ToString())
//{
// s = "========== ";
// sum = 0;
//}
//s += (++sum) + " " + ip + " ";
//s += val;
//info.Enqueue(s);
string s = "";
for (int i = 0; i < buff.Length; i++)
s += buff[i].ToString("X2") + " ";
Invoke(new Action(() => { textBox2.AppendText(s); }));
}
catch (Exception)
{ }
}
private void SaveLog()
{
string _logFile = string.Format("{0}\\RFID_{1:yyyy-MM-dd}.log", Application.StartupPath, DateTime.Now);
while (true)
{
System.Threading.Thread.Sleep(100);
if (info.TryDequeue(out string result))
System.IO.File.AppendAllText(_logFile, string.Format("[{0:HH:mm:ss.fff}] {1}\r\n", DateTime.Now, result), Encoding.UTF8);
}
}
}
}