BarCode Reader

Trying to learn how to program a BarCode Scanner

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 53799 Views - Last Post: 23 July 2011 - 04:25 AM Rate Topic: -----

#1 MTown  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 10-December 08

BarCode Reader

Post icon  Posted 10 December 2008 - 09:09 AM

Hello, this is my first time on this forum, so I would like to thank everyone in advance for any help you can provide. I am trying to learn how to develop a very simple application on a Handheld barcode Scanner. All I am looking to do is read a barcode, and pull data from a table in SQL Server. I have downloaded a couple of different developer kits, and the samples have not gotten me any where. Below is the code from my last attempt. Does anyone have or know where I could get a very simple example of coding a BarCode Reader in VB .Net? Again any help anyone can provide would be greatly appreciated.
Imports System
Imports System.Windows.Forms

Public Class ReaderForm

	Inherits System.Windows.Forms.Form

	Private Sub InitializeComponent()
		Me.ScanButton = New System.Windows.Forms.Button
		Me.DataLabel = New System.Windows.Forms.Label
		Me.DataTextBox = New System.Windows.Forms.TextBox
		Me.CloseButton = New System.Windows.Forms.Button
		Me.SuspendLayout()
		'
		'ScanButton
		'
		Me.ScanButton.Location = New System.Drawing.Point(8, 208)
		Me.ScanButton.Name = "ScanButton"
		Me.ScanButton.Size = New System.Drawing.Size(64, 25)
		Me.ScanButton.TabIndex = 0
		Me.ScanButton.Text = "Scan"
		'
		'DataLabel
		'
		Me.DataLabel.Location = New System.Drawing.Point(8, 16)
		Me.DataLabel.Name = "DataLabel"
		Me.DataLabel.Size = New System.Drawing.Size(72, 21)
		Me.DataLabel.Text = "Data:"
		'
		'DataTextBox
		'
		Me.DataTextBox.Location = New System.Drawing.Point(80, 16)
		Me.DataTextBox.Name = "DataTextBox"
		Me.DataTextBox.Size = New System.Drawing.Size(152, 23)
		Me.DataTextBox.TabIndex = 6
		'
		'CloseButton
		'
		Me.CloseButton.Location = New System.Drawing.Point(168, 208)
		Me.CloseButton.Name = "CloseButton"
		Me.CloseButton.Size = New System.Drawing.Size(64, 25)
		Me.CloseButton.TabIndex = 5
		Me.CloseButton.Text = "Exit"
		'
		'
		'ReaderForm
		'
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit
		Me.BackColor = System.Drawing.Color.White
		Me.ClientSize = New System.Drawing.Size(240, 270)
		Me.Controls.Add(Me.ScanButton)
		Me.Controls.Add(Me.DataLabel)
		Me.Controls.Add(Me.DataTextBox)
		Me.Controls.Add(Me.CloseButton)
		Me.Name = "ReaderForm"
		Me.Text = "MP2"
		Me.ResumeLayout(False)
	End Sub
	Public Shared Sub Main()
		Application.Run(New ReaderForm)
	End Sub
	Private MyReader As Symbol.Barcode.Reader = Nothing
	Private MyReaderData As Symbol.Barcode.ReaderData = Nothing
	Private MyReadNotifyHander As System.EventHandler = Nothing
	Private MyStatusNotifyHandler As System.EventHandler = Nothing
	Private MyActivateHandler As System.EventHandler = Nothing
	Private MyDeActivateHandler As System.EventHandler = Nothing

	'This function scales down the given Form & its child controls in order to
	'make them completely viewable, based on the screen width & height.
	Public Sub ScaleDown(ByVal frm As System.Windows.Forms.Form)

		Dim scrWidth As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width
		Dim scrHeight As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height
		Dim cntrl As System.Windows.Forms.Control
		If (scrWidth < frm.Width) Then
			For Each cntrl In frm.Controls

				cntrl.Width = CInt(((cntrl.Width) * (scrWidth)) / (frm.Width))
				cntrl.Left = CInt(((cntrl.Left) * (scrWidth)) / (frm.Width))
			Next cntrl
		End If

		If (scrHeight < frm.Height) Then
			For Each cntrl In frm.Controls

				cntrl.Height = CInt(((cntrl.Height) * (scrHeight)) / (frm.Height))
				cntrl.Top = CInt(((cntrl.Top) * (scrHeight)) / (frm.Height))

			Next cntrl
		End If

	End Sub

	Private Sub ReaderForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'Initalize the Reader
		If (CBool(Me.InitRead())) Then

			'start a read on the reader
			'Me.StartStatus()
			Me.StartRead()
		Else

			'if not close the form
			Me.Close()

			Return

		End If

		If (Symbol.Win32.PlatformType = "PocketPC") Then
			Me.Menu = New MainMenu
		End If

		ScaleDown(Me)

		Me.ScanButton.Focus()

	End Sub

	Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
		'close the form
		Me.Close()

	End Sub

	'Click from ScanButton

	Private Sub ScanButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScanButton.Click

		If (Me.MyReader Is Nothing) Then

			Return

		End If

		Me.MyReader.Actions.ToggleSoftTrigger()

	End Sub

	Private Sub ScanButton_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ScanButton.KeyDown
		' Checks if the Enter key (character code 13) was used.
		If e.KeyValue = 13 Then
			ScanButton_Click(Nothing, e)
		End If
	End Sub

	Private Sub ReaderForm_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
		Me.ScanButton.Focus()
	End Sub

	'Application is closing

	Protected Overloads Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)

		'Terminate the reader, call base class
		Me.TermReader()
		MyBase.OnClosing(e)

	End Sub

	Private Function InitRead() As Boolean

		'If reader is already present then fail initialize
		If Not (Me.MyReader Is Nothing) Then
			Return False
		End If


		Try

			'Get Selected device from user
			Dim MyDevice As Symbol.Generic.Device _
				= Symbol.StandardForms.SelectDevice.Select( _
										Symbol.Barcode.Device.Title, _
										Symbol.Barcode.Device.AvailableDevices)
			If (MyDevice Is Nothing) Then
				MessageBox.Show("No Device Selected", "SelectDevice")
				Return False
			End If

			'create the reader, based on selected device
			Me.MyReader = New Symbol.Barcode.Reader(MyDevice)

			' Create reader data
			Me.MyReaderData = New Symbol.Barcode.ReaderData( _
			 Symbol.Barcode.ReaderDataTypes.Text, _
			 Symbol.Barcode.ReaderDataLengths.MaximumLabel)

			'Enable reader, with wait cursor
			Me.MyReader.Actions.Enable()

			'create event handler
			Me.MyReadNotifyHander = New EventHandler(AddressOf MyReader_ReadNotify)
			Me.MyStatusNotifyHandler = New EventHandler(AddressOf MyReader_StatusNotify)

		Catch ex As Symbol.Exceptions.InvalidRequestException
			MessageBox.Show("InitReader\n" + "Invalid Operation\n" + ex.Message())
			Return False

		Catch ex As Symbol.Exceptions.OperationFailureException
			MessageBox.Show("InitReader\n" + "Operation Failure" + ex.Message())
			Return False

		Catch ex As Symbol.Exceptions.UnimplementedFunctionException
			MessageBox.Show("InitReader\n" + "Unimplemented Function" + ex.Message())
			Return False

		End Try

		Me.MyActivateHandler = New EventHandler(AddressOf ReaderForm_Activated)
		Me.MyDeActivateHandler = New EventHandler(AddressOf ReaderForm_Deactivate)
		AddHandler Me.Activated, Me.MyActivateHandler
		AddHandler Me.Deactivate, Me.MyDeActivateHandler

		Return True

	End Function
	'Stop reading and disable/close reader

	Private Sub TermReader()

		'If we have a reader
		If Not (Me.MyReader Is Nothing) Then
			'Remove Form event handlers
			RemoveHandler Me.Activated, Me.MyActivateHandler
			RemoveHandler Me.Deactivate, Me.MyDeActivateHandler

			'stop all notifications
			Me.StopRead()
			'Me.StopStatus()
			Try

				'Disable the Reader
				Me.MyReader.Actions.Disable()

				'free it up and assign nothing 
				Me.MyReader.Dispose()

				'Indiacte we no longer have one
				Me.MyReader = Nothing

			Catch ex As Symbol.Exceptions.InvalidRequestException
				MessageBox.Show("InitReader\n" + "Invalid Operation\n" + ex.Message())

			Catch ex As Symbol.Exceptions.OperationFailureException

				MessageBox.Show("InitReader\n" + "Operation Failure" + ex.Message())

			Catch ex As Symbol.Exceptions.UnimplementedFunctionException

				MessageBox.Show("InitReader\n" + "Unimplemented Function" + ex.Message())

			End Try

		End If

		If Not (Me.MyReaderData Is Nothing) Then

			'Free it up and assign nothing
			Me.MyReaderData.Dispose()

			'Indicate we no longer have one
			Me.MyReaderData = Nothing

		End If

	End Sub

	' start a read on reader

	Private Sub StartRead()

		'if we have both a reader and readerdata
		If Not ((Me.MyReader Is Nothing) And (Me.MyReaderData Is Nothing)) Then

			Try

				AddHandler MyReader.ReadNotify, Me.MyReadNotifyHander

				'Submit a read
				Me.MyReader.Actions.Read(Me.MyReaderData)

			Catch ex As Symbol.Exceptions.UnimplementedFunctionException
				MessageBox.Show("StartRead\n" + "Unimplemented Function\n" + ex.Message())

			Catch ex As Symbol.Exceptions.InvalidIndexerException
				MessageBox.Show("StartRead\n" + "Invalid Indexer\n" + ex.Message())

			Catch ex As Symbol.Exceptions.OperationFailureException
				MessageBox.Show("StopRead\n" + "Operation Failure\n" + "Result = 0x" + (ex.Result).ToString("X8") + "\n" + ex.Message())

			Catch ex As Symbol.Exceptions.InvalidRequestException
				MessageBox.Show("StartRead\n" + "Invalid Request\n" + ex.Message)

			End Try

		End If

	End Sub


	' stop all the read

	Private Sub StopRead()

		'if we do not have a reader, then do nothing
		If (Me.MyReader Is Nothing) Then

			Return

		End If
		Try

			'remove read notification handler
			RemoveHandler MyReader.ReadNotify, Me.MyReadNotifyHander

			'Flush (Cancel all pending reads)
			Me.MyReader.Actions.Flush()

		Catch ex As Symbol.Exceptions.UnimplementedFunctionException
			MessageBox.Show("StartRead\n" + "Unimplemented Function\n" + ex.Message())

		Catch ex As Symbol.Exceptions.InvalidRequestException
			MessageBox.Show("StartRead\n" + "Invalid Request\n" + ex.Message())

		Catch ex As Symbol.Exceptions.OperationFailureException
			MessageBox.Show("StopRead\n" + "Operation Failure\n" + "Result = 0x" + (ex.Result).ToString("X8") + "\n" + ex.Message())

		End Try

	End Sub

	'Read notification handler

	Private Sub MyReader_ReadNotify(ByVal sender As Object, ByVal e As EventArgs)

		'Get ReaderData
		Dim TheReaderData As Symbol.Barcode.ReaderData = Me.MyReader.GetNextReaderData

		Select Case TheReaderData.Result

			Case Symbol.Results.SUCCESS

				'Handle the data from this read
				Me.HandleData(TheReaderData)
				Me.StartRead()

			Case Symbol.Results.CANCELED

			Case Else

				Dim sMsg As String
				sMsg = "Read Failed\n" + "Result = " + (CInt(TheReaderData.Result)).ToString("X8")
				MessageBox.Show(sMsg, "ReadNotify")

		End Select

	End Sub

	'Handle data from the reader

	Private Sub HandleData(ByVal TheReaderData As Symbol.Barcode.ReaderData)

		Me.DataTextBox.Text = TheReaderData.Text

	End Sub

	Private Sub ReaderForm_Activated(ByVal sender As Object, ByVal e As EventArgs)

		'Me.StartStatus()

		'If there are no reads pending on MyReaderData start a new read
		If Not (Me.MyReaderData.IsPending) Then

			Me.StartRead()

		End If

	End Sub

	Private Sub ReaderForm_Deactivate(ByVal sender As Object, ByVal e As EventArgs)

		Me.StopRead()
		'Me.StopStatus()
	End Sub
	cnndata.close()
