scanning on multiple forms using Symbol SMDK

G

Guest

I am writing application for Symbol MC70 unit. For implementation of scanning
functionality I am using SMDK for .NET.
I have application, which performs scan on first form and from the handler
it will opens next form. From this form after successful scan, I am trying to
show next form. Unfortunately, it doesn't work.
Example from Symbol CS_ScanSample3 is not really good, because it will opens
next form not from handler.

Did anybody implemented such functionality?

Thanks in advance!
Olexandr.
 
S

savvaschr

Try This
Copy and Paste the following


Private Function InitReader() As Boolean

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

Return False

End If

'Create new reader, first available reader will be used.
Me.MyReader = New Symbol.Barcode.Reader

'Create reader data
Me.MyReaderData = New Symbol.Barcode.ReaderData( _

Symbol.Barcode.ReaderDataTypes.Text, _

Symbol.Barcode.ReaderDataLengths.MaximumLabel)


' create event handler delegate
Me.MyEventHandler = New System.EventHandler(AddressOf
MyReader_ReadNotify)

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

'Me.MyReader.Parameters.Feedback.Success.BeepTime = 0
'Me.MyReader.Parameters.Feedback.Success.WaveFile = "\\windows\
\alarm3.wav"

AddHandler Me.Activated, New EventHandler(AddressOf
FrmTrxn2_Activated)
AddHandler Me.Deactivate, New EventHandler(AddressOf
frmtrxn2_Deactivate)


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

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

'free it up
Me.MyReader.Dispose()

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

End If

' If we have a reader data
If Not (Me.MyReaderData Is Nothing) Then

'Free it up
Me.MyReaderData.Dispose()

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

End If

End Sub

'Start a read on the reader

Private Sub StartRead()

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

'Submit a read
AddHandler MyReader.ReadNotify, Me.MyEventHandler

Me.MyReader.Actions.Read(Me.MyReaderData)

End If

End Sub

'Stop all reads on the reader

Private Sub StopRead()

'If we have a reader
If Not (Me.MyReader Is Nothing) Then

'Flush (Cancel all pending reads)
RemoveHandler MyReader.ReadNotify, Me.MyEventHandler

Me.MyReader.Actions.Flush()

End If

End Sub

'Read complete or failure notification

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

Dim TheReaderData As Symbol.Barcode.ReaderData =
Me.MyReader.GetNextReaderData()

'If it is a successful read (as opposed to a failed one)
If (TheReaderData.Result = Symbol.Results.SUCCESS) Then

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

'Start the next read
Me.StartRead()

End If

End Sub

'Handle data from the reader

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


Dim S as string
S= TheReaderData.Text

Catch ex As Exception
End Try


End Sub

' Called when the form is activated. This will occur when the
form becomes the current application.
Private Sub FORM_Activated(ByVal sender As Object, ByVal e As
EventArgs) Handles Me.Activated
'If there are no reads pending on MyReader start a new read
If Not Me.MyReaderData Is Nothing Then
If Not (Me.MyReaderData.IsPending) Then

Me.StartRead()

End If
End If

End Sub


And then Add this to Your Form Load Event

Try
If (Me.InitReader()) Then
'Start a read on the reader
Me.StartRead()
End If
Catch ex As Exception
'MsgBox("Scanner is not Available on this Device")
End Try

In the Hadle data sub you can open your other form
Dim F as new Form2
F.show

I hope all this helps
 
G

Guest

Thank you for fast response !
But ...

Actually, I do the same what you suggested. If you look at example
CS_ScanSample3 from Symbol, it is look similar.

I have 2 choices.
1. Use one reader, like in CS_ScanSample3. I am able to scan on first form,
then from handler I show another form and then I am not able to scan. I am
sending you packed solution with example. You could test by yourself and
review code.

2. Use on every form new reader. I was using this approach before, but with
SMDK 1.3 and higher I have this issue:

http://support.symbol.com/support/s...L_Public&dialogID=7328225&stateId=1 0 7326267

and I don't know how to avoid this problem. I need to actions.enable on
every form, otherwise I am not able to scan.

