⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readersettingsform.cs

📁 RFID Reader SampleCode
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Symbol.RFID;

namespace CS_RFIDSample2
{
	/// <summary>
	/// Summary description for ReaderSettingsForm.
	/// </summary>
	public class ReaderSettingsForm : System.Windows.Forms.Form
	{
		private Reader theReader;
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.CheckBox checkBoxClass0;
		private System.Windows.Forms.CheckBox checkBoxClass0Plus;
		private System.Windows.Forms.CheckBox checkBoxClass1;
		private System.Windows.Forms.CheckBox checkBoxGen2;
		private System.Windows.Forms.Label labelReadAttenuation;
		private System.Windows.Forms.Label labelWriteAttenuation;
		private System.Windows.Forms.NumericUpDown numericUpDown1;
		private System.Windows.Forms.NumericUpDown numericUpDown2;
		private System.Windows.Forms.Button buttonOK;
		private System.Windows.Forms.Label labelTagMask;
		private System.Windows.Forms.TextBox textBoxTagMask;
		private System.Windows.Forms.Panel panel2;
		private System.Windows.Forms.Label label1;
	
		public ReaderSettingsForm(Reader r)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
			theReader = r;
            this.buttonOK.Focus();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			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()
		{
			this.buttonOK = new System.Windows.Forms.Button();
			this.panel1 = new System.Windows.Forms.Panel();
			this.label1 = new System.Windows.Forms.Label();
			this.checkBoxGen2 = new System.Windows.Forms.CheckBox();
			this.checkBoxClass1 = new System.Windows.Forms.CheckBox();
			this.checkBoxClass0Plus = new System.Windows.Forms.CheckBox();
			this.checkBoxClass0 = new System.Windows.Forms.CheckBox();
			this.labelReadAttenuation = new System.Windows.Forms.Label();
			this.labelWriteAttenuation = new System.Windows.Forms.Label();
			this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
			this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
			this.labelTagMask = new System.Windows.Forms.Label();
			this.textBoxTagMask = new System.Windows.Forms.TextBox();
			this.panel2 = new System.Windows.Forms.Panel();
            this.panel1.SuspendLayout();
            this.panel2.SuspendLayout();
            this.SuspendLayout();
			// 
			// buttonOK
			// 
			this.buttonOK.Location = new System.Drawing.Point(72, 248);
            this.buttonOK.Name = "buttonOK";
            this.buttonOK.Size = new System.Drawing.Size(72, 20);
            this.buttonOK.TabIndex = 0;
			this.buttonOK.Text = "OK";
			this.buttonOK.Click += new System.EventHandler(this.buttonOK_Click);
            this.buttonOK.KeyDown += new System.Windows.Forms.KeyEventHandler(this.buttonOK_KeyDown);
			// 
			// panel1
			// 
			this.panel1.BackColor = System.Drawing.Color.DarkGray;
			this.panel1.Controls.Add(this.label1);
			this.panel1.Controls.Add(this.checkBoxGen2);
			this.panel1.Controls.Add(this.checkBoxClass1);
			this.panel1.Controls.Add(this.checkBoxClass0Plus);
			this.panel1.Controls.Add(this.checkBoxClass0);
			this.panel1.Location = new System.Drawing.Point(8, 8);
            this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(224, 80);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 0);
            this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(144, 20);
			this.label1.Text = "Enabled Tag Types";
			// 
			// checkBoxGen2
			// 
			this.checkBoxGen2.Location = new System.Drawing.Point(112, 56);
            this.checkBoxGen2.Name = "checkBoxGen2";
            this.checkBoxGen2.Size = new System.Drawing.Size(100, 20);
            this.checkBoxGen2.TabIndex = 3;
			this.checkBoxGen2.Text = "Gen 2";
			// 
			// checkBoxClass1
			// 
			this.checkBoxClass1.Location = new System.Drawing.Point(8, 56);
            this.checkBoxClass1.Name = "checkBoxClass1";
            this.checkBoxClass1.Size = new System.Drawing.Size(100, 20);
            this.checkBoxClass1.TabIndex = 2;
			this.checkBoxClass1.Text = "Class 1";
			// 
			// checkBoxClass0Plus
			// 
			this.checkBoxClass0Plus.Location = new System.Drawing.Point(112, 32);
            this.checkBoxClass0Plus.Name = "checkBoxClass0Plus";
            this.checkBoxClass0Plus.Size = new System.Drawing.Size(100, 20);
            this.checkBoxClass0Plus.TabIndex = 1;
			this.checkBoxClass0Plus.Text = "Class 0 Plus";
			// 
			// checkBoxClass0
			// 
			this.checkBoxClass0.Location = new System.Drawing.Point(8, 32);
            this.checkBoxClass0.Name = "checkBoxClass0";
            this.checkBoxClass0.Size = new System.Drawing.Size(100, 20);
            this.checkBoxClass0.TabIndex = 0;
			this.checkBoxClass0.Text = "Class 0";
			// 
			// labelReadAttenuation
			// 
			this.labelReadAttenuation.Location = new System.Drawing.Point(8, 104);
            this.labelReadAttenuation.Name = "labelReadAttenuation";
            this.labelReadAttenuation.Size = new System.Drawing.Size(100, 20);
			this.labelReadAttenuation.Text = "Read Attenuation";
			// 
			// labelWriteAttenuation
			// 
			this.labelWriteAttenuation.Location = new System.Drawing.Point(8, 136);
            this.labelWriteAttenuation.Name = "labelWriteAttenuation";
			this.labelWriteAttenuation.Size = new System.Drawing.Size(112, 20);
			this.labelWriteAttenuation.Text = "Write Attenuation";
			// 
			// numericUpDown1
			// 
			this.numericUpDown1.Location = new System.Drawing.Point(128, 104);
            this.numericUpDown1.Maximum = new decimal(new int[] {
																		   255,
																		   0,
																		   0,
																		   0});
            this.numericUpDown1.Name = "numericUpDown1";
            this.numericUpDown1.Size = new System.Drawing.Size(100, 24);
            this.numericUpDown1.TabIndex = 1;
			// 
			// numericUpDown2
			// 
			this.numericUpDown2.Location = new System.Drawing.Point(128, 136);
            this.numericUpDown2.Maximum = new decimal(new int[] {
																		   255,
																		   0,
																		   0,
																		   0});
            this.numericUpDown2.Name = "numericUpDown2";
            this.numericUpDown2.Size = new System.Drawing.Size(100, 24);
            this.numericUpDown2.TabIndex = 2;
			// 
			// labelTagMask
			// 
			this.labelTagMask.Location = new System.Drawing.Point(8, 8);
            this.labelTagMask.Name = "labelTagMask";
			this.labelTagMask.Size = new System.Drawing.Size(72, 20);
			this.labelTagMask.Text = "Tag Mask :";
			// 
			// textBoxTagMask
			// 
			this.textBoxTagMask.Location = new System.Drawing.Point(8, 32);
			this.textBoxTagMask.MaxLength = 100;
            this.textBoxTagMask.Name = "textBoxTagMask";
            this.textBoxTagMask.Size = new System.Drawing.Size(208, 23);
            this.textBoxTagMask.TabIndex = 0;
			this.textBoxTagMask.WordWrap = false;
			// 
			// panel2
			// 
			this.panel2.BackColor = System.Drawing.Color.DarkGray;
			this.panel2.Controls.Add(this.labelTagMask);
			this.panel2.Controls.Add(this.textBoxTagMask);
			this.panel2.Location = new System.Drawing.Point(8, 168);
            this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(224, 64);
			// 
			// ReaderSettingsForm
			// 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
			this.ClientSize = new System.Drawing.Size(240, 288);
			this.ControlBox = false;
            this.Controls.Add(this.panel1);
			this.Controls.Add(this.numericUpDown2);
			this.Controls.Add(this.numericUpDown1);
			this.Controls.Add(this.labelWriteAttenuation);
			this.Controls.Add(this.labelReadAttenuation);
            this.Controls.Add(this.panel2);
			this.Controls.Add(this.buttonOK);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
            this.Name = "ReaderSettingsForm";
			this.Text = "Reader Settings";
            this.KeyUp += new System.Windows.Forms.KeyEventHandler(this.ReaderSettingsForm_KeyUp);
			this.Load += new System.EventHandler(this.ReaderSettingsForm_Load);
            this.panel1.ResumeLayout(false);
            this.panel2.ResumeLayout(false);
            this.ResumeLayout(false);

		}
		#endregion

