Commit 20bd3981 by 施晓雨

加入写卡窗口测试

parent 2f68f37a
......@@ -40,6 +40,7 @@
this.btnDisconnect = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnInstallDriver = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.panel1.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
......@@ -75,6 +76,7 @@
//
// panel1
//
this.panel1.Controls.Add(this.button1);
this.panel1.Controls.Add(this.btnInstallDriver);
this.panel1.Controls.Add(this.btnListen);
this.panel1.Controls.Add(this.tbxEPC);
......@@ -169,6 +171,16 @@
this.btnInstallDriver.UseVisualStyleBackColor = true;
this.btnInstallDriver.Click += new System.EventHandler(this.btnInstallDriver_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(123, 424);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 10;
this.button1.Text = "写EPC窗口";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// FrmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
......@@ -200,5 +212,6 @@
private System.Windows.Forms.TextBox tbxEPC;
private System.Windows.Forms.Button btnListen;
private System.Windows.Forms.Button btnInstallDriver;
private System.Windows.Forms.Button button1;
}
}
\ No newline at end of file
using Kivii.Rfid.D500;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Test
......@@ -157,5 +151,13 @@ namespace Test
Reader.InstallDriver();
}
private void button1_Click(object sender, EventArgs e)
{
var writingForm = new RFIDWritering(tbxEPC.Text);
writingForm.WaitTimes = 1000;
writingForm.WriteTimes = 1;
writingForm.ShowDialog();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using Kivii.Rfid.D500;
namespace Test
{
internal partial class RFIDWritering : Form
{
#region 属性
private Reader _reader = new Reader();
public string EPC = "";
public string Title = "等待写卡";
/// <summary>
/// 写卡计时器
/// </summary>
System.Timers.Timer _tmr = new System.Timers.Timer();
/// <summary>
/// 写卡次数,超过一定次数,退出
/// </summary>
private int _waitTimes = 0;
/// <summary>
/// 等待写空卡次数,超过就跳出
/// </summary>
public int WaitTimes { get; set; }
private int _writeTimes = 0;
/// <summary>
/// 写卡次数
/// </summary>
public int WriteTimes { get; set; }
/// <summary>
/// 写卡密码
/// </summary>
public string AccessPassword { get; set; }
private ProgramEpcParams _accessd = null;
private ProgramEpcParams accessd
{
get
{
if (_accessd != null) return _accessd;
_accessd = new ProgramEpcParams();
_accessd.NewEpc = EPC;
_accessd.AntennaPortNumber = 0;
_accessd.AccessPassword = AccessPassword;
return _accessd;
}
}
#endregion
public RFIDWritering(string epc)
{
EPC = epc;
InitializeComponent();
}
private void RFIDWritering_Load(object sender, EventArgs e)
{
_tmr.Interval = 500;
_tmr.Elapsed += new System.Timers.ElapsedEventHandler(tmr_Elapsed);
_reader.Connected += new EventHandler<ConnectionChangedEventArgs>(reader_Connected);
lblMsg.Text = "初始化中";
lblOutput.Text = "等待连接RFID终端...";
List<string> readers = _reader.GetReaderList();
if (readers.Count <= 0)
{
lblMsg.Text = "初始化失败";
lblMsg.ForeColor = Color.Red;
lblOutput.Text = "未能连接RFID读写终端,请检查连接线!";
return;
}
else
{
lblOutput.Text = "正在连接RFID读写终端...";
_reader.Connect(readers[0]);
}
}
void reader_Connected(object sender, ConnectionChangedEventArgs e)
{
this.Invoke(new Action(delegate()
{
lblMsg.Text = Title;
lblOutput.Text = "连接RFID读写终端成功,等待放入RFID卡片...";
}));
_tmr.Start();
}
void tmr_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
_tmr.Stop();
this.Invoke(new Action(delegate() { lblMsg.ForeColor = lblMsg.ForeColor == Color.Black ? Color.Red : Color.Black; }));
_waitTimes += 1;
if (_waitTimes > WaitTimes || _writeTimes >= WriteTimes)
{
this.Invoke(new Action(delegate()
{
lblOutput.Text = "等待退出程序,关闭RFID读写终端连接中...";
this.Close();
}));
return;
}
ProgramEpcResult result = _reader.ProgramEpc(accessd);
if (result.WriteResult.Result == AccessResult.Success)
{
this.Invoke(new Action(delegate()
{
lblOutput.Text = "写入数据成功,正在验证写入结果...";
lblOutput.ForeColor = Color.Green;
}));
Thread.Sleep(100);
ReadEpcResult writeResult = _reader.ReadEpc();
if (writeResult.ReadResult.Result!=AccessResult.Success||writeResult.TagAccessed.Epc.ToLower() != EPC.ToLower())
{
this.Invoke(new Action(delegate()
{
lblOutput.Text = DateTime.Now.ToString("[HH:mm:ss]") + "写入数据失败,尝试重写数据中...";
lblOutput.ForeColor = Color.Red;
}));
throw new Exception();
}
_waitTimes = 0;
_writeTimes += 1;
this.Invoke(new Action(delegate()
{
lblOutput.Text = "验证写入数据成功...";
lblOutput.ForeColor = Color.Blue;
}));
Thread.Sleep(200);
this.Invoke(new Action(delegate()
{
lblOutput.Text = "等待放入RFID卡片...";
lblOutput.ForeColor = Color.Black;
}));
}
else
{
this.Invoke(new Action(delegate()
{
lblOutput.Text = "等待放入RFID卡片...";
lblOutput.ForeColor = Color.Black;
}));
}
}
catch
{
}
finally
{
}
GC.Collect();
if(_tmr!=null)_tmr.Start();
}
protected override void OnClosing(CancelEventArgs e)
{
try
{
_tmr.Elapsed -= new System.Timers.ElapsedEventHandler(tmr_Elapsed);
_reader.Connected -= new EventHandler<ConnectionChangedEventArgs>(reader_Connected);
_tmr.Stop();
_tmr.Dispose();
_reader.DisConnect();
_reader = null;
}
catch { }
base.OnClosing(e);
}
}
}
namespace Test
{
partial class RFIDWritering
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(RFIDWritering));
this.lblOutput = new System.Windows.Forms.Label();
this.lblMsg = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblOutput
//
this.lblOutput.Dock = System.Windows.Forms.DockStyle.Bottom;
this.lblOutput.Location = new System.Drawing.Point(0, 172);
this.lblOutput.Name = "lblOutput";
this.lblOutput.Size = new System.Drawing.Size(430, 22);
this.lblOutput.TabIndex = 2;
//
// lblMsg
//
this.lblMsg.Dock = System.Windows.Forms.DockStyle.Fill;
this.lblMsg.Font = new System.Drawing.Font("宋体", 35F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.lblMsg.Location = new System.Drawing.Point(0, 0);
this.lblMsg.Name = "lblMsg";
this.lblMsg.Size = new System.Drawing.Size(430, 172);
this.lblMsg.TabIndex = 3;
this.lblMsg.Text = "等待写卡";
this.lblMsg.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// RFIDWritering
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(430, 194);
this.Controls.Add(this.lblMsg);
this.Controls.Add(this.lblOutput);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "RFIDWritering";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "RFID写卡";
this.Load += new System.EventHandler(this.RFIDWritering_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Label lblOutput;
private System.Windows.Forms.Label lblMsg;
}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -55,6 +55,12 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RFIDWritering.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="RFIDWritering.designer.cs">
<DependentUpon>RFIDWritering.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="FrmMain.resx">
<DependentUpon>FrmMain.cs</DependentUpon>
</EmbeddedResource>
......@@ -67,6 +73,9 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<EmbeddedResource Include="RFIDWritering.resx">
<DependentUpon>RFIDWritering.cs</DependentUpon>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment