Esempio n. 1
0
        // This function gets the CASHBOX PAYOUT OPERATION DATA from the validator and returns it as a string
        public void GetCashboxPayoutOpData(TextBox log = null)
        {
            // first send the command
            m_cmd.CommandData[0]    = CCommands.Hopper.SSP_CMD_CASHBOX_PAYOUT_OP_DATA;
            m_cmd.CommandDataLength = 1;

            if (!SendCommand(log))
            {
                return;
            }

            // now deal with the response data
            if (CheckGenericResponses(log))
            {
                // number of different coins
                int    n             = m_cmd.ResponseData[1];
                string displayString = "Number of Total Coins: " + n.ToString() + "\r\n\r\n";
                int    i             = 0;
                for (i = 2; i < (9 * n); i += 9)
                {
                    displayString += "Moved " + CHelpers.ConvertBytesToInt16(m_cmd.ResponseData, i) +
                                     " x " + CHelpers.FormatToCurrency(CHelpers.ConvertBytesToInt32(m_cmd.ResponseData, i + 2)) +
                                     " " + (char)m_cmd.ResponseData[i + 6] + (char)m_cmd.ResponseData[i + 7] + (char)m_cmd.ResponseData[i + 8]
                                     + " to cashbox\r\n";
                }
                displayString += CHelpers.ConvertBytesToInt32(m_cmd.ResponseData, i) + " coins not recognised\r\n";

                if (log != null)
                {
                    log.AppendText(displayString);
                }
            }
        }
Esempio n. 2
0
        // This uses the GET COIN AMOUNT command to query the validator on a specified coin it has stored, it returns
        // the level as an int.
        public short CheckCoinLevel(int coinValue, char[] currency, TextBox log = null)
        {
            m_cmd.CommandData[0] = CCommands.Hopper.SSP_CMD_GET_COIN_AMOUNT;
            byte[] b = CHelpers.ConvertInt32ToBytes(coinValue);
            m_cmd.CommandData[1]    = b[0];
            m_cmd.CommandData[2]    = b[1];
            m_cmd.CommandData[3]    = b[2];
            m_cmd.CommandData[4]    = b[3];
            m_cmd.CommandData[5]    = (byte)currency[0];
            m_cmd.CommandData[6]    = (byte)currency[1];
            m_cmd.CommandData[7]    = (byte)currency[2];
            m_cmd.CommandDataLength = 8;

            if (!SendCommand(log) || !CheckGenericResponses(log))
            {
                return(0);
            }
            short ret = CHelpers.ConvertBytesToInt16(m_cmd.ResponseData, 1);

            return(ret);
        }