		private void ReaderSettingsForm_Load(object sender, System.EventArgs e)
		{

			//Initialize 'enabled' check boxes
			this.checkBoxClass0.Checked = this.theReader.Parameters.Class0Tags.Enabled;
			this.checkBoxClass0Plus.Checked = this.theReader.Parameters.Class0PlusTags.Enabled;
			this.checkBoxClass1.Checked = this.theReader.Parameters.Class1Tags.Enabled;
			this.checkBoxGen2.Checked = this.theReader.Parameters.Gen2Tags.Enabled;
			
			//Initialize read attenuation numericUpDown control
			numericUpDown1.Value = theReader.Parameters.ReadAttenuation;
			//Initialize write attenuation numericUpDown control
			numericUpDown2.Value = theReader.Parameters.WriteAttenuation;

			//Display any TagMasks already set
			byte [] mask = theReader.Parameters.Mask.MaskBytes;
			textBoxTagMask.Text = "";

			int byteLength = theReader.Parameters.Mask.BitLength / 8;
			for(int i = 0; i < byteLength ; i++)
			{
				textBoxTagMask.Text += mask[i].ToString("X2");
			}


			//Add event handlers for controls after initializing
			this.checkBoxGen2.CheckStateChanged += new System.EventHandler(this.checkBoxGen2_CheckStateChanged);
            this.checkBoxGen2.KeyDown += new System.Windows.Forms.KeyEventHandler(this.checkBoxGen2_KeyDown);
			this.checkBoxClass1.CheckStateChanged += new System.EventHandler(this.checkBoxClass1_CheckStateChanged);
            this.checkBoxClass1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.checkBoxClass1_KeyDown);
			this.checkBoxClass0Plus.CheckStateChanged += new System.EventHandler(this.checkBoxClass0Plus_CheckStateChanged);
            this.checkBoxClass0Plus.KeyDown += new System.Windows.Forms.KeyEventHandler(this.checkBoxClass0Plus_KeyDown);
			this.checkBoxClass0.CheckStateChanged += new System.EventHandler(this.checkBoxClass0_CheckStateChanged);
            this.checkBoxClass0.KeyDown += new System.Windows.Forms.KeyEventHandler(this.checkBoxClass0_KeyDown);
			this.numericUpDown1.LostFocus += new System.EventHandler(this.numericUpDown1_ValueChanged);
			this.numericUpDown2.LostFocus += new System.EventHandler(this.numericUpDown2_ValueChanged);
			this.textBoxTagMask.LostFocus += new System.EventHandler(this.textBoxTagMask_TextChanged);

		}

		private void checkBoxClass0_CheckStateChanged(object sender, System.EventArgs e)
		{
			this.theReader.Parameters.Class0Tags.Enabled = checkBoxClass0.Checked;		
		}
        private void checkBoxClass0_KeyDown(object sender, KeyEventArgs e)
        {
            // Checks if the key pressed was an enter button (character code 13)
            if (e.KeyValue == (char)13)
            {
                this.checkBoxClass0.Checked = !(this.checkBoxClass0.Checked);
                checkBoxClass0_CheckStateChanged(this, e);
            }
        }

		private void checkBoxClass0Plus_CheckStateChanged(object sender, System.EventArgs e)
		{
			this.theReader.Parameters.Class0PlusTags.Enabled = checkBoxClass0Plus.Checked;
		}
        private void checkBoxClass0Plus_KeyDown(object sender, KeyEventArgs e)
        {
            // Checks if the key pressed was an enter button (character code 13)
            if (e.KeyValue == (char)13)
            {
                this.checkBoxClass0Plus.Checked = !(this.checkBoxClass0Plus.Checked);
                checkBoxClass0Plus_CheckStateChanged(this, e);
            }
        }

		private void checkBoxClass1_CheckStateChanged(object sender, System.EventArgs e)
		{
			this.theReader.Parameters.Class1Tags.Enabled = checkBoxClass1.Checked;
		}
        private void checkBoxClass1_KeyDown(object sender, KeyEventArgs e)
        {
            // Checks if the key pressed was an enter button (character code 13)
            if (e.KeyValue == (char)13)
            {
                this.checkBoxClass1.Checked = !(this.checkBoxClass1.Checked);
                checkBoxClass1_CheckStateChanged(this, e);
            }
        }

		private void checkBoxGen2_CheckStateChanged(object sender, System.EventArgs e)
		{
			this.theReader.Parameters.Gen2Tags.Enabled = checkBoxGen2.Checked;		
		}
        private void checkBoxGen2_KeyDown(object sender, KeyEventArgs e)
        {
            // Checks if the key pressed was an enter button (character code 13)
            if (e.KeyValue == (char)13)
            {
                this.checkBoxGen2.Checked = !(this.checkBoxGen2.Checked);
                checkBoxGen2_CheckStateChanged(this, e);
            }
        }

		private void buttonOK_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}
        private void buttonOK_KeyDown(object sender, KeyEventArgs e)
        {
            // Checks if the key pressed was an enter button (character code 13)
            if (e.KeyValue == (char)13)
                buttonOK_Click(this, e);
        }

        private void ReaderSettingsForm_KeyUp(object sender, KeyEventArgs e)
        {
            this.buttonOK.Focus();
        }

		private void textBoxTagMask_TextChanged(object sender, System.EventArgs e)
		{
			//Take each two bytes and convert to hex bytes to create the mask
			byte [] maskBytes = new byte[textBoxTagMask.Text.Length / 2 ];
			int j = 0;
			for(int i =  0 ; i < textBoxTagMask.Text.Length ; i += 2) 
			{
				string s =  textBoxTagMask.Text[i].ToString() +  textBoxTagMask.Text[i + 1].ToString();
				maskBytes[j] =  byte.Parse(s,System.Globalization.NumberStyles.AllowHexSpecifier);
				j++; 
			}

			theReader.Parameters.Mask = new TagMask((byte) (maskBytes.Length*8) , 0 , maskBytes);
		}

		private void numericUpDown1_ValueChanged(object sender, System.EventArgs e)
		{
			this.theReader.Parameters.ReadAttenuation = (byte) numericUpDown1.Value;
		}

		private void numericUpDown2_ValueChanged(object sender, System.EventArgs e)
		{
			this.theReader.Parameters.WriteAttenuation = (byte) numericUpDown2.Value;		
		}

	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -