Sunilraskar
October 16th, 2004, 08:27 AM
I'm using PDT8100 Pocket PC. I've implemented bar code scanning using scanwedge.exe and code below. This is implemented on two pages. but some time it stop scanning. What check need to down to avoid scanning to stop
private bool InitReader()
{
try
{
// If reader is already present then fail initialize
if ( this.Field ServiceReader != null )
{
//MessageBox.Show(myDataTable.Rows.Count + " records found");
return false;
}
try
{
// Get selected device from user
Symbol.Generic.Device MyDevice =
Symbol.StandardForms.SelectDevice.Select(
Symbol.Barcode.Device.Title,
Symbol.Barcode.Device.AvailableDevices);
if ( MyDevice == null )
{
MessageBox.Show("No Device Selected","SelectDevice");
return false;
}
// Create the reader, based on selected device
this.Field ServiceReader = new Symbol.Barcode.Reader(MyDevice);
// Create reader data
this.Field ServiceReaderData = new Symbol.Barcode.ReaderData(
Symbol.Barcode.ReaderDataTypes.Text,
Symbol.Barcode.ReaderDataLengths.DefaultText);
// Enable the Reader
this.Field ServiceReader.Actions.Enable();
// Initialize Reader parameters
this.InitReadParams();
// create event handlers
this.MyReadNotifyHandler = new EventHandler(Field ServiceReader_ReadNotify);
this.MyStatusNotifyHandler = new EventHandler(Field ServiceReader_StatusNotify);
this.Activated +=new EventHandler(frmVwWorkOrders_Activated);
this.Deactivate +=new EventHandler(frmVwWorkOrders_Deactivate);
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
MessageBox.Show("InitReader\n"+"Invalid Operation\n"+ex.Message,"Field Service");
return false;
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("InitReader\n"+"Operation Failure"+ex.Message,"Field Service");
return false;
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("InitReader\n"+"Unimplemented Function"+ex.Message,"Field Service");
return false;
}
}
catch(Exception es)
{
MessageBox.Show(es.ToString(),"Field Service");
return false;
}
return true;
}
private void InitReadParams()
{
this.MyReadParamsList = new object[2];
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
// Terminate reader, call base class
//this.TermReader();
base.OnClosing(e);
}
private void TermReader()
{
try
{
// If we have a reader
if ( this.Field ServiceReader != null )
{
// stop all notifications
this.StopRead();
this.StopStatus();
try
{
if ( this.Field ServiceReader != null )
{
// Disable the reader
this.Field ServiceReader.Actions.Disable();
// Free it up
this.Field ServiceReader.Dispose();
// Indicate we no longer have one
this.Field ServiceReader = null;
}
if ( this.Field ServiceReaderData != null )
{
// Free it up
this.Field ServiceReaderData.Dispose();
// Indicate we no longer have one
this.Field ServiceReaderData = null;
}
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
MessageBox.Show("TermReader\n"+"Invalid Operation"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("TermReader\n"+"Operation Failure\n"+"Result = 0x"+
((uint)ex.Result).ToString("X8")+"\n"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("TermReader\n"+"Unimplemented Function"+ex.Message,"Field Service");
}
}
}
catch(Exception es)
{
MessageBox.Show(es.ToString(),"Field Service");
}
}
private void StartRead()
{
// If we have both a reader and a reader data
if ( ( this.Field ServiceReader != null ) &&
( this.Field ServiceReaderData != null ) )
try
{
//this.Field ServiceReader.Changes.Restore(this.MyReadParamsList[this.CurrentReadParamIndex]);
if ( ++this.CurrentReadParamIndex >= this.MyReadParamsList.Length )
{
this.CurrentReadParamIndex = 0;
}
this.Field ServiceReader.ReadNotify += MyReadNotifyHandler;
// Submit a read
this.Field ServiceReader.Actions.Read(this.Field ServiceReaderData);
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("StartRead\n" +
"Unimplemented Function\n" +
ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.InvalidIndexerException ex )
{
MessageBox.Show("StartRead\n"+
"Invalid Indexer\n"+
ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("StopRead\n" +
"Operation Failure\n" +
"Result = 0x" +
((uint)ex.Result).ToString("X8") +
"\n"+
ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
/*MessageBox.Show("StartRead\n"+
"Invalid Request\n"+
ex.Message,"Field Service");*/
string s = ex.Message;
};
}
private void StopRead()
{
// If we do not have a reader, then do nothing
if ( this.Field ServiceReader == null )
{
return;
}
try
{
// Remove read notification handler
this.Field ServiceReader.ReadNotify -= MyReadNotifyHandler;
// Flush (Cancel all pending reads)
this.Field ServiceReader.Actions.Flush();
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
MessageBox.Show("StopRead\n"+"Invalid Operation"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("StopRead\n"+"Operation Failure\n"+"Result = 0x"+
((uint)ex.Result).ToString("X8")+"\n"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("StopRead\n"+"Unimplemented Function\n"+ex.Message,"Field Service");
}
}
private void StartStatus()
{
if( this.Field ServiceReader != null)
{
// Attach status notification handler
this.Field ServiceReader.StatusNotify += this.MyStatusNotifyHandler;
}
}
private bool InitReader()
{
try
{
// If reader is already present then fail initialize
if ( this.Field ServiceReader != null )
{
//MessageBox.Show(myDataTable.Rows.Count + " records found");
return false;
}
try
{
// Get selected device from user
Symbol.Generic.Device MyDevice =
Symbol.StandardForms.SelectDevice.Select(
Symbol.Barcode.Device.Title,
Symbol.Barcode.Device.AvailableDevices);
if ( MyDevice == null )
{
MessageBox.Show("No Device Selected","SelectDevice");
return false;
}
// Create the reader, based on selected device
this.Field ServiceReader = new Symbol.Barcode.Reader(MyDevice);
// Create reader data
this.Field ServiceReaderData = new Symbol.Barcode.ReaderData(
Symbol.Barcode.ReaderDataTypes.Text,
Symbol.Barcode.ReaderDataLengths.DefaultText);
// Enable the Reader
this.Field ServiceReader.Actions.Enable();
// Initialize Reader parameters
this.InitReadParams();
// create event handlers
this.MyReadNotifyHandler = new EventHandler(Field ServiceReader_ReadNotify);
this.MyStatusNotifyHandler = new EventHandler(Field ServiceReader_StatusNotify);
this.Activated +=new EventHandler(frmVwWorkOrders_Activated);
this.Deactivate +=new EventHandler(frmVwWorkOrders_Deactivate);
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
MessageBox.Show("InitReader\n"+"Invalid Operation\n"+ex.Message,"Field Service");
return false;
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("InitReader\n"+"Operation Failure"+ex.Message,"Field Service");
return false;
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("InitReader\n"+"Unimplemented Function"+ex.Message,"Field Service");
return false;
}
}
catch(Exception es)
{
MessageBox.Show(es.ToString(),"Field Service");
return false;
}
return true;
}
private void InitReadParams()
{
this.MyReadParamsList = new object[2];
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
// Terminate reader, call base class
//this.TermReader();
base.OnClosing(e);
}
private void TermReader()
{
try
{
// If we have a reader
if ( this.Field ServiceReader != null )
{
// stop all notifications
this.StopRead();
this.StopStatus();
try
{
if ( this.Field ServiceReader != null )
{
// Disable the reader
this.Field ServiceReader.Actions.Disable();
// Free it up
this.Field ServiceReader.Dispose();
// Indicate we no longer have one
this.Field ServiceReader = null;
}
if ( this.Field ServiceReaderData != null )
{
// Free it up
this.Field ServiceReaderData.Dispose();
// Indicate we no longer have one
this.Field ServiceReaderData = null;
}
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
MessageBox.Show("TermReader\n"+"Invalid Operation"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("TermReader\n"+"Operation Failure\n"+"Result = 0x"+
((uint)ex.Result).ToString("X8")+"\n"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("TermReader\n"+"Unimplemented Function"+ex.Message,"Field Service");
}
}
}
catch(Exception es)
{
MessageBox.Show(es.ToString(),"Field Service");
}
}
private void StartRead()
{
// If we have both a reader and a reader data
if ( ( this.Field ServiceReader != null ) &&
( this.Field ServiceReaderData != null ) )
try
{
//this.Field ServiceReader.Changes.Restore(this.MyReadParamsList[this.CurrentReadParamIndex]);
if ( ++this.CurrentReadParamIndex >= this.MyReadParamsList.Length )
{
this.CurrentReadParamIndex = 0;
}
this.Field ServiceReader.ReadNotify += MyReadNotifyHandler;
// Submit a read
this.Field ServiceReader.Actions.Read(this.Field ServiceReaderData);
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("StartRead\n" +
"Unimplemented Function\n" +
ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.InvalidIndexerException ex )
{
MessageBox.Show("StartRead\n"+
"Invalid Indexer\n"+
ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("StopRead\n" +
"Operation Failure\n" +
"Result = 0x" +
((uint)ex.Result).ToString("X8") +
"\n"+
ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
/*MessageBox.Show("StartRead\n"+
"Invalid Request\n"+
ex.Message,"Field Service");*/
string s = ex.Message;
};
}
private void StopRead()
{
// If we do not have a reader, then do nothing
if ( this.Field ServiceReader == null )
{
return;
}
try
{
// Remove read notification handler
this.Field ServiceReader.ReadNotify -= MyReadNotifyHandler;
// Flush (Cancel all pending reads)
this.Field ServiceReader.Actions.Flush();
}
catch ( Symbol.Exceptions.InvalidRequestException ex )
{
MessageBox.Show("StopRead\n"+"Invalid Operation"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.OperationFailureException ex )
{
MessageBox.Show("StopRead\n"+"Operation Failure\n"+"Result = 0x"+
((uint)ex.Result).ToString("X8")+"\n"+ex.Message,"Field Service");
}
catch ( Symbol.Exceptions.UnimplementedFunctionException ex )
{
MessageBox.Show("StopRead\n"+"Unimplemented Function\n"+ex.Message,"Field Service");
}
}
private void StartStatus()
{
if( this.Field ServiceReader != null)
{
// Attach status notification handler
this.Field ServiceReader.StatusNotify += this.MyStatusNotifyHandler;
}
}