End Class


Is This A Good Question/Topic? 1

Replies To: BarCode Reader

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9366
  • View blog
  • Posts: 35,187
  • Joined: 12-June 08

Re: BarCode Reader

Posted 10 December 2008 - 09:57 AM

Yup - the good ol' "Cue Cat" is .NEt friendly..

http://blogs.msdn.co...06/1815618.aspx
Was This Post Helpful? 0
  • +
  • -

#3 fuzzymallets  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 29
  • Joined: 03-December 07

Re: BarCode Reader

Posted 12 December 2008 - 11:52 AM

I had to do something similar for the company I work for. What kind of scanner is it serial, usb, ps2? If the scanner is serial or usb I have some code that may help.

What are you having problems doing?

And there are lots of people here that can help. They helped me with the same kind of problem.
Was This Post Helpful? 0
  • +
  • -

#4 princess1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-January 09

Re: BarCode Reader

Posted 07 January 2009 - 11:37 AM

I have the same problem at my company and we need to use a serial scanner. Also try to read a 2D barcode, and pull data from a table in SQL Server. Any help or sample code greatly appreciated.
Was This Post Helpful? 0
  • +
  • -

#5 tscheffel  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 20-February 09

Re: BarCode Reader

Posted 20 February 2009 - 09:26 AM

