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

📄 form1.cs

📁 SDKs-And-Demos-CS.NET-2.1.1b10 Graba的sdk
💻 CS
字号:
using GrabbaDotNet;
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace Barcode_Demo_CSharp
{

	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button triggerBtn;
		private System.Windows.Forms.Button clearBtn;
		private System.Windows.Forms.Button enableBtn;
        private Button ser;
	
		Grabba myGrabba;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			myGrabba = new Grabba();

			if (myGrabba.Open() != myGrabba.errNone) 
			{
				//problem opening grabba
			}

			Grabba.GrabbaModelType myGrabbaModel = new Grabba.GrabbaModelType();
			myGrabba.GetModel(ref myGrabbaModel);
           
            // check that the barcode device was detected as a T-3300 / T-4300
			if (!(myGrabbaModel.barcodeDevice.Equals(Grabba.BarcodeDeviceEnum.barcodeTx3xx)))
			{
				// failure do something here since it wasnt detected properly
			}

            // add event handler
            Grabba.GrabbaBarcodeTimeoutEvent += new EventHandler(onBarcodeTimeoutEvent);
            Grabba.GrabbaBarcodeEvent += new EventHandler(onBarcodeEvent);
            Grabba.GrabbaDisconnectedEvent += new EventHandler(onGrabbaDisconnectedEvent);
            Grabba.GrabbaReconnectedEvent += new EventHandler(onGrabbaReconnectedEvent);
		}
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			myGrabba.Close();
			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.textBox1 = new System.Windows.Forms.TextBox();
            this.enableBtn = new System.Windows.Forms.Button();
            this.triggerBtn = new System.Windows.Forms.Button();
            this.clearBtn = new System.Windows.Forms.Button();
            this.ser = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.AcceptsReturn = true;
            this.textBox1.Location = new System.Drawing.Point(8, 48);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(192, 168);
            this.textBox1.TabIndex = 3;
            // 
            // enableBtn
            // 
            this.enableBtn.Location = new System.Drawing.Point(8, 16);
            this.enableBtn.Name = "enableBtn";
            this.enableBtn.Size = new System.Drawing.Size(96, 24);
            this.enableBtn.TabIndex = 2;
            this.enableBtn.Text = "Enable";
            this.enableBtn.Click += new System.EventHandler(this.enableBtn_Click);
            // 
            // triggerBtn
            // 
            this.triggerBtn.Location = new System.Drawing.Point(144, 16);
            this.triggerBtn.Name = "triggerBtn";
            this.triggerBtn.Size = new System.Drawing.Size(56, 24);
            this.triggerBtn.TabIndex = 1;
            this.triggerBtn.Text = "Trigger";
            this.triggerBtn.Click += new System.EventHandler(this.triggerBtn_Click);
            // 
            // clearBtn
            // 
            this.clearBtn.Location = new System.Drawing.Point(152, 224);
            this.clearBtn.Name = "clearBtn";
            this.clearBtn.Size = new System.Drawing.Size(48, 24);
            this.clearBtn.TabIndex = 0;
            this.clearBtn.Text = "Clear";
            this.clearBtn.Click += new System.EventHandler(this.clearBtn_Click);
            // 
            // ser
            // 
            this.ser.Location = new System.Drawing.Point(6, 222);
            this.ser.Name = "ser";
            this.ser.Size = new System.Drawing.Size(97, 25);
            this.ser.TabIndex = 4;
            this.ser.Text = "Serial";
            this.ser.Click += new System.EventHandler(this.ser_Click);
            // 
            // Form1
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
            this.ClientSize = new System.Drawing.Size(212, 272);
            this.Controls.Add(this.ser);
            this.Controls.Add(this.clearBtn);
            this.Controls.Add(this.triggerBtn);
            this.Controls.Add(this.enableBtn);
            this.Controls.Add(this.textBox1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>

		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void triggerBtn_Click(object sender, System.EventArgs e)
		{
			myGrabba.BarcodeTrigger(true);		
		}

		private void clearBtn_Click(object sender, System.EventArgs e)
		{
			textBox1.Text = "";
		}

        private void onBarcodeTimeoutEvent(object sender, System.EventArgs e)
        {
            textBox1.Text += "Barcode Timed Out!\r\n";
        }

        private void onGrabbaReconnectedEvent(object sender, System.EventArgs e)
        {
            textBox1.Text += "Grabba Reconnected!\r\n";
        }

        private void onGrabbaDisconnectedEvent(object sender, System.EventArgs e)
        {
            textBox1.Text += "Grabba Disconnected!\r\n";
        }

		private void onBarcodeEvent(object sender, System.EventArgs e)
		{
			textBox1.Text += myGrabba.BarcodeGetDataBarcode();
            textBox1.Text += "\r\n";
			// can do something with myGrabba.BarcodeGetDataSymbology
			// if you want to do something with it.
		}

		private void enableBtn_Click(object sender, System.EventArgs e)
		{
			if (enableBtn.Text.Equals("Enable")) 
			{
				myGrabba.BarcodeEnable();
				enableBtn.Text = "Disable";
			} 
			else 
			{
				myGrabba.BarcodeDisable();
				enableBtn.Text = "Enable";
			}
		}

        private void ser_Click(object sender, EventArgs e)
        {
            string serial = null;
            uint err = myGrabba.GetSerialNumber(ref serial);
            textBox1.Text += serial;
            textBox1.Text += "\r\n";
        }
	}
}

⌨️ 快捷键说明

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