Imaging problems with ES400

R Rrichard Pilton 3 years 6 months ago
0 1 0

We’re using the EMDK 2.5’s Symbol.Barcode2 library to read barcodes in scan (as opposed to e.g. “scan continuous”) mode, having followed the CS_Barcode2Sample1 code sample that comes with the EMDK. Our barcode API class is currently a direct copy of the one that’s in the sample, whereas our API consumer looks like:

 

// lots of usings ommitted for brevity

using Symbol.Barcode2;

namespace OurProject.Forms

{

    public partial class OurForm

    {

        // Locals

        private OurProject.API.BarcodeReader barcodeReader = null;

        private Barcode2.OnScanHandler myScanNotifyHandler = null;

       

        // Constructor

        public OurForm()

        {

            InitializeComponent();

            StartReader();

        }

       

        // load event handler

        private void Form_Load(object sender, EventArgs e)

        {

            this.barcodeReader = new OurProject.API.BarcodeReader();

        }

        // barcode scanned event handler

        private void barcodeReader_ScanNotify(ScanDataCollection scanDataCollection)

        {

            ScanData scanData = scanDataCollection.GetFirst;

            switch (scanData.Result)

            {

                case Results.SUCCESS:

                    doScanBarcode(scanData.Text);

                    barcodeReader.StartScan(false);

                    break;

                case Results.E_SCN_READTIMEOUT:

                    barcodeReader.StartScan(false);

                    break;

                case Results.CANCELED:

                    break;

                case Results.E_SCN_DEVICEFAILURE:

                    barcodeReader.StopScan();

                    barcodeReader.StartScan(false);

                    break;

            }

        }

        // start the reader - called when this form loads and by any child forms just before they close themselves

        public void StartReader()

        {

            try

            {

                if (barcodeReader.InitBarcode())

                {

                    barcodeReader.StartScan(false);

                    this.myScanNotifyHandler = new Barcode2.OnScanHandler(barcodeReader_ScanNotify);

                    barcodeReader.AttachScanNotify(myScanNotifyHandler);

                }

                else

                {

                    MessageBox.Show("cant init reader");

                }

            }

            catch (Exception ex)

            {

            }

        }

        // stop the reader - called when this form onloads and immediately before any child form is shown

        public void StopReader()

        {

            barcodeReader.TermBarcode();

        }

        // we just scanned a barcode - called by barcode scanned event handler

        public void doScanBarcode(string barcode)

        {

            MessageBox.Show("you scanned " + barcode);

        }

    }

}

The reason for stopping the reader before opening any child form (as noted in the comments above) is that this has proved necessary in order to get access to the phone’s camera from the child form. This has proved extremely difficult, with the following approaches tried and failed:

 

Symbol.Imaging and Symbol.Imaging2: doesn’t work on ES400 due to lack of ImgApi32.dll

Windows.Mobile.Forms.CameraCaptureDialog: throws up an error message (which can’t be read because it’s behind a flickering form) on call to ShowDialog(). Our code is as follows:

      private void pictureButton_Click(object sender, EventArgs e)

      {

            CameraCaptureDialog cameraCapture = new CameraCaptureDialog();

            cameraCapture.Owner = this.pictureButton;

            cameraCapture.InitialDirectory = @"\My Documents";

            cameraCapture.DefaultFileName = "picture.jpg";

            cameraCapture.Mode = CameraCaptureMode.Still;

            cameraCapture.StillQuality = CameraCaptureStillQuality.Low;

            object cameraEnabled = SystemState.GetValue(SystemProperty.CameraEnabled);

            if (null != cameraEnabled && 0 == (int)cameraEnabled)

            {

                MessageBox.Show("The camera is disabled", "Camera error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);

                return;

            }

            else

            {

                // Displays the "Camera Capture" dialog box

                if (DialogResult.OK == cameraCapture.ShowDialog())

                {

                    // the picture was taken OK so load it in and pass it to the pictureButton control

                    string fileName = cameraCapture.FileName;

                    using (FileStream reader = new FileStream(fileName, FileMode.Open))

                    {

                        byte[] data = new byte[reader.Length];

                        reader.Read(data, 0, (int)reader.Length);

                        // data should now be byte array with jpeg file in it

                        // so convert it to base64

                        this.pictureButton.setPictureString(Convert.ToBase64String(data));

                        this.pictureButton.setImage((Image)Mobilize.Properties.Resources.winphoneimage_taken);

                    }

                }

            }

       }

 

DirectShow (using DirectShowNETCF): This is the nearest we’ve got to success. We see the camera viewfinder and even get a still image saved. However, when closing the form and attempting the restart the barcode reader on our API consumer (above) by calling the public StartReader() method, the following error message is shown:

 

InitBarcode OperationFailure SCAN_Enable: The device could not be started. Result = E_SCN_CATSTARTDEVICE.

 

Exiting and restarting the application following this error clears the problem and the barcode scanner can be initialised again. Opening any other child form (having first called StopReader()) and closing back to our API consumer (having first called StartReader()) works fine – it’s only accessing the phone’s camera from the child form that causes the SCAN_Enable error message.

 

A very important point to note here is that our primary requirement is to have a C# application that can reliably scan barcodes when the trigger is pressed and can take photographs. The barcode scanning seems to be quite stable. We need a method to programmatically allow taking a photograph that will subsequently allow restarting of the barcode scanner.

Please Register or Login to post a reply

1 Replies

E Elvis Hsu

I used to have this issue before either using DirectShow or the NET image capture dialog. The best way to do it is to terminate the scan engine when you start to take photos. When finishes or cancel taking photos, initialize the scan engine again. Well, it works for me with any version of EMDK (Barcode or Barcode2).

CONTACT
Can’t find what you’re looking for?