As others have said, knowing your target environment (e.g. scanner model, O/S, API framework) would better enable viewers to assist you. Anyway, the C# (sorry, not VB) code below was taken from a Symbol (now Motorola) video tutorial demonstrating how to make a simple Windows Forms app to read barcode values into a textbox. Once you have the data in a textbox it should be quite easy to shove it into a database.

I, too, am learning (as of yesterday) how to program mobile apps for a barcode scanner (specifically the Symbol MC9090/WM5 using VS2008 and Symbol's EMDK for .Net). There doesn't seem to be a wealth of demo apps out there, making this experience challenging. I'll be happy when I get an emulator set up since I don't have an actual 9090 to experiment with.

Note: the video demo is available via Video Demo

Troy

using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyFirstBarcodeApp
{
	public partial class Form1 : Form
	{
		public Symbol.Barcode.Reader Reader { get; set; }
		private Symbol.Barcode.ReaderData ReaderData { get; set; }

		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			this.Reader = new Symbol.Barcode.Reader();
			this.ReaderData = new Symbol.Barcode.ReaderData(Symbol.Barcode.ReaderDataTypes.Text, 7905); // 7905 = max barcode length in bytes

			this.Reader.Actions.Enable();

			this.Reader.ReadNotify += new EventHandler(Reader_ReadNotify);  // specify event handler for reading barcode data
			this.Reader.Actions.Read(this.ReaderData);					  // this call activates the scanner's scanning ability
		}

		void Reader_ReadNotify(object sender, EventArgs e)
		{
			Symbol.Barcode.ReaderData nextReaderData = this.Reader.GetNextReaderData();
			this.textBox1.Text = nextReaderData.Text;				   // display barcode info on screen
			this.Reader.Actions.Read(this.ReaderData);				  // repeat loop by waiting for next barcode input
		}

		private void Form1_Closing(object sender, CancelEventArgs e)
		{
			this.Reader.Actions.Flush();								// close any pending barcode reads
			this.Reader.Actions.Disable();							  // disable barcode reader
			this.ReaderData.Dispose();								  // clean up NEWed object
			this.Reader.Dispose();									  // clean up NEWed object
		}
	}
}

