Вопрос

i've got problems with the barcode scanner MT2070 from Motorola. I use the EMDK 2.6 for .NET(Update 2) to create strings from the scanned barcode, then transmit them to the host pc. But the transmit failed.

The MT2070 run with Windows CE5.0 and is connected over bluetooth to the cradle STB2078. But everytime i get "send failed" and the ResultCode is "E_INCORRECT_MODE".

The problem is that dont understand what they mean with "INCORRECT_MODE" i set it to DECODE and by RawData what is mean with source?

        ScannerServicesClient scannerServices;
        scannerServices = new ScannerServicesClient();
        SCANNERSVC_MODE mode;

        if(scannerServices.Connect(true))
        {
            Logger("start service with decode rights"); // primitiv method to see what happen

            scannerServices.GetMode(out mode);

            if (mode != SCANNERSVC_MODE.SVC_MODE_DECODE)
            {
                mode = SCANNERSVC_MODE.SVC_MODE_DECODE;
                if (scannerServices.SetMode(mode) != RESULTCODE.E_OK)
                {
                    Logger("cant set mode: " + mode.ToString());
                }
            }

            // wanna know which connection is use
            string connection = "";

            switch (scannerServices.HostParameters.CurrentConnection)
            {
                case SCANNERSVC_DATA_CONNECTION.NO_CONNECTION:
                    connection = "Not connected";
                    break;
                case SCANNERSVC_DATA_CONNECTION.BLUETOOTH:
                    connection = scannerServices.HostParameters.BluetoothConnection.ToString();
                    break;
                case SCANNERSVC_DATA_CONNECTION.RS232:
                    connection = scannerServices.HostParameters.RS232Connection.ToString();
                    break;
                case SCANNERSVC_DATA_CONNECTION.USB_CABLE:
                    connection = scannerServices.HostParameters.USBConnection.ToString();
                    break;
            }
            Logger(connection);

            ScannerHostParameters scnHost = new ScannerHostParameters(scannerServices);



            //example hello
            string input = "hello";                     //what should send
            byte[] output = new byte[input.Length];     //field with converted data
            byte source = 0;    //<-- what mean source? i sum all byte-value but this cant be correct

            for (int i = 0; i < input.Length; ++i)
            {
                output[i] = Convert.ToByte(input[i]);
                source += output[i];
            }

            RawData rawData = new RawData(output, input.Length, source);
            //RawParameters rawParam = new RawParameters();

            //rawParam.BaudRate = RawParameters.RawBaudRates.RAWSERIAL_9600;
            //rawParam.Type = RawParameters.RawHostType.Auto;

            RESULTCODE result = scannerServices.SendRawData(rawData, 2000);

            if(result == RESULTCODE.E_OK)
            {
                Logger("successful send");
            }
            else
            {
                Logger("Send failed: " + result.ToString());
            }
            Logger("ScannerService kill");
            scannerServices.Disconnect();
        }
        Logger("\n");
        scannerServices.Dispose();

        scannerServices = null;

Thanks for your help! (and sorry for my english)

Это было полезно?

Решение

At some point (somewhere where you're setting the mode - I do it right after setting the mode) you'll want to do this:

//set raw mode
if (RESULTCODE.E_OK != scannerServices.SetAttributeByte((ushort)ATTRIBUTE_NUMBER.ATT_MIA_HOSTNUM, (byte)ENUM_HOSTS.HOST_RAW))
{
    throw new Exception("Can't set RAW mode");
    scannerServices.Disconnect();
    scannerServices.Dispose();
    return;
}

Where you have:

RawData rawData = new RawData(output, input.Length, source);

you can leave source as 0:

RawData rawData = new RawData(output, input.Length, 0);

Unfortunately I'm not the greatest when it comes to programming so I've only managed to stumble my way through getting my scanner to work. The documentation isn't great, in fact I find it severly lacking. Even the people at Motorola don't seem to know much about it or how to program it. I've been given misinformation by them on on at least one point.

I use the CDC COM Port Emulation mode for the scanner so that it shows up under Ports in Device Manager (I need the scanner to work with an old program we have which uses COM ports). A driver is also needed for this.

Depending on how you're using the scanner, the above may or may not work.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top