2

我正在使用库中的 EMDK 2.5(VS2008 和 VC# 和 .NetCF3.5)Barcode2 类来编写示例应用程序来扫描条形码。我遵循 EMDK 中可用的示例,即 CS_Barcode2Sample1 项目。每次我硬件触发扫描时,都会抛出通知“E_SCN_READINCOMPATIBLE”并且无法检索扫描的数据。该文档没有太多关于 E_SCN_READINCOMPATIBLE 通知的原因以及谷歌搜索的运气。我尝试了几个选项,包括使用 Symbol.Barcode,结果是一样的。我也试过 EMDK 2.3 但结果是一样的。

我已经在这里粘贴了整个代码......

public partial class Form1 : Form
    {
        private Barcode2 myBarcode2 = null;

        public Form1()
        {
            InitializeComponent();
            InitBarcode();
        }

        public bool InitBarcode()
        {
            // If the Barcode2 object is already initialized then fail the initialization.
            if (myBarcode2 != null)
            {
                return false;
            }
            else // Else initialize the reader.
            {
                try
                {

                    Symbol.Barcode2.Device[] AvailableDevices = Symbol.Barcode2.Devices.SupportedDevices;
                    if (AvailableDevices.Length == 0)
                    {
                        return false;
                    }

                    if (AvailableDevices.Length == 1)
                    {
                        //get the first available scanner in the list
                        Symbol.Barcode2.Device MyDevice = AvailableDevices[0];
                        // Create the reader, based on selected device.
                        myBarcode2 = new Barcode2(MyDevice);

                        // Attach a scan notification handler.
                        //this.myScanNotifyHandler = new Barcode2.OnScanHandler(myBarcode2_ScanNotify);
                        myBarcode2.OnScan += myBarcode2_ScanNotify;

                        // Attach a status notification handler.
                        //this.myStatusNotifyHandler = new Barcode2.OnStatusHandler(myBarcode2_StatusNotify);
                        myBarcode2.OnStatus += myBarcode2_StatusNotify;
                        myBarcode2.Config.TriggerMode = TRIGGERMODES.HARD;

                        // Submit a scan.
                        myBarcode2.Scan(5000);
                      }
                }
                catch (OperationFailureException ex)
                {
                    MessageBox.Show("Exception Raised 1");
                    return false;
                }
                catch (InvalidRequestException ex)
                {
                    MessageBox.Show("Exception Raised 2");
                    return false;
                }
                catch (InvalidIndexerException ex)
                {
                    MessageBox.Show("Exception Raised 3");
                    return false;
                }
            }
            return false;
        }

        private void myBarcode2_ScanNotify(ScanDataCollection scanDataCollection)
        {
            // Checks if the BeginInvoke method is required because the OnScan delegate is called by a different thread
            if (this.InvokeRequired)
            {
                // Executes the OnScan delegate asynchronously on the main thread
                this.BeginInvoke(new Barcode2.OnScanHandler(myBarcode2_ScanNotify), new object[] { scanDataCollection });
            }
            else
            {
                // Get ScanData
                ScanData scanData = scanDataCollection.GetFirst;

                int i;
                switch (scanData.Result)
                {
                    case Symbol.Barcode2.Results.SUCCESS:
                        String str = scanData.Text;
                        myBarcode2.Config.TriggerMode = TRIGGERMODES.HARD;
                        myBarcode2.Scan(5000);
                        break;

                    case Symbol.Barcode2.Results.E_SCN_READTIMEOUT:
                        break;

                    case Symbol.Barcode2.Results.CANCELED:
                        break;

                    case Symbol.Barcode2.Results.E_SCN_DEVICEFAILURE:
                        i = 93;
                        break;

                    default:
                        if (scanData.Result == Symbol.Barcode2.Results.E_SCN_READINCOMPATIBLE)
                        {
                            // If the failure is E_SCN_READINCOMPATIBLE, exit the application.
                            MessageBox.Show("Fatal Error");
                            this.Close();
                            return;
                        }
                        break;
                }
            }
        }

        private void myBarcode2_StatusNotify(StatusData statusData)
        {
            // Checks if the Invoke method is required because the OnStatus delegate is called by a different thread
            if (this.InvokeRequired)
            {
                // Executes the OnStatus delegate on the main thread
                this.Invoke(new Barcode2.OnStatusHandler(myBarcode2_StatusNotify), new object[] { statusData });
            }
            else
            {
                int i;
                switch (statusData.State)
                {
                    case States.IDLE:
                        break;

                    case States.READY:
                        break;

                    default:
                        break;
                }
            }
        }
    }
}
4

1 回答 1

3

我最近也经历过这个,正如我所观察到的,这可能是由于扫描仪设备被其他应用程序占用,扫描请求已经排队,你可以去内存管理,杀死可疑的应用程序,然后尝试你的应用程序。

请参阅符号常见问题解答

于 2012-10-05T02:36:55.720 回答