Was This Post Helpful? 1

#6 oda1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-April 09

Re: BarCode Reader

Posted 02 April 2009 - 07:54 AM

I am going through the video. When I get to add the Symbol References they are not there. Where can I go to download these so they will show up in my list.
Was This Post Helpful? 0
  • +
  • -

#7 tscheffel  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 2
  • Joined: 20-February 09

Re: BarCode Reader

Posted 02 April 2009 - 08:11 AM

For Symbol DLL references, go to their support site and search for SDK. I believe v1.4 is the latest one for the .Net framework.
Was This Post Helpful? 1
  • +
  • -

#8 oda1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-April 09

Re: BarCode Reader

Posted 02 April 2009 - 09:13 AM

I am having trouble finding and determining which sdk I need.

I have Visual Studio 2008 and the Symbol device I have is Windows Mobile 2003.

I have downloaded the "smdk-m-1.04.05" and when I run it I get a message "Unable to install smdk-visual studio not found.
Was This Post Helpful? 0
  • +
  • -

#9 oda1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-April 09

Re: BarCode Reader

Posted 02 April 2009 - 09:47 AM

SMDK v1.7 for .NET seems to have worked.

Thanks for your help
Was This Post Helpful? 0
  • +
  • -

#10 oda1  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 02-April 09

