public static String getBarcodeName(MWResult result)
        {
            String typeName = "Unknown";
                if (result.type == Scanner.FOUND_128) typeName = "Code 128";
                if (result.type == Scanner.FOUND_39) typeName = "Code 39";
                if (result.type == Scanner.FOUND_DM) typeName = "Datamatrix";
                if (result.type == Scanner.FOUND_EAN_13) typeName = "EAN 13";
                if (result.type == Scanner.FOUND_EAN_8) typeName = "EAN 8";
                if (result.type == Scanner.FOUND_NONE) typeName = "None";
                if (result.type == Scanner.FOUND_RSS_14) typeName = "Databar 14";
                if (result.type == Scanner.FOUND_RSS_14_STACK) typeName = "Databar 14 Stacked";
                if (result.type == Scanner.FOUND_RSS_EXP) typeName = "Databar Expanded";
                if (result.type == Scanner.FOUND_RSS_LIM) typeName = "Databar Limited";
                if (result.type == Scanner.FOUND_UPC_A) typeName = "UPC A";
                if (result.type == Scanner.FOUND_UPC_E) typeName = "UPC E";
                if (result.type == Scanner.FOUND_PDF) typeName = "PDF417";
                if (result.type == Scanner.FOUND_QR) typeName = "QR";
                if (result.type == Scanner.FOUND_AZTEC) typeName = "Aztec";
                if (result.type == Scanner.FOUND_25_INTERLEAVED) typeName = "Code 25 Interleaved";
                if (result.type == Scanner.FOUND_25_STANDARD) typeName = "Code 25 Standard";
                if (result.type == Scanner.FOUND_93) typeName = "Code 93";
                if (result.type == Scanner.FOUND_CODABAR) typeName = "Codabar";
                if (result.type == Scanner.FOUND_DOTCODE) typeName = "Dotcode";
                if (result.type == Scanner.FOUND_128_GS1) typeName = "Code 128 GS1";
                if (result.type == Scanner.FOUND_ITF14) typeName = "ITF 14";
                if (result.type == Scanner.FOUND_11) typeName = "Code 11";
                if (result.type == Scanner.FOUND_MSI) typeName = "MSI Plessey";
                if (result.type == Scanner.FOUND_25_IATA) typeName = "IATA Code 25";

                if (result.isGS1)
                {
                    typeName += " (GS1)";
                }

                return typeName;
        }
        public MWResults(byte[] buffer)
        {
            results = new List<MWResult>();
                count = 0;
                version = 0;

                if (buffer[0] != 'M' || buffer[1] != 'W' || buffer[2] != 'R')
                {
                    return;
                }

                version = buffer[3];

                count = buffer[4];

                int currentPos = 5;

                for (int i = 0; i < count; i++)
                {

                    MWResult result = new MWResult();

                    int fieldsCount = buffer[currentPos];
                    currentPos++;
                    for (int f = 0; f < fieldsCount; f++)
                    {
                        int fieldType = buffer[currentPos];
                        int fieldNameLength = buffer[currentPos + 1];
                        int fieldContentLength = 256 * (buffer[currentPos + 3 + fieldNameLength] & 0xFF) + (buffer[currentPos + 2 + fieldNameLength] & 0xFF);
                        String fieldName = null;

                        if (fieldNameLength > 0)
                        {
                            fieldName = Encoding.UTF8.GetString(buffer, currentPos + 2, fieldNameLength);
                        }

                        int contentPos = currentPos + fieldNameLength + 4;
                        float[] locations = new float[8];
                        if (fieldType == Scanner.MWB_RESULT_FT_TYPE)
                        {
                            result.type = BitConverter.ToInt32(buffer, contentPos);
                        }
                        else
                            if (fieldType == Scanner.MWB_RESULT_FT_SUBTYPE)
                            {
                                result.subtype = BitConverter.ToInt32(buffer, contentPos);
                            }
                            else
                                if (fieldType == Scanner.MWB_RESULT_FT_ISGS1)
                                {
                                    result.isGS1 = BitConverter.ToInt32(buffer, contentPos) == 1;
                                }
                                else
                                    if (fieldType == Scanner.MWB_RESULT_FT_IMAGE_WIDTH)
                                    {
                                        result.imageWidth = BitConverter.ToInt32(buffer, contentPos);
                                    }
                                    else
                                        if (fieldType == Scanner.MWB_RESULT_FT_IMAGE_HEIGHT)
                                        {
                                            result.imageHeight = BitConverter.ToInt32(buffer, contentPos);
                                        }
                                        else
                                            if (fieldType == Scanner.MWB_RESULT_FT_LOCATION)
                                            {
                                                for (int l = 0; l < 8; l++)
                                                {
                                                    locations[l] = BitConverter.ToSingle(buffer, contentPos + l * 4);
                                                }
                                                result.locationPoints = new MWLocation(locations);
                                            }
                                            else
                                                if (fieldType == Scanner.MWB_RESULT_FT_TEXT)
                                                {
                                                    result.text = Encoding.UTF8.GetString(buffer, contentPos, fieldContentLength);
                                                }
                                                else
                                                    if (fieldType == Scanner.MWB_RESULT_FT_BYTES)
                                                    {
                                                        result.bytes = new byte[fieldContentLength];
                                                        result.bytesLength = fieldContentLength;
                                                        for (int c = 0; c < fieldContentLength; c++)
                                                        {
                                                            result.bytes[c] = buffer[contentPos + c];
                                                        }
                                                    }

                        currentPos += (fieldNameLength + fieldContentLength + 4);

                    }

                    results.Add(result);

                }
        }
        public static String getBarcodeName(MWResult result)
        {
            String typeName = "Unknown";

            if (result.type == Scanner.FOUND_128)
            {
                typeName = "Code 128";
            }
            if (result.type == Scanner.FOUND_39)
            {
                typeName = "Code 39";
            }
            if (result.type == Scanner.FOUND_DM)
            {
                typeName = "Datamatrix";
            }
            if (result.type == Scanner.FOUND_EAN_13)
            {
                typeName = "EAN 13";
            }
            if (result.type == Scanner.FOUND_EAN_8)
            {
                typeName = "EAN 8";
            }
            if (result.type == Scanner.FOUND_NONE)
            {
                typeName = "None";
            }
            if (result.type == Scanner.FOUND_RSS_14)
            {
                typeName = "Databar 14";
            }
            if (result.type == Scanner.FOUND_RSS_14_STACK)
            {
                typeName = "Databar 14 Stacked";
            }
            if (result.type == Scanner.FOUND_RSS_EXP)
            {
                typeName = "Databar Expanded";
            }
            if (result.type == Scanner.FOUND_RSS_LIM)
            {
                typeName = "Databar Limited";
            }
            if (result.type == Scanner.FOUND_UPC_A)
            {
                typeName = "UPC A";
            }
            if (result.type == Scanner.FOUND_UPC_E)
            {
                typeName = "UPC E";
            }
            if (result.type == Scanner.FOUND_PDF)
            {
                typeName = "PDF417";
            }
            if (result.type == Scanner.FOUND_QR)
            {
                typeName = "QR";
            }
            if (result.type == Scanner.FOUND_AZTEC)
            {
                typeName = "Aztec";
            }
            if (result.type == Scanner.FOUND_25_INTERLEAVED)
            {
                typeName = "Code 25 Interleaved";
            }
            if (result.type == Scanner.FOUND_25_STANDARD)
            {
                typeName = "Code 25 Standard";
            }
            if (result.type == Scanner.FOUND_93)
            {
                typeName = "Code 93";
            }
            if (result.type == Scanner.FOUND_CODABAR)
            {
                typeName = "Codabar";
            }
            if (result.type == Scanner.FOUND_DOTCODE)
            {
                typeName = "Dotcode";
            }
            if (result.type == Scanner.FOUND_128_GS1)
            {
                typeName = "Code 128 GS1";
            }
            if (result.type == Scanner.FOUND_ITF14)
            {
                typeName = "ITF 14";
            }
            if (result.type == Scanner.FOUND_11)
            {
                typeName = "Code 11";
            }
            if (result.type == Scanner.FOUND_MSI)
            {
                typeName = "MSI Plessey";
            }
            if (result.type == Scanner.FOUND_25_IATA)
            {
                typeName = "IATA Code 25";
            }
            if (result.type == Scanner.FOUND_25_MATRIX)
            {
                typeName = "Code 2/5 Matrix";
            }
            if (result.type == Scanner.FOUND_25_COOP)
            {
                typeName = "Code 2/5 COOP";
            }
            if (result.type == Scanner.FOUND_25_INVERTED)
            {
                typeName = "Code 2/5 Inverted";
            }
            if (result.type == Scanner.FOUND_QR_MICRO)
            {
                typeName = "QR Micro";
            }
            if (result.type == Scanner.FOUND_MAXICODE)
            {
                typeName = "Maxicode";
            }
            if (result.type == Scanner.FOUND_POSTNET)
            {
                typeName = "Postnet";
            }
            if (result.type == Scanner.FOUND_PLANET)
            {
                typeName = "Planet";
            }
            if (result.type == Scanner.FOUND_IMB)
            {
                typeName = "Intelligent mail";
            }
            if (result.type == Scanner.FOUND_ROYALMAIL)
            {
                typeName = "Royal mail";
            }


            return(typeName);
        }
        public MWResults(byte[] buffer)
        {
            results = new List <MWResult>();
            count   = 0;
            version = 0;

            if (buffer[0] != 'M' || buffer[1] != 'W' || buffer[2] != 'R')
            {
                return;
            }

            version = buffer[3];

            count = buffer[4];

            int currentPos = 5;

            for (int i = 0; i < count; i++)
            {
                MWResult result = new MWResult();

                int fieldsCount = buffer[currentPos];
                currentPos++;
                for (int f = 0; f < fieldsCount; f++)
                {
                    int    fieldType          = buffer[currentPos];
                    int    fieldNameLength    = buffer[currentPos + 1];
                    int    fieldContentLength = 256 * (buffer[currentPos + 3 + fieldNameLength] & 0xFF) + (buffer[currentPos + 2 + fieldNameLength] & 0xFF);
                    String fieldName          = null;

                    if (fieldNameLength > 0)
                    {
                        fieldName = Encoding.UTF8.GetString(buffer, currentPos + 2, fieldNameLength);
                    }

                    int     contentPos = currentPos + fieldNameLength + 4;
                    float[] locations  = new float[8];
                    if (fieldType == Scanner.MWB_RESULT_FT_TYPE)
                    {
                        result.type = BitConverter.ToInt32(buffer, contentPos);
                    }
                    else
                    if (fieldType == Scanner.MWB_RESULT_FT_SUBTYPE)
                    {
                        result.subtype = BitConverter.ToInt32(buffer, contentPos);
                    }
                    else
                    if (fieldType == Scanner.MWB_RESULT_FT_ISGS1)
                    {
                        result.isGS1 = BitConverter.ToInt32(buffer, contentPos) == 1;
                    }
                    else
                    if (fieldType == Scanner.MWB_RESULT_FT_IMAGE_WIDTH)
                    {
                        result.imageWidth = BitConverter.ToInt32(buffer, contentPos);
                    }
                    else
                    if (fieldType == Scanner.MWB_RESULT_FT_IMAGE_HEIGHT)
                    {
                        result.imageHeight = BitConverter.ToInt32(buffer, contentPos);
                    }
                    else
                    if (fieldType == Scanner.MWB_RESULT_FT_LOCATION)
                    {
                        for (int l = 0; l < 8; l++)
                        {
                            locations[l] = BitConverter.ToSingle(buffer, contentPos + l * 4);
                        }
                        result.locationPoints = new MWLocation(locations);
                    }
                    else
                    if (fieldType == Scanner.MWB_RESULT_FT_TEXT)
                    {
                        result.text = Encoding.UTF8.GetString(buffer, contentPos, fieldContentLength);
                    }
                    else
                    if (fieldType == Scanner.MWB_RESULT_FT_BYTES)
                    {
                        result.bytes       = new byte[fieldContentLength];
                        result.bytesLength = fieldContentLength;
                        for (int c = 0; c < fieldContentLength; c++)
                        {
                            result.bytes[c] = buffer[contentPos + c];
                        }
                    }
                    else if (fieldType == Scanner.MWB_RESULT_FT_PARSER_BYTES)
                    {
                        result.encryptedResult = new byte[fieldContentLength + 1];
                        result.encryptedResult[fieldContentLength] = 0;
                        Buffer.BlockCopy(buffer, contentPos, result.encryptedResult, 0, fieldContentLength);
                    }



                    currentPos += (fieldNameLength + fieldContentLength + 4);
                }


                results.Add(result);
            }
        }
        public static String getBarcodeName(MWResult result)
        {
            String typeName = "Unknown";

            if (result.type == Scanner.FOUND_128)
            {
                typeName = "Code 128";
            }
            if (result.type == Scanner.FOUND_39)
            {
                typeName = "Code 39";
            }
            if (result.type == Scanner.FOUND_DM)
            {
                typeName = "Datamatrix";
            }
            if (result.type == Scanner.FOUND_EAN_13)
            {
                typeName = "EAN 13";
            }
            if (result.type == Scanner.FOUND_EAN_8)
            {
                typeName = "EAN 8";
            }
            if (result.type == Scanner.FOUND_NONE)
            {
                typeName = "None";
            }
            if (result.type == Scanner.FOUND_RSS_14)
            {
                typeName = "Databar 14";
            }
            if (result.type == Scanner.FOUND_RSS_14_STACK)
            {
                typeName = "Databar 14 Stacked";
            }
            if (result.type == Scanner.FOUND_RSS_EXP)
            {
                typeName = "Databar Expanded";
            }
            if (result.type == Scanner.FOUND_RSS_LIM)
            {
                typeName = "Databar Limited";
            }
            if (result.type == Scanner.FOUND_UPC_A)
            {
                typeName = "UPC A";
            }
            if (result.type == Scanner.FOUND_UPC_E)
            {
                typeName = "UPC E";
            }
            if (result.type == Scanner.FOUND_PDF)
            {
                typeName = "PDF417";
            }
            if (result.type == Scanner.FOUND_QR)
            {
                typeName = "QR";
            }
            if (result.type == Scanner.FOUND_AZTEC)
            {
                typeName = "Aztec";
            }
            if (result.type == Scanner.FOUND_25_INTERLEAVED)
            {
                typeName = "Code 25 Interleaved";
            }
            if (result.type == Scanner.FOUND_25_STANDARD)
            {
                typeName = "Code 25 Standard";
            }
            if (result.type == Scanner.FOUND_93)
            {
                typeName = "Code 93";
            }
            if (result.type == Scanner.FOUND_CODABAR)
            {
                typeName = "Codabar";
            }
            if (result.type == Scanner.FOUND_DOTCODE)
            {
                typeName = "Dotcode";
            }
            if (result.type == Scanner.FOUND_128_GS1)
            {
                typeName = "Code 128 GS1";
            }
            if (result.type == Scanner.FOUND_ITF14)
            {
                typeName = "ITF 14";
            }
            if (result.type == Scanner.FOUND_11)
            {
                typeName = "Code 11";
            }
            if (result.type == Scanner.FOUND_MSI)
            {
                typeName = "MSI Plessey";
            }
            if (result.type == Scanner.FOUND_25_IATA)
            {
                typeName = "IATA Code 25";
            }


            return(typeName);
        }