Exemple #1
0
        internal bool ValidateMessage(byte[] Baf, int bytesToRead, byte SEQ, byte CMD, List <byte> lstB)
        {
            char R_SOH = Convert.ToChar(Baf[0]);
            char R_LEN = Convert.ToChar(Baf[1]);
            char R_SEQ = Convert.ToChar(Baf[2]);
            char R_CMD = Convert.ToChar(Baf[3]);
            char R_ETX = Convert.ToChar(Baf[bytesToRead - 1]);

            byte[] BCCCheckX = new byte[4];
            BCCCheckX[0] = Baf[bytesToRead - 5];
            BCCCheckX[1] = Baf[bytesToRead - 4];
            BCCCheckX[2] = Baf[bytesToRead - 3];
            BCCCheckX[3] = Baf[bytesToRead - 2];

            int px;

            for (px = 4; px <= 200 + 4; px++)
            {
                if (Baf[px] == 0x4)
                {
                    break; // TODO: might not be correct. Was : Exit For
                }
                lstB.Add(Baf[px]);
            }

            List <byte> BCCLIST = new List <byte>();

            for (int xp = px + 1; xp <= px + 6; xp++)
            {
                if (Baf[xp] == 0x5)
                {
                    break; // TODO: might not be correct. Was : Exit For
                }
                BCCLIST.Add((Baf[xp]));
            }

            if (!CheckBCC(lstB.ToArray(), BCCLIST.ToArray(), R_LEN, R_CMD, R_SEQ, BCCCheckX))
            {
                return(false);
            }


            if (R_SEQ != SEQ || R_CMD != CMD || R_ETX != 3)
            {
                return(false);
            }
            else
            {
                StatusCodes = new List <BYTEN>();
                for (int i = 1; i < BCCLIST.Count + 1; i++)
                {
                    StatusCodes.Add(BYTEN.SetFlags(BCCLIST[i - 1], i - 1));
                }

                return(true);
            }
        }