Re: BarCode Reader

Posted 02 April 2009 - 11:43 AM

Great tutorial! Any more? I am wanting to print to a Zebra rw220 also.
Was This Post Helpful? 0
  • +
  • -

#11 Raj The Legend  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-April 09

Re: BarCode Reader

Posted 08 April 2009 - 07:34 PM

guys, hi there...im new here and also for barcode programming....i tried tscheffel program and i notice there is a using System.Ling which is not recognized...cld u advise on this please? as well i am not able to find the library to add public Symbol.Barcode.Reader Reader { get; set; }..please advise. thank you.
Was This Post Helpful? 0
  • +
  • -

#12 scsfdev  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-April 09

Re: BarCode Reader

Posted 12 April 2009 - 08:57 PM

View PostRaj The Legend, on 8 Apr, 2009 - 06:34 PM, said:

guys, hi there...im new here and also for barcode programming....i tried tscheffel program and i notice there is a using System.Ling which is not recognized...cld u advise on this please? as well i am not able to find the library to add public Symbol.Barcode.Reader Reader { get; set; }..please advise. thank you.


I think you mean LINQ. This is a reference in Visual Studio 2008.
If you are trying to run this project "tscheffel" using older version that is 2005 or 2003, it will not work. I think you can download Free visual studio 2008 express edition from microsoft web site.
Was This Post Helpful? 0
  • +
  • -

#13 dbasnett  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 109
  • View blog
  • Posts: 605
  • Joined: 01-October 08

Re: BarCode Reader

Posted 13 April 2009 - 06:26 AM

I have used barcode readers in the past. All of them acted like keyboards, meaning that if you have a form with a textbox that is selected and you read with the barcode scanner the input will be in the textbox.
Was This Post Helpful? 0
  • +
  • -

#14 venkatakris2000  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-August 09

Re: BarCode Reader

Posted 02 August 2009 - 01:26 PM

View PostMTown, on 10 Dec, 2008 - 08:09 AM, said:

Hello, this is my first time on this forum, so I would like to thank everyone in advance for any help you can provide. I am trying to learn how to develop a very simple application on a Handheld barcode Scanner. All I am looking to do is read a barcode, and pull data from a table in SQL Server. I have downloaded a couple of different developer kits, and the samples have not gotten me any where. Below is the code from my last attempt. Does anyone have or know where I could get a very simple example of coding a BarCode Reader in VB .Net? Again any help anyone can provide would be greatly appreciated.
Imports System
Imports System.Windows.Forms

