// This uses the PAYOUT AMOUNT command to payout a value specified by the param amountToPayout. // Protocol 6+ - We can use an option byte to test whether the payout is possible (0x19), and if // it is then we can resend with the option byte 0x58 to do the payout. public bool PayoutAmount(int amountToPayout, char[] currency, TextBox log = null) { m_cmd.CommandData[0] = CCommands.Hopper.SSP_CMD_PAYOUT_AMOUNT; // Value to payout byte[] b = CHelpers.ConvertInt32ToBytes(amountToPayout); m_cmd.CommandData[1] = b[0]; m_cmd.CommandData[2] = b[1]; m_cmd.CommandData[3] = b[2]; m_cmd.CommandData[4] = b[3]; // Country code m_cmd.CommandData[5] = (byte)currency[0]; m_cmd.CommandData[6] = (byte)currency[1]; m_cmd.CommandData[7] = (byte)currency[2]; m_cmd.CommandData[8] = 0x58; // payout option (0x19 for test, 0x58 for real) m_cmd.CommandDataLength = 9; if (!SendCommand(log)) { return(false); } if (CheckGenericResponses(log)) { return(true); } return(false); }
// This function uses the FLOAT AMOUNT command to set the float amount. The validator will empty // notes into the cashbox leaving the requested floating amount in the payout. The minimum payout // is also setup so the validator will leave itself the ability to payout the minimum value requested. public void SetFloat(int minPayout, int floatAmount, char[] currency, TextBox log = null) { cmd.CommandData[0] = CCommands.SMARTPayout.SSP_CMD_FLOAT_AMOUNT; byte[] b = CHelpers.ConvertInt32ToBytes(minPayout); cmd.CommandData[1] = b[0]; cmd.CommandData[2] = b[1]; cmd.CommandData[3] = b[2]; cmd.CommandData[4] = b[3]; b = CHelpers.ConvertInt32ToBytes(floatAmount); cmd.CommandData[5] = b[0]; cmd.CommandData[6] = b[1]; cmd.CommandData[7] = b[2]; cmd.CommandData[8] = b[3]; // Add currency cmd.CommandData[9] = (byte)currency[0]; cmd.CommandData[10] = (byte)currency[1]; cmd.CommandData[11] = (byte)currency[2]; cmd.CommandData[12] = 0x58; // real float (could use 0x19 for test) cmd.CommandDataLength = 13; if (!SendCommand(log) || !CheckGenericResponses(log)) { return; } if (log != null) { log.AppendText("Floated amount successfully\r\n"); } }
// This function uses the GET ROUTING command to see if a specified note is recycling. The // caller passes a bool across which is set by the function. public void IsNoteRecycling(int noteValue, char[] currency, ref bool response, TextBox log = null) { // Determine if the note is currently being recycled cmd.CommandData[0] = CCommands.SMARTPayout.SSP_CMD_GET_ROUTING; byte[] b = CHelpers.ConvertInt32ToBytes(noteValue); cmd.CommandData[1] = b[0]; cmd.CommandData[2] = b[1]; cmd.CommandData[3] = b[2]; cmd.CommandData[4] = b[3]; // Add currency cmd.CommandData[5] = (byte)currency[0]; cmd.CommandData[6] = (byte)currency[1]; cmd.CommandData[7] = (byte)currency[2]; cmd.CommandDataLength = 8; if (!SendCommand(log) || !CheckGenericResponses(log)) { return; } // True if it is currently being recycled if (cmd.ResponseData[1] == 0x00) { response = true; } // False if not else if (cmd.ResponseData[1] == 0x01) { response = false; } }
// This function calls the PAYOUT AMOUNT command to payout a specified value. This can be sent // with the option byte 0x19 to test whether the payout is possible or 0x58 to actually do the payout. public void PayoutAmount(int amount, char[] currency, bool test = false, TextBox log = null) { cmd.CommandData[0] = CCommands.SMARTPayout.SSP_CMD_PAYOUT_AMOUNT; byte[] b = CHelpers.ConvertInt32ToBytes(amount); cmd.CommandData[1] = b[0]; cmd.CommandData[2] = b[1]; cmd.CommandData[3] = b[2]; cmd.CommandData[4] = b[3]; cmd.CommandData[5] = (byte)currency[0]; cmd.CommandData[6] = (byte)currency[1]; cmd.CommandData[7] = (byte)currency[2]; if (!test) { cmd.CommandData[8] = 0x58; // real payout } else { cmd.CommandData[8] = 0x19; // test payout } cmd.CommandDataLength = 9; if (!SendCommand(log) || !CheckGenericResponses(log)) { return; } if (log != null) { log.AppendText("Paying out " + CHelpers.FormatToCurrency(amount) + " " + new string(currency) + "\r\n"); } }
private void PayoutBtn_Click(object sender, EventArgs e) { bool payoutRequired = false; byte[] data = new byte[9 * Hopper.NumberOfChannels]; // create to size of maximum possible byte length = 0; int dataIndex = 0; byte denomsToPayout = 0; // For each denomination for (int i = 0; i < Hopper.NumberOfChannels; i++) { try { // Check if there is input in the box if (AmountToPayout[i].Text != "" && AmountToPayout[i].Text != "0") { // If textbox isn't blank then this denom is being paid out denomsToPayout++; length += 9; // 9 bytes per denom to payout (2 amount, 4 value, 3 currency) payoutRequired = true; // need to do a payout as there is now > 0 denoms // Number of this denomination to payout UInt16 numToPayout = UInt16.Parse(AmountToPayout[i].Text); byte[] b = CHelpers.ConvertInt16ToBytes((short)numToPayout); data[dataIndex++] = b[0]; data[dataIndex++] = b[1]; // Value of this denomination ChannelData d = Hopper.UnitDataList[i]; b = CHelpers.ConvertInt32ToBytes(d.Value); data[dataIndex++] = b[0]; data[dataIndex++] = b[1]; data[dataIndex++] = b[2]; data[dataIndex++] = b[3]; // Currency of this denomination data[dataIndex++] = (Byte)d.Currency[0]; data[dataIndex++] = (Byte)d.Currency[1]; data[dataIndex++] = (Byte)d.Currency[2]; } } catch (Exception ex) { MessageBox.Show(ex.ToString()); payoutRequired = false; // don't payout on exception } } if (payoutRequired) { // Send payout command and shut this form Hopper.PayoutByDenomination(denomsToPayout, data, length, Output); base.Dispose(); } }
// Set a channel to route to storage, this sends the SET ROUTING command. public void RouteChannelToStorage(int channelNumber, TextBox log = null) { // setup command m_cmd.CommandData[0] = CCommands.Hopper.SSP_CMD_SET_ROUTING; m_cmd.CommandData[1] = 0x00; // storage // coin to route // Get value of coin (4 byte protocol 6) byte[] b = CHelpers.ConvertInt32ToBytes(GetChannelValue(channelNumber)); m_cmd.CommandData[2] = b[0]; m_cmd.CommandData[3] = b[1]; m_cmd.CommandData[4] = b[2]; m_cmd.CommandData[5] = b[3]; // Add country code, locate from dataset foreach (ChannelData d in m_UnitDataList) { if (d.Channel == channelNumber) { m_cmd.CommandData[6] = (byte)d.Currency[0]; m_cmd.CommandData[7] = (byte)d.Currency[1]; m_cmd.CommandData[8] = (byte)d.Currency[2]; break; } } m_cmd.CommandDataLength = 9; // send command if (!SendCommand(log)) { return; } if (CheckGenericResponses(log)) { // update list foreach (ChannelData d in m_UnitDataList) { if (d.Channel == channelNumber) { d.Recycling = true; break; } } if (log != null) { log.AppendText("Successfully routed coin on channel " + channelNumber.ToString() + " to storage\r\n"); } } }
// This uses the SET COIN AMOUNT command to increase a channel level by passing over the channel and the amount to increment by public void SetCoinLevelsByChannel(int channel, short amount, TextBox log = null) { m_cmd.CommandData[0] = CCommands.Hopper.SSP_CMD_SET_COIN_AMOUNT; // Level to set byte[] b = CHelpers.ConvertInt16ToBytes(amount); m_cmd.CommandData[1] = b[0]; m_cmd.CommandData[2] = b[1]; // Coin(channel) to set b = CHelpers.ConvertInt32ToBytes(GetChannelValue(channel)); m_cmd.CommandData[3] = b[0]; m_cmd.CommandData[4] = b[1]; m_cmd.CommandData[5] = b[2]; m_cmd.CommandData[6] = b[3]; // Add country code, locate from dataset foreach (ChannelData d in m_UnitDataList) { if (d.Channel == channel) { m_cmd.CommandData[7] = (byte)d.Currency[0]; m_cmd.CommandData[8] = (byte)d.Currency[1]; m_cmd.CommandData[9] = (byte)d.Currency[2]; break; } } m_cmd.CommandDataLength = 10; if (!SendCommand(log)) { return; } if (CheckGenericResponses(log)) { // Update the level foreach (ChannelData d in m_UnitDataList) { if (d.Channel == channel) { d.Level += amount; break; } } if (log != null) { log.AppendText("Changed coin value " + CHelpers.FormatToCurrency(GetChannelValue(channel)).ToString() + "'s level to " + amount.ToString() + "\r\n"); } } }
// This function uses the GET ROUTING command to see if a specified coin is recycling. The // caller passes a bool across which is set by the function. public void IsCoinRecycling(int coinValue, char[] currency, ref bool response, TextBox log = null) { // First determine if the coin is currently being recycled m_cmd.CommandData[0] = CCommands.Hopper.SSP_CMD_GET_ROUTING; 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]; // Add currency 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)) { return; } if (CheckGenericResponses(log)) { // True if it is currently being recycled if (m_cmd.ResponseData[1] == 0x00) { response = true; if (log != null) { log.AppendText(CHelpers.FormatToCurrency(coinValue) + " is recycling\r\n"); } } // False if not else if (m_cmd.ResponseData[1] == 0x01) { response = false; if (log != null) { log.AppendText(CHelpers.FormatToCurrency(coinValue) + " is not recycling\r\n"); } } } }
// 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); }
// This function uses the FLOAT AMOUNT command to set the float amount. The Hopper will empty // coins into the cashbox leaving the requested floating amount in the payout. The minimum payout // is also setup so the validator will leave itself the ability to payout the minimum value requested. public bool SetFloat(short minPayout, int floatAmount, char[] currency, TextBox log = null) { m_cmd.CommandData[0] = CCommands.Hopper.SSP_CMD_FLOAT_AMOUNT; // Min payout byte[] b = CHelpers.ConvertInt16ToBytes(minPayout); m_cmd.CommandData[1] = b[0]; m_cmd.CommandData[2] = b[1]; // Amount to payout b = CHelpers.ConvertInt32ToBytes(floatAmount); m_cmd.CommandData[3] = b[0]; m_cmd.CommandData[4] = b[1]; m_cmd.CommandData[5] = b[2]; m_cmd.CommandData[6] = b[3]; // Country code m_cmd.CommandData[7] = (byte)currency[0]; m_cmd.CommandData[8] = (byte)currency[1]; m_cmd.CommandData[9] = (byte)currency[2]; m_cmd.CommandData[10] = 0x58; // real float m_cmd.CommandDataLength = 11; if (!SendCommand(log)) { return(false); } if (CheckGenericResponses(log)) { if (log != null) { log.AppendText("Set float successfully\r\n"); } return(true); } return(false); }
// This uses the SET COIN AMOUNT command to increase a channel level by passing over the coin value and the amount to increment by public void SetCoinLevelsByCoin(int coin, char[] currency, short amount, TextBox log = null) { m_cmd.CommandData[0] = CCommands.Hopper.SSP_CMD_SET_COIN_AMOUNT; byte[] b = CHelpers.ConvertInt16ToBytes(amount); m_cmd.CommandData[1] = b[0]; m_cmd.CommandData[2] = b[1]; b = CHelpers.ConvertInt32ToBytes(coin); m_cmd.CommandData[3] = b[0]; m_cmd.CommandData[4] = b[1]; m_cmd.CommandData[5] = b[2]; m_cmd.CommandData[6] = b[3]; m_cmd.CommandData[7] = (byte)currency[0]; m_cmd.CommandData[8] = (byte)currency[1]; m_cmd.CommandData[9] = (byte)currency[2]; m_cmd.CommandDataLength = 10; if (!SendCommand(log)) { return; } if (CheckGenericResponses(log)) { // Update the level foreach (ChannelData d in m_UnitDataList) { if (d.Value == coin) { d.Level += amount; break; } } if (log != null) { log.AppendText("Increased coin value " + CHelpers.FormatToCurrency(coin).ToString() + "'s level by " + amount.ToString() + "\r\n"); } } }
// This function uses the command GET NOTE AMOUNT to find out the number of // a specified type of note stored in the payout. Returns the number of notes stored // of that denomination. public int CheckNoteLevel(int note, char[] currency, TextBox log = null) { cmd.CommandData[0] = CCommands.SMARTPayout.SSP_CMD_GET_NOTE_AMOUNT; byte[] b = CHelpers.ConvertInt32ToBytes(note); cmd.CommandData[1] = b[0]; cmd.CommandData[2] = b[1]; cmd.CommandData[3] = b[2]; cmd.CommandData[4] = b[3]; cmd.CommandData[5] = (byte)currency[0]; cmd.CommandData[6] = (byte)currency[1]; cmd.CommandData[7] = (byte)currency[2]; cmd.CommandDataLength = 8; if (!SendCommand(log) || !CheckGenericResponses(log)) { return(0); } int i = (int)cmd.ResponseData[1]; return(i); }