Exemple #2
0
        public static BYTEN SetFlags(int code, int byteNum)
        {
            string BinaryCode = Convert.ToString(code, 2);
            BYTEN  xByte      = new BYTEN();

            switch (byteNum)
            {
            case 0:
                xByte = new BYTEN
                {
                    ByteN = byteNum,
                    Seven = new StatusFlag
                    {
                        BYTENO          = 7,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(0) == '1' ? true : false
                    },
                    Six = new StatusFlag
                    {
                        BYTENO          = 6,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(1) == '1' ? true : false
                    },
                    Five = new StatusFlag
                    {
                        BYTENO          = 5,
                        GeneralFunction = "OR of all errors with *from bytes 0, 1, 2 – general error",
                        Flag            = BinaryCode.ElementAt(2) == '1' ? true : false
                    },
                    Four = new StatusFlag
                    {
                        BYTENO          = 4,
                        GeneralFunction = "Printing mechanism error",
                        Flag            = BinaryCode.ElementAt(3) == '1' ? true : false
                    },
                    Three = new StatusFlag
                    {
                        BYTENO          = 3,
                        GeneralFunction = "No external display",
                        Flag            = BinaryCode.ElementAt(4) == '1' ? true : false
                    },
                    Two = new StatusFlag
                    {
                        BYTENO          = 2,
                        GeneralFunction = "Date and time are not set",
                        Flag            = BinaryCode.ElementAt(5) == '1' ? true : false
                    },
                    One = new StatusFlag
                    {
                        BYTENO          = 1,
                        GeneralFunction = "Invalid command",
                        Flag            = BinaryCode.ElementAt(6) == '1' ? true : false
                    },
                    Zero = new StatusFlag
                    {
                        BYTENO          = 0,
                        GeneralFunction = "Syntactic error",
                        Flag            = BinaryCode.ElementAt(7) == '1' ? true : false
                    }
                };
                break;

            case 1:
                xByte = new BYTEN
                {
                    ByteN = byteNum,
                    Seven = new StatusFlag
                    {
                        BYTENO          = 7,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(0) == '1' ? true : false
                    },
                    Six = new StatusFlag
                    {
                        BYTENO          = 6,
                        GeneralFunction = "Wrong password",
                        Flag            = BinaryCode.ElementAt(1) == '1' ? true : false
                    },
                    Five = new StatusFlag
                    {
                        BYTENO          = 5,
                        GeneralFunction = "Error in cutter",
                        Flag            = BinaryCode.ElementAt(2) == '1' ? true : false
                    },
                    Four = new StatusFlag
                    {
                        BYTENO          = 4,
                        GeneralFunction = "Not used",
                        Flag            = BinaryCode.ElementAt(3) == '1' ? true : false
                    },
                    Three = new StatusFlag
                    {
                        BYTENO          = 3,
                        GeneralFunction = "Not used",
                        Flag            = BinaryCode.ElementAt(4) == '1' ? true : false
                    },
                    Two = new StatusFlag
                    {
                        BYTENO          = 2,
                        GeneralFunction = "Reset memory",
                        Flag            = BinaryCode.ElementAt(5) == '1' ? true : false
                    },
                    One = new StatusFlag
                    {
                        BYTENO          = 1,
                        GeneralFunction = "Prohibited command in current mode",
                        Flag            = BinaryCode.ElementAt(6) == '1' ? true : false
                    },
                    Zero = new StatusFlag
                    {
                        BYTENO          = 0,
                        GeneralFunction = "Overflow of sum fields",
                        Flag            = BinaryCode.ElementAt(7) == '1' ? true : false
                    }
                };
                break;

            case 2:
                xByte = new BYTEN
                {
                    ByteN = byteNum,
                    Seven = new StatusFlag
                    {
                        BYTENO          = 7,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(0) == '1' ? true : false
                    },
                    Six = new StatusFlag
                    {
                        BYTENO          = 6,
                        GeneralFunction = "Print of document is allowed",
                        Flag            = BinaryCode.ElementAt(1) == '1' ? true : false
                    },
                    Five = new StatusFlag
                    {
                        BYTENO          = 5,
                        GeneralFunction = "non-fiscal receipt is opened",
                        Flag            = BinaryCode.ElementAt(2) == '1' ? true : false
                    },
                    Four = new StatusFlag
                    {
                        BYTENO          = 4,
                        GeneralFunction = "Insufficient paper in EJT",
                        Flag            = BinaryCode.ElementAt(3) == '1' ? true : false
                    },
                    Three = new StatusFlag
                    {
                        BYTENO          = 3,
                        GeneralFunction = "Fiscal receipt is opened",
                        Flag            = BinaryCode.ElementAt(4) == '1' ? true : false
                    },
                    Two = new StatusFlag
                    {
                        BYTENO          = 2,
                        GeneralFunction = "No paper (control tape)",
                        Flag            = BinaryCode.ElementAt(5) == '1' ? true : false
                    },
                    One = new StatusFlag
                    {
                        BYTENO          = 1,
                        GeneralFunction = "Not enough paper",
                        Flag            = BinaryCode.ElementAt(6) == '1' ? true : false
                    },
                    Zero = new StatusFlag
                    {
                        BYTENO          = 0,
                        GeneralFunction = "No paper",
                        Flag            = BinaryCode.ElementAt(7) == '1' ? true : false
                    }
                };
                break;

            case 3:     //TODO
                //int ErrCode = Convert.ToInt32(BinaryCode.Substring(1, BinaryCode.Length - 1), 2);
                xByte = new BYTEN
                {
                    ByteN = byteNum,
                    Seven = new StatusFlag
                    {
                        BYTENO          = 7,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(0) == '1' ? true : false
                    },
                    Six = new StatusFlag
                    {
                        BYTENO = 6,
                        // GeneralFunction = ErrorCodes.ContainsKey(ErrCode)? ErrorCodes[ErrCode].Description : ""
                    }
                };
                break;

            case 4:
                xByte = new BYTEN
                {
                    ByteN = byteNum,
                    Seven = new StatusFlag
                    {
                        BYTENO          = 7,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(0) == '1' ? true : false
                    },
                    Six = new StatusFlag
                    {
                        BYTENO          = 6,
                        GeneralFunction = "Not used",
                        Flag            = BinaryCode.ElementAt(1) == '1' ? true : false
                    },
                    Five = new StatusFlag
                    {
                        BYTENO          = 5,
                        GeneralFunction = "OR of all errors with*from bytes 4 and 5– general error",
                        Flag            = BinaryCode.ElementAt(2) == '1' ? true : false
                    },
                    Four = new StatusFlag
                    {
                        BYTENO          = 4,
                        GeneralFunction = "Fiscal memory full",
                        Flag            = BinaryCode.ElementAt(3) == '1' ? true : false
                    },
                    Three = new StatusFlag
                    {
                        BYTENO          = 3,
                        GeneralFunction = "Room for less than 50 records in fiscal memory",
                        Flag            = BinaryCode.ElementAt(4) == '1' ? true : false
                    },
                    Two = new StatusFlag
                    {
                        BYTENO          = 2,
                        GeneralFunction = "Invalid record in fiscal memory",
                        Flag            = BinaryCode.ElementAt(5) == '1' ? true : false
                    },
                    One = new StatusFlag
                    {
                        BYTENO          = 1,
                        GeneralFunction = "Not used",
                        Flag            = BinaryCode.ElementAt(6) == '1' ? true : false
                    },
                    Zero = new StatusFlag
                    {
                        BYTENO          = 0,
                        GeneralFunction = "Record error in fiscal memory",
                        Flag            = BinaryCode.ElementAt(7) == '1' ? true : false
                    }
                };
                break;

            case 5:
                xByte = new BYTEN
                {
                    ByteN = byteNum,
                    Seven = new StatusFlag
                    {
                        BYTENO          = 7,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(0) == '1' ? true : false
                    },
                    Six = new StatusFlag
                    {
                        BYTENO          = 6,
                        GeneralFunction = "FM ready",
                        Flag            = BinaryCode.ElementAt(1) == '1' ? true : false
                    },
                    Five = new StatusFlag
                    {
                        BYTENO          = 5,
                        GeneralFunction = "MRC is programmed",
                        Flag            = BinaryCode.ElementAt(2) == '1' ? true : false
                    },
                    Four = new StatusFlag
                    {
                        BYTENO          = 4,
                        GeneralFunction = "Tax rate is programmed",
                        Flag            = BinaryCode.ElementAt(3) == '1' ? true : false
                    },
                    Three = new StatusFlag
                    {
                        BYTENO          = 3,
                        GeneralFunction = "Fiscal device in use",
                        Flag            = BinaryCode.ElementAt(4) == '1' ? true : false
                    },
                    Two = new StatusFlag
                    {
                        BYTENO          = 2,
                        GeneralFunction = "Reserved",
                        Flag            = BinaryCode.ElementAt(5) == '1' ? true : false
                    },
                    One = new StatusFlag
                    {
                        BYTENO          = 1,
                        GeneralFunction = "Not used",
                        Flag            = BinaryCode.ElementAt(6) == '1' ? true : false
                    },
                    Zero = new StatusFlag
                    {
                        BYTENO          = 0,
                        GeneralFunction = "FM overflowed",
                        Flag            = BinaryCode.ElementAt(7) == '1' ? true : false
                    }
                };
                break;

            default:
                break;
            }

            return(xByte);
        }