Public Class ReaderForm

	Inherits System.Windows.Forms.Form

	Private Sub InitializeComponent()
		Me.ScanButton = New System.Windows.Forms.Button
		Me.DataLabel = New System.Windows.Forms.Label
		Me.DataTextBox = New System.Windows.Forms.TextBox
		Me.CloseButton = New System.Windows.Forms.Button
		Me.SuspendLayout()
		'
		'ScanButton
		'
		Me.ScanButton.Location = New System.Drawing.Point(8, 208)
		Me.ScanButton.Name = "ScanButton"
		Me.ScanButton.Size = New System.Drawing.Size(64, 25)
		Me.ScanButton.TabIndex = 0
		Me.ScanButton.Text = "Scan"
		'
		'DataLabel
		'
		Me.DataLabel.Location = New System.Drawing.Point(8, 16)
		Me.DataLabel.Name = "DataLabel"
		Me.DataLabel.Size = New System.Drawing.Size(72, 21)
		Me.DataLabel.Text = "Data:"
		'
		'DataTextBox
		'
		Me.DataTextBox.Location = New System.Drawing.Point(80, 16)
		Me.DataTextBox.Name = "DataTextBox"
		Me.DataTextBox.Size = New System.Drawing.Size(152, 23)
		Me.DataTextBox.TabIndex = 6
		'
		'CloseButton
		'
		Me.CloseButton.Location = New System.Drawing.Point(168, 208)
		Me.CloseButton.Name = "CloseButton"
		Me.CloseButton.Size = New System.Drawing.Size(64, 25)
		Me.CloseButton.TabIndex = 5
		Me.CloseButton.Text = "Exit"
		'
		'
		'ReaderForm
		'
		Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit
		Me.BackColor = System.Drawing.Color.White
		Me.ClientSize = New System.Drawing.Size(240, 270)
		Me.Controls.Add(Me.ScanButton)
		Me.Controls.Add(Me.DataLabel)
		Me.Controls.Add(Me.DataTextBox)
		Me.Controls.Add(Me.CloseButton)
		Me.Name = "ReaderForm"
		Me.Text = "MP2"
		Me.ResumeLayout(False)
	End Sub
	Public Shared Sub Main()
		Application.Run(New ReaderForm)
	End Sub
	Private MyReader As Symbol.Barcode.Reader = Nothing
	Private MyReaderData As Symbol.Barcode.ReaderData = Nothing
	Private MyReadNotifyHander As System.EventHandler = Nothing
	Private MyStatusNotifyHandler As System.EventHandler = Nothing
	Private MyActivateHandler As System.EventHandler = Nothing
	Private MyDeActivateHandler As System.EventHandler = Nothing

	'This function scales down the given Form & its child controls in order to
	'make them completely viewable, based on the screen width & height.
	Public Sub ScaleDown(ByVal frm As System.Windows.Forms.Form)

		Dim scrWidth As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width
		Dim scrHeight As Integer = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height
		Dim cntrl As System.Windows.Forms.Control
		If (scrWidth < frm.Width) Then
			For Each cntrl In frm.Controls

				cntrl.Width = CInt(((cntrl.Width) * (scrWidth)) / (frm.Width))
				cntrl.Left = CInt(((cntrl.Left) * (scrWidth)) / (frm.Width))
			Next cntrl
		End If

		If (scrHeight < frm.Height) Then
			For Each cntrl In frm.Controls

				cntrl.Height = CInt(((cntrl.Height) * (scrHeight)) / (frm.Height))
				cntrl.Top = CInt(((cntrl.Top) * (scrHeight)) / (frm.Height))

			Next cntrl
		End If

	End Sub

	Private Sub ReaderForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'Initalize the Reader
		If (CBool(Me.InitRead())) Then

			'start a read on the reader
			'Me.StartStatus()
			Me.StartRead()
		Else

			'if not close the form
			Me.Close()

			Return

		End If

		If (Symbol.Win32.PlatformType = "PocketPC") Then
			Me.Menu = New MainMenu
		End If

		ScaleDown(Me)

		Me.ScanButton.Focus()

	End Sub

	Private Sub CloseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseButton.Click
		'close the form
		Me.Close()

	End Sub

	'Click from ScanButton

	Private Sub ScanButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ScanButton.Click

		If (Me.MyReader Is Nothing) Then

			Return

		End If

		Me.MyReader.Actions.ToggleSoftTrigger()

	End Sub

	Private Sub ScanButton_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ScanButton.KeyDown
		' Checks if the Enter key (character code 13) was used.
		If e.KeyValue = 13 Then
			ScanButton_Click(Nothing, e)
		End If
	End Sub

	Private Sub ReaderForm_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyUp
		Me.ScanButton.Focus()
	End Sub

	'Application is closing

	Protected Overloads Overrides Sub OnClosing(ByVal e As System.ComponentModel.CancelEventArgs)

		'Terminate the reader, call base class
		Me.TermReader()
		MyBase.OnClosing(e)

	End Sub

	Private Function InitRead() As Boolean

		'If reader is already present then fail initialize
		If Not (Me.MyReader Is Nothing) Then
			Return False
		End If


		Try

			'Get Selected device from user
			Dim MyDevice As Symbol.Generic.Device _
				= Symbol.StandardForms.SelectDevice.Select( _
										Symbol.Barcode.Device.Title, _
										Symbol.Barcode.Device.AvailableDevices)
			If (MyDevice Is Nothing) Then
				MessageBox.Show("No Device Selected", "SelectDevice")
				Return False
			End If

			'create the reader, based on selected device
			Me.MyReader = New Symbol.Barcode.Reader(MyDevice)

			' Create reader data
			Me.MyReaderData = New Symbol.Barcode.ReaderData( _
			 Symbol.Barcode.ReaderDataTypes.Text, _
			 Symbol.Barcode.ReaderDataLengths.MaximumLabel)

			'Enable reader, with wait cursor
			Me.MyReader.Actions.Enable()

			'create event handler
			Me.MyReadNotifyHander = New EventHandler(AddressOf MyReader_ReadNotify)
			Me.MyStatusNotifyHandler = New EventHandler(AddressOf MyReader_StatusNotify)

		Catch ex As Symbol.Exceptions.InvalidRequestException
			MessageBox.Show("InitReader\n" + "Invalid Operation\n" + ex.Message())
			Return False

		Catch ex As Symbol.Exceptions.OperationFailureException
			MessageBox.Show("InitReader\n" + "Operation Failure" + ex.Message())
			Return False

		Catch ex As Symbol.Exceptions.UnimplementedFunctionException
			MessageBox.Show("InitReader\n" + "Unimplemented Function" + ex.Message())
			Return False

		End Try

		Me.MyActivateHandler = New EventHandler(AddressOf ReaderForm_Activated)
		Me.MyDeActivateHandler = New EventHandler(AddressOf ReaderForm_Deactivate)
		AddHandler Me.Activated, Me.MyActivateHandler
		AddHandler Me.Deactivate, Me.MyDeActivateHandler

		Return True

	End Function
	'Stop reading and disable/close reader

	Private Sub TermReader()

		'If we have a reader
		If Not (Me.MyReader Is Nothing) Then
			'Remove Form event handlers
			RemoveHandler Me.Activated, Me.MyActivateHandler
			RemoveHandler Me.Deactivate, Me.MyDeActivateHandler

			'stop all notifications
			Me.StopRead()
			'Me.StopStatus()
			Try

				'Disable the Reader
				Me.MyReader.Actions.Disable()

				'free it up and assign nothing 
				Me.MyReader.Dispose()

				'Indiacte we no longer have one
				Me.MyReader = Nothing

			Catch ex As Symbol.Exceptions.InvalidRequestException
				MessageBox.Show("InitReader\n" + "Invalid Operation\n" + ex.Message())

			Catch ex As Symbol.Exceptions.OperationFailureException

				MessageBox.Show("InitReader\n" + "Operation Failure" + ex.Message())

			Catch ex As Symbol.Exceptions.UnimplementedFunctionException

				MessageBox.Show("InitReader\n" + "Unimplemented Function" + ex.Message())

			End Try

		End If

		If Not (Me.MyReaderData Is Nothing) Then

			'Free it up and assign nothing
			Me.MyReaderData.Dispose()

			'Indicate we no longer have one
			Me.MyReaderData = Nothing

		End If

	End Sub

	' start a read on reader

	Private Sub StartRead()

		'if we have both a reader and readerdata
		If Not ((Me.MyReader Is Nothing) And (Me.MyReaderData Is Nothing)) Then

			Try

				AddHandler MyReader.ReadNotify, Me.MyReadNotifyHander

				'Submit a read
				Me.MyReader.Actions.Read(Me.MyReaderData)

			Catch ex As Symbol.Exceptions.UnimplementedFunctionException
				MessageBox.Show("StartRead\n" + "Unimplemented Function\n" + ex.Message())

			Catch ex As Symbol.Exceptions.InvalidIndexerException
				MessageBox.Show("StartRead\n" + "Invalid Indexer\n" + ex.Message())

			Catch ex As Symbol.Exceptions.OperationFailureException
				MessageBox.Show("StopRead\n" + "Operation Failure\n" + "Result = 0x" + (ex.Result).ToString("X8") + "\n" + ex.Message())

			Catch ex As Symbol.Exceptions.InvalidRequestException
				MessageBox.Show("StartRead\n" + "Invalid Request\n" + ex.Message)

			End Try

		End If

	End Sub


	' stop all the read

	Private Sub StopRead()

		'if we do not have a reader, then do nothing
		If (Me.MyReader Is Nothing) Then

			Return

		End If
		Try

			'remove read notification handler
			RemoveHandler MyReader.ReadNotify, Me.MyReadNotifyHander

			'Flush (Cancel all pending reads)
			Me.MyReader.Actions.Flush()

		Catch ex As Symbol.Exceptions.UnimplementedFunctionException
			MessageBox.Show("StartRead\n" + "Unimplemented Function\n" + ex.Message())

		Catch ex As Symbol.Exceptions.InvalidRequestException
			MessageBox.Show("StartRead\n" + "Invalid Request\n" + ex.Message())

		Catch ex As Symbol.Exceptions.OperationFailureException
			MessageBox.Show("StopRead\n" + "Operation Failure\n" + "Result = 0x" + (ex.Result).ToString("X8") + "\n" + ex.Message())

		End Try

	End Sub

	'Read notification handler

	Private Sub MyReader_ReadNotify(ByVal sender As Object, ByVal e As EventArgs)

		'Get ReaderData
		Dim TheReaderData As Symbol.Barcode.ReaderData = Me.MyReader.GetNextReaderData

		Select Case TheReaderData.Result

			Case Symbol.Results.SUCCESS

				'Handle the data from this read
				Me.HandleData(TheReaderData)
				Me.StartRead()

			Case Symbol.Results.CANCELED

			Case Else

				Dim sMsg As String
				sMsg = "Read Failed\n" + "Result = " + (CInt(TheReaderData.Result)).ToString("X8")
				MessageBox.Show(sMsg, "ReadNotify")

		End Select

	End Sub

	'Handle data from the reader

	Private Sub HandleData(ByVal TheReaderData As Symbol.Barcode.ReaderData)

		Me.DataTextBox.Text = TheReaderData.Text

	End Sub

	Private Sub ReaderForm_Activated(ByVal sender As Object, ByVal e As EventArgs)

		'Me.StartStatus()

		'If there are no reads pending on MyReaderData start a new read
		If Not (Me.MyReaderData.IsPending) Then

			Me.StartRead()

		End If

	End Sub

	Private Sub ReaderForm_Deactivate(ByVal sender As Object, ByVal e As EventArgs)

		Me.StopRead()
		'Me.StopStatus()
	End Sub
	cnndata.close()
End Class


Hi, I am working on symbol devices. I am trying to get a code in VB. Were you able to find any?Please let me know as early as possible

Mentor Edit: Remove duplication.

This post has been edited by AdamSpeight2008: 02 August 2009 - 01:39 PM

Was This Post Helpful? 0
  • +
  • -

#15 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2267
  • View blog
  • Posts: 9,479
  • Joined: 29-May 08

Re: BarCode Reader

Posted 02 August 2009 - 01:39 PM

Are you receiving any errors? Does this code not work that way you intended it? When asking for help there are a couple items that are vital in order for someone to properly help you:
  • Post the code you're having problems with
  • Post the exact error you're receiving, if you are receiving one
  • If no error explain what the code is doing versus what you want it to do
  • Post your question in the body of your post, not the description field

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2