示例#1
0
        public bool CmdStatus(byte Addr)
        {
            byte[]   Data     = new byte[] { SYNC, 0, 6, GET_STATUS, 0, 0 };
            CCommand cmd      = new CCommand(Data, 0, 0);
            CCommand Response = Transmit(cmd, Addr);

            if ((iLastError = Response.Code) == 0)
            {
                if ((Response.Data[3] == ST_INV_CMD) && (Response.Data[2] == 6))
                {
                    iLastError          = ER_INVALID_CMD;
                    BillStatus.Enabled  = 0;
                    BillStatus.Security = 0;
                    BillStatus.Routing  = 0;
                    return(false);
                }
                BillStatus.Enabled  = Response.Data[5] + ((UInt32)Response.Data[4] << 8) + ((UInt32)Response.Data[3] << 16);
                BillStatus.Security = Response.Data[8] + ((UInt32)Response.Data[7] << 8) + ((UInt32)Response.Data[6] << 16);
                BillStatus.Routing  = Response.Data[11] + ((UInt32)Response.Data[10] << 8) + ((UInt32)Response.Data[9] << 16);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        public bool CmdBillType(UInt32 enBill, UInt32 escBill, byte Addr)
        {
            byte[] Data = new byte[] { SYNC, 0, 12, BILL_TYPE,
                                       (byte)(enBill >> 16), (byte)(enBill >> 8), (byte)enBill,
                                       (byte)(escBill >> 16), (byte)(escBill >> 8), (byte)escBill,
                                       0, 0 };
            CCommand cmd      = new CCommand(Data, 0, 0);
            CCommand Response = Transmit(cmd, Addr);
            byte     ack;

            if ((iLastError = Response.Code) == 0)
            {
                if ((ack = Response.Data[3]) != ACK)
                {
                    iLastError = (ack != ST_INV_CMD) ? ER_NAK : ER_INVALID_CMD;
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
示例#3
0
        CCommand TransmitCMD(CCommand Cmd, byte Addr)
        {
            byte[] tmpBuffer = new byte[256];
            int    i         = (Cmd.Data[2] != 0) ? (Cmd.Data)[2] :
                               (((UInt16)(Cmd.Data)[4]) << 8) + (Cmd.Data)[5];

            Cmd.SetByte(Addr, 1);
            UInt16 wCRC = CalculateCRC(Cmd.Data);

            Cmd.SetByte((byte)wCRC, i - 2);
            Cmd.SetByte((byte)(wCRC >> 8), i - 1);
            cmdOut = Cmd;

            int iErrCode = SendCommand(Cmd.Data, ref tmpBuffer);

            if ((iErrCode == 0) && (Cmd.Data[3] != 0) && (0xFF != Cmd.Data[3]))
            {
                wCRC = (UInt16)(tmpBuffer[((tmpBuffer[2] != 0) ? tmpBuffer[2] - 2 : (UInt16)((tmpBuffer)[4] << 8) + tmpBuffer[5] - 2)] +
                                (tmpBuffer[((tmpBuffer[2] != 0) ? tmpBuffer[2] - 1 : (UInt16)(tmpBuffer[4] << 8) + tmpBuffer[5] - 1)] << 8));
                if (CalculateCRC(tmpBuffer) != wCRC)
                {
                    iErrCode = RE_CRC;
                }
                cmdIn = new CCommand(tmpBuffer, iErrCode, (tmpBuffer[2] != 0) ? (tmpBuffer)[2] :
                                     (((UInt16)(tmpBuffer)[4]) << 8) + (tmpBuffer)[5]);
                return(cmdIn);
            }
            cmdIn = new CCommand(tmpBuffer, iErrCode, 0);
            return(cmdIn);
        }
示例#4
0
        CCommand Transmit(CCommand CMD, byte Addr)
        {
            CCommand cmdRes = null;
            CCommand cmdACK = new CCommand();

            for (int i = 0; i < 3; i++)
            {
                cmdRes = TransmitCMD(CMD, Addr);
                cmdACK.SetByte(SYNC, 0);
                cmdACK.SetByte(6, 2);
                cmdACK.SetByte(ACK, 3);

                if (cmdRes.Code == RE_NONE)
                {
                    if ((ACK == cmdRes.Data[3]) && (cmdRes.Data[2] == 6))
                    {
                        return(cmdRes);
                    }
                    if ((NAK == cmdRes.Data[3]) && (cmdRes.Data[2] == 6))
                    {
                        if (iCmdDelay != 0)
                        {
                            Thread.Sleep(iCmdDelay);//5
                        }
                    }
                    else
                    {
                        cmdACK.SetByte(ACK, 3);
                        TransmitCMD(cmdACK, Addr);
                        if (iCmdDelay != 0)
                        {
                            Thread.Sleep(iCmdDelay);//5
                        }
                        break;
                    }
                }
                else
                {
                    if (cmdRes.Code != RE_TIMEOUT)
                    {
                        cmdACK.SetByte(NAK, 3);
                        TransmitCMD(cmdACK, Addr);
                        if (iCmdDelay != 0)
                        {
                            Thread.Sleep(iCmdDelay);//5
                        }
                    }
                }
            }

            return(cmdRes);
        }
示例#5
0
        public bool CmdPoll(byte Addr)
        {
            byte[]   Data     = new byte[] { SYNC, 0, 6, POLL, 0, 0 };
            CCommand cmd      = new CCommand(Data, 0, 0);
            CCommand Response = Transmit(cmd, Addr);

            if ((iLastError = Response.Code) == 0)
            {
                m_PollResults.Z1 = Response.Data[3];
                m_PollResults.Z2 = Response.Data[4];
                return(true);
            }
            else
            {
                m_PollResults.Z1 = 0;
                m_PollResults.Z2 = 0;
                return(false);
            }
        }
示例#6
0
        public bool CmdReset(byte Addr)
        {
            byte[]   Data     = new byte[] { SYNC, 0, 6, RESET, 0 };
            CCommand cmd      = new CCommand(Data, 0, 6 - 1);
            CCommand Response = Transmit(cmd, Addr);
            byte     ack;

            if ((iLastError = Response.Code) == 0)
            {
                if ((ack = Response.Data[3]) != ACK)
                {
                    iLastError = (ack != ST_INV_CMD) ? ER_NAK : ER_INVALID_CMD;
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
示例#7
0
        public bool CmdGetBillTable(byte Addr)
        {
            byte[]   Data     = new byte[] { SYNC, 0, 6, GET_BILL_TABLE, 0, 0 };
            CCommand cmd      = new CCommand(Data, 0, 0);
            CCommand Response = Transmit(cmd, Addr);

            if ((iLastError = Response.Code) == 0)
            {
                if ((Response.Data[3] == ST_INV_CMD) && (Response.Data[2] == 6))
                {
                    iLastError = ER_INVALID_CMD;

                    /*for (int i = 0; i < 24; i++)
                     * {
                     *  m_BillTable[i].Denomination = 0;
                     *  //strcpy(BillTable[i].sCountryCode,"");
                     * }*/
                    /*foreach (_BillRecord record in m_BillRecordList)
                     * {
                     *  record.Denomination = 0;
                     *  record.sCountryCode1 = "";
                     *  record.sCountryCode2 = "";
                     *  record.sCountryCode3 = "";
                     * }*/
                    return(false);
                }
                m_BillRecordList.Clear();
                for (int i = 0; i < (Response.Data[2]) - 5; i += 5)
                {
                    _BillRecord billRecord = new _BillRecord();
                    billRecord.Denomination = Response.Data[i + 3];
                    billRecord.sCountryCode = String.Format("{0}{1}{2}",
                                                            Response.Data[i + 4], Response.Data[i + 5], Response.Data[i + 6]);
                    //BillTable[i/5].Denomination=Response.Data[i+3];
                    //char sTmp[5];
                    //strncpy(sTmp,(const char *)(Response.GetData()+i+4),3);
                    //sTmp[3]='\0';
                    //strcpy(BillTable[i/5].sCountryCode,sTmp);
                    if (((Response.Data[i + 7]) & 0x80) != 0)
                    {
                        for (int j = 0; j < ((Response.Data[i + 7]) & 0x7F); j++)
                        {
                            billRecord.Denomination /= 10;
                        }
                        //BillTable[i/5].Denomination/=10;
                    }
                    else
                    {
                        for (int j = 0; j < ((Response.Data[i + 7]) & 0x7F); j++)
                        {
                            billRecord.Denomination *= 10;
                        }
                        //BillTable[i/5].Denomination*=10;
                    };
                    m_BillRecordList.Add(billRecord);
                }

                /*for(i;i<24*5;i+=5)
                 * {
                 *  BillTable[i/5].Denomination=0;
                 *  strcpy(BillTable[i/5].sCountryCode,"");
                 * } */
                return(true);
            }
            else
            {
                return(false);
            }
        }