- Joined
- Jun 22, 2007
- Messages
- 3
- Reaction score
- 0
Hi,
I am .NET developer and recently I have got chance to work on Windows Mobile 5.0 and very first application I have got is to scan barcode using symbol MC70 device. I grade my self as a beginner in WM 5.0.
So far I have installed Symbol Mobility SDK 1.5 for .NET and created a prototype for barcode scanning. Inititally I was just testing it on emulator and it was giving me NullReference exception in following line:
barcode1.Reader.Actions.Read(this.symReader);
Then I deployed on actual device, i.e. Symbol MC70 but again result was same.
Now I could not figure out that why its throwing NullReference exception. My code is given below:
I would appreciate if anyone helps me.
Thanks in advance,
My Code:
frmBarcodeScanning.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace BarcodeScanning
{
public partial class frmBarcodeScanning : Form
{
private Symbol.Barcode.ReaderData symReader;
public frmBarcodeScanning()
{
InitializeComponent();
}
privatevoid menuItem1_Click(object sender, EventArgs e)
{
this.Close();
}
privatevoid button1_Click(object sender, EventArgs e)
{
}
privatevoid barcode1_OnStatus(object sender, Symbol.Barcode.BarcodeStatus barcodeStatus)
{
label2.Text += barcodeStatus.Text;
}
privatevoid barcode1_OnRead(object sender, Symbol.Barcode.ReaderData readerData)
{
try
{
switch (readerData.Result)
{
case Symbol.Results.SUCCESS:
listBox1.Items.Add("Barcode Device: " + readerData.Source.ToString());
listBox1.Items.Add("Data Read: " + readerData.Text.ToString());
listBox1.Items.Add("------------------");
this.ReadData();
break;
default:
listBox1.Items.Add("No data was read.");
listBox1.Items.Add("Status of Read: " + readerData.Result.ToString());
listBox1.Items.Add("------------------");
break;
}
}
catch (Exception ex)
{
listBox1.Items.Add(ex.Message.ToString());
listBox1.Items.Add("------------------");
}
}
privatebool InitReader()
{
try
{
this.symReader = new Symbol.Barcode.ReaderData (Symbol.Barcode.ReaderDataTypes.Text, Symbol.Barcode.ReaderDataLengths.MaximumLabel);
barcode1.EnableScanner = true;
returntrue;
}
catch (Exception ex)
{
returnfalse;
}
}
privatevoid ReadData()
{
barcode1.Reader.Actions.Read(this.symReader);
}
privatevoid cmdRead2_Click(object sender, EventArgs e)
{
barcode1.Reader.Actions.ToggleSoftTrigger();
}
privatevoid cmdRead3_Click(object sender, EventArgs e)
{
barcode1.Reader.Actions.Flush();
}
privatevoid frmBarcodeScanning_Load(object sender, EventArgs e)
{
if (this.InitReader())
{
this.ReadData();
}
}
privatevoid label2_ParentChanged(object sender, EventArgs e)
{
}
}
}
Regards,
Naimish
I am .NET developer and recently I have got chance to work on Windows Mobile 5.0 and very first application I have got is to scan barcode using symbol MC70 device. I grade my self as a beginner in WM 5.0.
So far I have installed Symbol Mobility SDK 1.5 for .NET and created a prototype for barcode scanning. Inititally I was just testing it on emulator and it was giving me NullReference exception in following line:
barcode1.Reader.Actions.Read(this.symReader);
Then I deployed on actual device, i.e. Symbol MC70 but again result was same.
Now I could not figure out that why its throwing NullReference exception. My code is given below:
I would appreciate if anyone helps me.
Thanks in advance,
My Code:
frmBarcodeScanning.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace BarcodeScanning
{
public partial class frmBarcodeScanning : Form
{
private Symbol.Barcode.ReaderData symReader;
public frmBarcodeScanning()
{
InitializeComponent();
}
privatevoid menuItem1_Click(object sender, EventArgs e)
{
this.Close();
}
privatevoid button1_Click(object sender, EventArgs e)
{
}
privatevoid barcode1_OnStatus(object sender, Symbol.Barcode.BarcodeStatus barcodeStatus)
{
label2.Text += barcodeStatus.Text;
}
privatevoid barcode1_OnRead(object sender, Symbol.Barcode.ReaderData readerData)
{
try
{
switch (readerData.Result)
{
case Symbol.Results.SUCCESS:
listBox1.Items.Add("Barcode Device: " + readerData.Source.ToString());
listBox1.Items.Add("Data Read: " + readerData.Text.ToString());
listBox1.Items.Add("------------------");
this.ReadData();
break;
default:
listBox1.Items.Add("No data was read.");
listBox1.Items.Add("Status of Read: " + readerData.Result.ToString());
listBox1.Items.Add("------------------");
break;
}
}
catch (Exception ex)
{
listBox1.Items.Add(ex.Message.ToString());
listBox1.Items.Add("------------------");
}
}
privatebool InitReader()
{
try
{
this.symReader = new Symbol.Barcode.ReaderData (Symbol.Barcode.ReaderDataTypes.Text, Symbol.Barcode.ReaderDataLengths.MaximumLabel);
barcode1.EnableScanner = true;
returntrue;
}
catch (Exception ex)
{
returnfalse;
}
}
privatevoid ReadData()
{
barcode1.Reader.Actions.Read(this.symReader);
}
privatevoid cmdRead2_Click(object sender, EventArgs e)
{
barcode1.Reader.Actions.ToggleSoftTrigger();
}
privatevoid cmdRead3_Click(object sender, EventArgs e)
{
barcode1.Reader.Actions.Flush();
}
privatevoid frmBarcodeScanning_Load(object sender, EventArgs e)
{
if (this.InitReader())
{
this.ReadData();
}
}
privatevoid label2_ParentChanged(object sender, EventArgs e)
{
}
}
}
Regards,
Naimish
Last edited: