Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends

I am facing "value cannot be null" problem for a barcode scanner.

And the exception occurs at this.scanner =(Scanner)explorer.CreateInstance(device);

pointing to device.

It would be great if can get any help to resolve this
C#
class bScan
{
    public PosExplorer explorer;
    public  Scanner scanner;
    string BarCodeReader;

    public  void  Start_Scan()
    {         
        //  explorer = new PosExplorer();
        // explorer.DeviceAddedEvent += new DeviceChangedEventHandler(explorer_DeviceAddedEvent);
        // var device=explorer.GetDevice(DeviceType.Scanner);
        ;
    }

    public void read()
  //  public   void explorer_DeviceAddedEvent(object sender,DeviceChangedEventArgs e)
    {
        explorer = new PosExplorer();
        DeviceInfo device = explorer.GetDevice("Scanner",BarCodeReader);
        this.scanner =(Scanner)explorer.CreateInstance(device);
        this.scanner.Open();
        this.scanner.Claim(1000);
        this.scanner.DeviceEnabled = true;
        this.scanner.DataEvent += new DataEventHandler(scanner_DataEvent);
        this.scanner.DataEventEnabled = true;
        this.scanner.DecodeData = true;   
    }
        //}
  
    public  void scanner_DataEvent(object sender,DataEventArgs e)
    {
        string data;
        ASCIIEncoding encoding=new ASCIIEncoding();
        scanner.DataEventEnabled=true;         
        data=encoding.GetString(scanner.ScanDataLabel);
        // listBox1.Items.Add(encoding.GetString(scanner.ScanDataLabel));     
    }

}
Posted
Updated 16-Nov-15 19:54pm
v2

1 solution

Well, the most likely problem is that this line returns null.
C#
DeviceInfo device = explorer.GetDevice("Scanner",BarCodeReader);

Then you get an error on the next line
C#
this.scanner = (Scanner)explorer.CreateInstance(device);

And that is kind of an expected error if you send null as a parameter.

Should the variable BarCodeReader have a value?
As far as I can see it is not initialized, so what happens if you send an empty string or null?

The problem is we don't know what you have installed or not on your computer, so it is difficult to give any more exact help.

[UPDATE]
Here is some configuration documentation for POS v1.14. It should be similar to your version, I think, or you can download and install the new version.
Manually managing POS for .NET devices[^]
It is never bad to read the documentation.
 
Share this answer
 
v2
Comments
sarath para 17-Nov-15 10:30am    
Hi Jonsson
Installed POS.NETV1.12.But it does not show up in HKEY_LOCAL_MACHINE/SOFTWARE/.
One more isssue is Deviice event handler did not work so I have commented that portion of code.Is there any configuration xml file I need to update.

Thanks
George Jonsson 17-Nov-15 19:49pm    
See my updated answer.
sarath para 23-Nov-15 3:25am    
I working out this one for XP service pack2 so i have to use v1.12 but I will give a try on documentation and check thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900