-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathForm1.cs
139 lines (123 loc) · 4.8 KB
/
Form1.cs
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using DigitalPlatform;
using DigitalPlatform.IO;
using DigitalPlatform.RFID;
namespace CallRfidCenterSample
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button_tagListForm_Click(object sender, EventArgs e)
{
TagListForm dlg = new TagListForm();
dlg.ShowDialog(this);
}
private void Form1_Load(object sender, EventArgs e)
{
StartRfidManager("ipc://RfidChannel/RfidServer");
}
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
StopRfidManager();
}
CancellationTokenSource _cancelRfidManager = new CancellationTokenSource();
void StartRfidManager(string url)
{
_cancelRfidManager?.Cancel();
_cancelRfidManager = new CancellationTokenSource();
RfidManager.Base.Name = "RFID 中心";
RfidManager.Url = url;
// RfidManager.AntennaList = "1|2|3|4"; // testing
// RfidManager.SetError += RfidManager_SetError;
RfidManager.ListTags += RfidManager_ListTags;
RfidManager.Start(_cancelRfidManager.Token);
}
public static event TagChangedEventHandler TagChanged = null;
public static NewTagList TagList = new NewTagList();
private void RfidManager_ListTags(object sender, ListTagsEventArgs e)
{
// 标签总数显示
if (e.Result.Results != null)
{
TagList.Refresh(
e.ReaderNameList,
e.Result.Results,
(readerName, uid, antennaID, protocol) =>
{
var channel = sender as BaseChannel<IRfid>;
return channel.Object.GetTagInfo(readerName, uid, antennaID);
},
(add_books, update_books, remove_books) =>
{
TagChanged?.Invoke(sender, new TagChangedEventArgs
{
AddBooks = add_books,
UpdateBooks = update_books,
RemoveBooks = remove_books,
});
},
(type, text) =>
{
RfidManager.TriggerSetError(this, new SetErrorEventArgs { Error = text });
// TagSetError?.Invoke(this, new SetErrorEventArgs { Error = text });
});
#if REMOVED
TagList.Refresh(sender as BaseChannel<IRfid>,
e.ReaderNameList,
e.Result.Results,
(add_books, update_books, remove_books, add_patrons, update_patrons, remove_patrons) =>
{
TagChanged?.Invoke(sender, new TagChangedEventArgs
{
AddBooks = add_books,
UpdateBooks = update_books,
RemoveBooks = remove_books,
AddPatrons = add_patrons,
UpdatePatrons = update_patrons,
RemovePatrons = remove_patrons
});
},
(type, text) =>
{
RfidManager.TriggerSetError(this, new SetErrorEventArgs { Error = text });
// TagSetError?.Invoke(this, new SetErrorEventArgs { Error = text });
});
#endif
// 标签总数显示 图书+读者卡
// this.Number = $"{TagList.Books.Count}:{TagList.Patrons.Count}";
}
}
void StopRfidManager()
{
_cancelRfidManager?.Cancel();
RfidManager.Url = "";
RfidManager.ListTags -= RfidManager_ListTags;
}
}
public delegate void TagChangedEventHandler(object sender,
TagChangedEventArgs e);
/// <summary>
/// 设置标签变化事件的参数
/// </summary>
public class TagChangedEventArgs : EventArgs
{
public List<TagAndData> AddBooks { get; set; }
public List<TagAndData> UpdateBooks { get; set; }
public List<TagAndData> RemoveBooks { get; set; }
public List<TagAndData> AddPatrons { get; set; }
public List<TagAndData> UpdatePatrons { get; set; }
public List<TagAndData> RemovePatrons { get; set; }
}
}