Esempio n. 3
0
        // This function is called repeatedly to poll the validator about what events are happening. It
        // can optionally output these events to a textbox.
        public bool DoPoll(TextBox log)
        {
            byte i;

            //send poll
            m_cmd.CommandData[0]    = CCommands.Generic.SSP_CMD_POLL;
            m_cmd.CommandDataLength = 1;

            if (!SendCommand(log))
            {
                return(false);
            }

            // Check unit hasn't lost key (could be due to power loss or reset)
            if (m_cmd.ResponseData[0] == 0xFA)
            {
                return(false);
            }

            // isolate poll response to allow reuse of the SSP_COMMAND structure
            m_CurrentPollResponseLength = m_cmd.ResponseDataLength;
            m_cmd.ResponseData.CopyTo(m_CurrentPollResponse, 0);

            //parse poll response
            int    coin     = 0;
            string currency = "";

            for (i = 1; i < m_CurrentPollResponseLength; i++)
            {
                switch (m_CurrentPollResponse[i])
                {
                // This response indicates that the unit was reset and this is the first time a poll
                // has been called since the reset.
                case CCommands.Hopper.SSP_POLL_RESET:
                    UpdateData();
                    break;

                // This response is given when the unit is disabled.
                case CCommands.Hopper.SSP_POLL_DISABLED:
                    log.AppendText("Unit disabled...\r\n");
                    break;

                // The unit is in the process of paying out a coin or series of coins, this will continue to poll
                // until the coins have been fully dispensed
                case CCommands.Hopper.SSP_POLL_DISPENSING:
                    log.AppendText("Dispensing coin(s)...\r\n");
                    // Now the index needs to be moved on to skip over the data provided by this response so it
                    // is not parsed as a normal poll response.
                    // In this response, the data includes the number of countries being dispensed (1 byte), then a 4 byte value
                    // and 3 byte currency code for each country.
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // This is polled when a unit has finished a dispense operation. The following 4 bytes give the
                // value of the coin(s) dispensed.
                case CCommands.Hopper.SSP_POLL_DISPENSED:
                    for (int j = 0; j < m_CurrentPollResponse[i + 1] * 7; j += 7)
                    {
                        coin = CHelpers.ConvertBytesToInt32(m_cmd.ResponseData, i + j + 2);     // get coin data from response
                        // get currency from response
                        currency  = "";
                        currency += (char)m_CurrentPollResponse[i + j + 6];
                        currency += (char)m_CurrentPollResponse[i + j + 7];
                        currency += (char)m_CurrentPollResponse[i + j + 8];
                        log.AppendText(CHelpers.FormatToCurrency(coin) + " " + currency + " coin(s) dispensed\r\n");
                    }

                    UpdateData();
                    EnableValidator();
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // The coins being recycled inside the unit are running low.
                case CCommands.Hopper.SSP_POLL_COINS_LOW:
                    log.AppendText("Coins low\r\n");
                    break;

                // There are no coins left in the unit.
                case CCommands.Hopper.SSP_POLL_EMPTY:
                    log.AppendText("Unit empty\r\n");
                    break;

                // The mechanism inside the unit is jammed.
                case CCommands.Hopper.SSP_POLL_JAMMED:
                    log.AppendText("Jammed\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // A dispense, SMART empty or float operation has been halted.
                case CCommands.Hopper.SSP_POLL_HALTED:
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // The device is 'floating' a specified amount of coins. It will transfer some to the cashbox and
                // leave the specified amount in the device.
                case CCommands.Hopper.SSP_POLL_FLOATING:
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // The float operation has completed.
                case CCommands.Hopper.SSP_POLL_FLOATED:
                    UpdateData();
                    EnableValidator();
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // This poll appears when the SMART Hopper has been searching for a coin but cannot find it within
                // the timeout period.
                case CCommands.Hopper.SSP_POLL_TIME_OUT:
                    log.AppendText("Search for suitable coins failed\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // A payout was interrupted in some way. The amount paid out does not match what was requested. The value
                // of the dispensed and requested amount is contained in the response.
                case CCommands.Hopper.SSP_POLL_INCOMPLETE_PAYOUT:
                    log.AppendText("Incomplete payout detected...\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 11) + 1);
                    break;

                // A float was interrupted in some way. The amount floated does not match what was requested. The value
                // of the dispensed and requested amount is contained in the response.
                case CCommands.Hopper.SSP_POLL_INCOMPLETE_FLOAT:
                    log.AppendText("Incomplete float detected...\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 11) + 1);
                    break;

                // This poll appears when coins have been dropped to the cashbox whilst making a payout. The value of
                // coins and the currency is reported in the response.
                case CCommands.Hopper.SSP_POLL_CASHBOX_PAID:
                    log.AppendText("Cashbox paid\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // A credit event has been detected, this is when the coin mech has accepted a coin as legal currency.
                case CCommands.Hopper.SSP_POLL_COIN_CREDIT:
                    coin      = CHelpers.ConvertBytesToInt16(m_cmd.ResponseData, i + 1);
                    currency  = "";
                    currency += (char)m_CurrentPollResponse[i + 5];
                    currency += (char)m_CurrentPollResponse[i + 6];
                    currency += (char)m_CurrentPollResponse[i + 7];
                    log.AppendText(CHelpers.FormatToCurrency(coin) + " " + currency + " credited\r\n");
                    UpdateData();
                    i += 7;
                    break;

                // The coin mech has become jammed.
                case CCommands.Hopper.SSP_POLL_COIN_MECH_JAMMED:
                    log.AppendText("Coin mech jammed\r\n");
                    break;

                // The return button on the coin mech has been pressed.
                case CCommands.Hopper.SSP_POLL_COIN_MECH_RETURN_PRESSED:
                    log.AppendText("Return button pressed\r\n");
                    break;

                // The unit is in the process of dumping all the coins stored inside it into the cashbox.
                case CCommands.Hopper.SSP_POLL_EMPTYING:
                    log.AppendText("Emptying...\r\n");
                    break;

                // The unit has finished dumping coins to the cashbox.
                case CCommands.Hopper.SSP_POLL_EMPTIED:
                    log.AppendText("Emptied\r\n");
                    UpdateData();
                    EnableValidator();
                    break;

                // A fraud attempt has been detected.
                case CCommands.Hopper.SSP_POLL_FRAUD_ATTEMPT:
                    log.AppendText("Fraud attempted\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // The unit is in the process of dumping all the coins stored inside it into the cashbox.
                // This poll means that the unit is keeping track of what it empties.
                case CCommands.Hopper.SSP_POLL_SMART_EMPTYING:
                    log.AppendText("SMART emptying...\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // The unit has finished SMART emptying. The info on what has been dumped can be obtained
                // by sending the CASHBOX PAYOUT OPERATION DATA command.
                case CCommands.Hopper.SSP_POLL_SMART_EMPTIED:
                    GetCashboxPayoutOpData(log);
                    UpdateData();
                    EnableValidator();
                    log.AppendText("SMART emptied\r\n");
                    i += (byte)((m_CurrentPollResponse[i + 1] * 7) + 1);
                    break;

                // A coin has had its routing changed to either cashbox or recycling.
                case CCommands.Hopper.SSP_POLL_COIN_ROUTED:
                    log.AppendText("Routed coin\r\n");
                    UpdateData();
                    break;

                default:
                    log.AppendText("Unsupported poll response received: " + (int)m_CurrentPollResponse[i] + "\r\n");
                    break;
                }
            }
            return(true);
        }