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

📄 readerform.cs

📁 Symbol MC3000 Visual C 条码扫码范例程序之1
💻 CS
📖 第 1 页 / 共 2 页
字号:

		/// <summary>
		/// Initialize the Reader parameters
		/// </summary>
		private void InitReadParams()
		{
			this.MyReadParamsList = new object[2];

			/*this.MyReadParamsList[0] = this.MyReader.Changes.Save();

			this.MyReader.Decoders.UPCE1.Enabled = true;
			this.MyReader.Decoders.UPCE1.ConvertToUPCA = true;
			this.MyReader.Decoders.UPCE1.ReportCheckDigit = true;
			this.MyReader.Decoders.UPCE1.Preamble = Symbol.Barcode.UPCE1.Preambles.CountryAndSystem;

			this.MyReader.Decoders.D2OF5.Enabled = true;

			this.MyReader.Parameters.CodeIdType = Symbol.Barcode.CodeIdTypes.Symbol;
			this.MyReader.Parameters.ScanType = Symbol.Barcode.ScanTypes.Background;
			this.MyReader.Parameters.LocalFeedback = Symbol.Barcode.DisabledEnabled.Enabled;

			this.MyReader.UPCEAN.Supplemental2 = Symbol.Barcode.DisabledEnabled.Disabled;

			this.MyReader.Parameters.Feedback.Success.BeepTime = 0;
			this.MyReader.Parameters.Feedback.Success.WaveFile = "\\windows\\alarm3.wav";

			this.MyReadParamsList[1] = this.MyReader.Changes.Save();

			this.CurrentReadParamIndex = 0;*/
		}


		/// <summary>
		/// Application is closing
		/// </summary>
		protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
		{
			// Terminate reader, call base class
			this.TermReader();
			base.OnClosing(e);
		}

		/// <summary>
		/// Stop reading and disable/close reader
		/// </summary>
		private void TermReader()
		{
			// If we have a reader
			if ( this.MyReader != null )
			{
                //Remove Form event handlers
                this.Activated -= MyActivatedEventHandler;
                this.Deactivate -= MyDeactivatedEventHandler;

				// stop all notifications
				this.StopRead();
				this.StopStatus();

				try
				{
					// Disable the reader
					this.MyReader.Actions.Disable();

					// Free it up
					this.MyReader.Dispose();

					// Indicate we no longer have one
					this.MyReader = null;
				}
				catch ( Symbol.Exceptions.InvalidRequestException ex )
				{
					MessageBox.Show("TermReader\n"+"Invalid Operation"+ex.Message);
				}
				catch ( Symbol.Exceptions.OperationFailureException ex )
				{
					MessageBox.Show("TermReader\n"+"Operation Failure\n"+"Result = 0x"+
						((uint)ex.Result).ToString("X8")+"\n"+ex.Message);
				}
				catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
				{
					MessageBox.Show("TermReader\n"+"Unimplemented Function"+ex.Message);
				}
			}

			if ( this.MyReaderData != null )
			{
				// Free it up
				this.MyReaderData.Dispose();

				// Indicate we no longer have one
				this.MyReaderData = null;
			}
		}


		/// <summary>
		/// Start a read on the reader
		/// </summary>
		private void StartRead()
		{
			// If we have both a reader and a reader data
			if ( ( this.MyReader != null ) &&
				( this.MyReaderData != null ) )

				try
				{
					//this.MyReader.Changes.Restore(this.MyReadParamsList[this.CurrentReadParamIndex]);

					if ( ++this.CurrentReadParamIndex >= this.MyReadParamsList.Length )
					{
						this.CurrentReadParamIndex = 0;
					}

					this.MyReader.ReadNotify += MyReadNotifyHandler;

					// Submit a read
					this.MyReader.Actions.Read(this.MyReaderData);
				}
				catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
				{
					MessageBox.Show("StartRead\n" +
						"Unimplemented Function\n" +
						ex.Message);
				}
				catch ( Symbol.Exceptions.InvalidIndexerException ex )
				{
					MessageBox.Show("StartRead\n"+
						"Invalid Indexer\n"+
						ex.Message);
				}
				catch ( Symbol.Exceptions.OperationFailureException ex )
				{
					MessageBox.Show("StopRead\n" +
						"Operation Failure\n" +
						"Result = 0x" +
						((uint)ex.Result).ToString("X8") +
						"\n"+
						ex.Message);
				}
				catch ( Symbol.Exceptions.InvalidRequestException ex )
				{
					MessageBox.Show("StartRead\n"+
						"Invalid Request\n"+
						ex.Message);
				};
		}

		/// <summary>
		/// Stop all reads on the reader
		/// </summary>
		private void StopRead()
		{
			// If we do not have a reader, then do nothing
			if ( this.MyReader == null )
			{
				return;
			}

			try
			{
				// Remove read notification handler
				this.MyReader.ReadNotify -= MyReadNotifyHandler;

				// Flush (Cancel all pending reads)
				this.MyReader.Actions.Flush();
			}
			catch ( Symbol.Exceptions.InvalidRequestException ex )
			{
				MessageBox.Show("StopRead\n"+"Invalid Operation"+ex.Message);
			}
			catch ( Symbol.Exceptions.OperationFailureException ex )
			{
				MessageBox.Show("StopRead\n"+"Operation Failure\n"+"Result = 0x"+
					((uint)ex.Result).ToString("X8")+"\n"+ex.Message);
			}
			catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
			{
				MessageBox.Show("StopRead\n"+"Unimplemented Function\n"+ex.Message);
			}
		}

		/// <summary>
		/// Start status notifications
		/// </summary>
		private void StartStatus()
		{
			if( this.MyReader != null)
			{
				// Attach status notification handler
				this.MyReader.StatusNotify += this.MyStatusNotifyHandler;
			}
		}

		/// <summary>
		/// Stop all status notifications
		/// </summary>
		private void StopStatus()
		{
			if(this.MyReader != null)
			{
				// Detach status notification handler
				this.MyReader.StatusNotify -= this.MyStatusNotifyHandler;
			}
		}

		/// <summary>
        /// Click from the scan button
        /// </summary>
        private void ScanButton_Click(object sender, System.EventArgs e)
        {
            if (this.MyReader == null)
            {
                return;
            }

            this.MyReader.Actions.ToggleSoftTrigger();
        }

		/// <summary>
		/// Click from the about button
		/// </summary>
		private void AboutButton_Click(object sender, System.EventArgs e)
		{
			Symbol.StandardForms.About.Run(
				null,
				"CS_ScanSample2 - Version 1.1.2.1\nC# Scanning Sample 2");
            this.AboutButton.Focus();
		}

        /// <summary>
        /// Click from the View button
        /// </summary>
        private void ViewButton_Click(object sender, System.EventArgs e)
        {
            if (this.MyReader == null)
            {
                return;
            }

            ViewData.Run(this.DataTextBox.Text, this.MyReader);
            this.ViewButton.Focus();
		}

		/// <summary>
		/// Click from the codes button
		/// </summary>
		private void CodesButton_Click(object sender, System.EventArgs e)
		{
			if ( this.MyReader == null )
			{
				return;
			}

			Symbol.StandardForms.EnabledDecoders.Run(this.MyReader);
            this.CodesButton.Focus();
		}

		/// <summary>
		/// Click from the Params button
		/// </summary>
		private void ParamsButton_Click(object sender, System.EventArgs e)
		{
			if ( this.MyReader == null )
			{
				return;
			}

			Symbol.StandardForms.ScanParamsForm.Run(this.MyReader);
            this.ParamsButton.Focus();
		}

		/// <summary>
        /// Click from the close button
		/// </summary>
        private void CloseButton_Click(object sender, System.EventArgs e)
        {
            // Close this form
            this.Close();
        }

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

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

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

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

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

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

        private void ReaderForm_KeyUp(object sender, KeyEventArgs e)
        {
            this.ScanButton.Focus();
		}


		/// <summary>
		/// Status notification handler
		/// </summary>
		private void MyReader_StatusNotify(object Sender,EventArgs e)
		{
			// Get current status  
			Symbol.Barcode.BarcodeStatus TheEvent = this.MyReader.GetNextStatus();

			// Set event text in UI
			this.EventTextBox.Text = TheEvent.Text;
		}

		/// <summary>
		/// Read notification handler
		/// </summary>
		private void MyReader_ReadNotify(object Sender,EventArgs e)
		{
			// Get ReaderData
			Symbol.Barcode.ReaderData TheReaderData = this.MyReader.GetNextReaderData();

			switch(TheReaderData.Result)
			{
				case Symbol.Results.SUCCESS:
					// Handle the data from this read
					this.HandleData(TheReaderData);
					this.StartRead();
					break;

				case Symbol.Results.CANCELED:
					break;

				default:
					string sMsg =	"Read Failed\n"
						+	"Result = "
						+	((int)TheReaderData.Result).ToString("X8");
					MessageBox.Show(sMsg,"ReadNotify");
					break;
			}
		}			

		/// <summary>
		/// Handle data from the reader
		/// </summary>
		private void HandleData(Symbol.Barcode.ReaderData TheReaderData)
		{
			this.DataTextBox.Text = TheReaderData.Text;
			this.TypeTextBox.Text = TheReaderData.TypeHex;
			this.SourceTextBox.Text = TheReaderData.Source;
			this.TimeTextBox.Text = TheReaderData.TimeStamp.ToString();
			this.LengthTextBox.Text = TheReaderData.Length.ToString();
		}

		private void ReaderForm_Activated(object sender, EventArgs e)
		{
			this.StartStatus();

			// If there are no reads pending on MyReaderData start a new read
			if ( !this.MyReaderData.IsPending )
				this.StartRead();
		}

		private void ReaderForm_Deactivate(object sender, EventArgs e)
		{
			this.StopRead();
			this.StopStatus();
		}
	}
}

⌨️ 快捷键说明

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