Any ideas?

Thanks, Olexandr !
 
G

Guest

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

namespace MultiScanForm
{
public partial class MainForm : Form
{
private System.EventHandler FormEventHandler;

public MainForm()
{
InitializeComponent();
}


private void MainForm_Load(object sender, EventArgs e)
{
if (Scanning.InitReader())
{
// Create a new delegate to handle scan notifications
FormEventHandler = new EventHandler(MyReader_ReadNotify);
// Set the event handler of the Scanning class to our delegate
Scanning.MyEventHandler = FormEventHandler;
}
else
{
this.Close();
return;
}
}

/// <summary>
/// Read complete or failure notification
/// </summary>
private void MyReader_ReadNotify(object sender, EventArgs e)
{
Symbol.Barcode.ReaderData TheReaderData = Scanning.MyReaderData;

// If it is a successful read (as opposed to a failed one)
if (TheReaderData.Result == Symbol.Results.SUCCESS)
{
FirstChildForm firstChildForm = new
FirstChildForm(TheReaderData.Text);
firstChildForm.ShowDialog();
firstChildForm.Dispose();
}
}

private void MainForm_Closed(object sender, EventArgs e)
{
Scanning.TermReader();
}


private void MainForm_Activated(object sender, EventArgs e)
{
// Reset the scan event handler for the Scanning object to the form's
delegate.
Scanning.MyEventHandler = FormEventHandler;

// Start the next read
Scanning.StartRead("MainForm.Activated");
}


private void MainForm_Deactivate(object sender, EventArgs e)
{
Scanning.StopRead("MainForm.MainForm_Deactivate");
}
}
}
 
G

Guest

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

namespace MultiScanForm
{
public partial class FirstChildForm : Form
{
private System.EventHandler FormEventHandler;

public FirstChildForm(string label)
{
InitializeComponent();
textBox1.Text = label;
}

private void FirstChildForm_Load(object sender, EventArgs e)
{
// Create a new delegate to handle scan notifications
FormEventHandler = new EventHandler(FirstChildForm_ReadNotify);
// Set the event handler of the Scanning class to our delegate
Scanning.MyEventHandler = FormEventHandler;
}

private void FirstChildForm_ReadNotify(object sender, EventArgs e)
{
Symbol.Barcode.ReaderData TheReaderData = Scanning.MyReaderData;

// If it is a successful read (as opposed to a failed one)
if (TheReaderData.Result == Symbol.Results.SUCCESS)
{
SecondChildForm secChildForm = new
SecondChildForm(TheReaderData.Text);
secChildForm.ShowDialog();
secChildForm.Dispose();
}
}

private void FirstChildForm_Activated(object sender, EventArgs e)
{
// Reset the scan event handler for the Scanning object everytime the
form is activated
Scanning.MyEventHandler = this.FormEventHandler;

// Start the next read
Scanning.StartRead("FirstChildForm_Activated");
}

private void FirstChildForm_Deactivate(object sender, EventArgs e)
{
Scanning.StopRead("FirstChildForm_Deactivate");
}
}
}
 
G

Guest

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

namespace MultiScanForm
{
public partial class SecondChildForm : Form
{
public SecondChildForm(string label)
{
InitializeComponent();
textBox1.Text = label;
}

private void button1_Click(object sender, EventArgs e)
{
Close();
}
}
}
 
G

Guest

//--------------------------------------------------------------------
// FILENAME: Scanning.cs
//
// Copyright(c) 2005 Symbol Technologies Inc. All rights reserved.
//
// DESCRIPTION:
//
// NOTES:
//
//
//--------------------------------------------------------------------
using System;
using System.Diagnostics;

namespace MultiScanForm
{
/// <summary>
/// The Scanning class provides static methods to allow reuse of the same
/// Reader and ReaderData objects on multiple forms.
/// </summary>
public class Scanning
{
private static Symbol.Barcode.Reader _MyReader = null;
private static Symbol.Barcode.ReaderData _MyReaderData = null;
private static System.EventHandler _MyEventHandler = null;

/// <summary>
/// MyReaderData property provides access to the ReaderData
/// </summary>
public static Symbol.Barcode.ReaderData MyReaderData
{
get { return _MyReader.GetNextReaderData(); }
}

/// <summary>
/// Upon completion of a scan a ReadNotify event will be fired.
/// _MyEventHandler specifies the delegate that will handle this
notification
/// and MyEventHandler property provides access to _MyEventHandler.
/// Each form that uses the Scanning class will have it's own delegate.
/// The form will be responsible for setting this Event Handler to it's
delegate.
/// </summary>
public static System.EventHandler MyEventHandler
{
get { return _MyEventHandler; }
set { _MyEventHandler = value; }
}

/// <summary>
/// Initialize the reader.
/// </summary>
public static bool InitReader()
{
// If reader is already present then fail initialize
if ( Scanning._MyReader != null )
{
return false;
}
Debug.WriteLine("InitReader");

// Create new reader, first available reader will be used.
Scanning._MyReader = new Symbol.Barcode.Reader();

// Create reader data
Scanning._MyReaderData = new Symbol.Barcode.ReaderData(
Symbol.Barcode.ReaderDataTypes.Text,
Symbol.Barcode.ReaderDataLengths.MaximumLabel);

// Enable reader, with wait cursor
Scanning._MyReader.Actions.Enable();

Scanning._MyReader.Parameters.Feedback.Success.BeepTime = 0;
Scanning._MyReader.Parameters.Feedback.Success.WaveFile =
"\\windows\\alarm3.wav";

return true;
}

/// <summary>
/// Stop reading and disable/close reader
/// </summary>
public static void TermReader()
{
Debug.WriteLine("TermReader");
// If we have a reader
if ( Scanning._MyReader != null )
{
// Disable the reader
Scanning._MyReader.Actions.Disable();

// Free it up
Scanning._MyReader.Dispose();

// Indicate we no longer have one
Scanning._MyReader = null;
}

// If we have a reader data
if ( Scanning._MyReaderData != null )
{
// Free it up
Scanning._MyReaderData.Dispose();

// Indicate we no longer have one
Scanning._MyReaderData = null;
}
}

/// <summary>
/// Start a read on the reader
/// </summary>
public static void StartRead(string form)
{
// If we have both a reader and a reader data
if ( ( Scanning._MyReader != null ) &&
( Scanning._MyReaderData != null ) )
{
Debug.WriteLine(string.Format("StartRead <{0}>",form));
// Submit a read
Scanning._MyReader.ReadNotify += Scanning._MyEventHandler;

// Prevent duplicate reads
if ( !Scanning._MyReaderData.IsPending )
Scanning._MyReader.Actions.Read(Scanning._MyReaderData);
}
}

/// <summary>
/// Stop all reads on the reader
/// </summary>
public static void StopRead(string form)
{
// If we have a reader
if ( Scanning._MyReader != null )
{
Debug.WriteLine(string.Format("StopRead <{0}>",form));
// Flush (Cancel all pending reads)
Scanning._MyReader.ReadNotify -= Scanning._MyEventHandler;
Scanning._MyReader.Actions.Flush();
}
}
public static void ToggleTrigger()
{
if (Scanning._MyReader== null)
{
return;
}
Scanning._MyReader.Actions.ToggleSoftTrigger();
}

}
}
 
G

Guest

Hi !
Finally, I figured out how to make it work. I just changed handler of scan
to invoke my another handler async. I set ScannedEvent before.

private void MyReader_ReadNotify(object sender, EventArgs e)
{
if (BarcodeReader.MyReaderData.Result == Symbol.Results.SUCCESS)
{
ScanEventArgs scanArgs = new
ScanEventArgs(BarcodeReader.MyReaderData.Text);
form.BeginInvoke(this.ScannedEvent, this, scanArgs);
this.StartRead();
}
}

Thanks, Sasha !
 
M

Martin

create static class for symbol scanner
and use this in all foms
open scanner at startup, activae / deactivae only during open/close forms,
shutdown during application close
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top