Operate a Coin Acceptor

The initialization sequence as defined per the MDB Specification is as follows:

M,1
R,08
R,09
R,0F,00
R,0F,0100000000
R,0A
R,0C,000F0000
(Poll, in loop)

Now, below, there is a python program that does this sequence programatically.

Some remarks:

  • This program follows the advised sequence described in Section 5 of the MDB Specification to Initialize a Coin Acceptor.

  • The Tube status is always empty

  • The program is doing nothing with Coin Inserted events

  • The VMC is not enabling any of the Expansion Features that are allowed for level 3 Coin Acceptors.

  • If the coin acceptor sends an incorrect message, the sequence is not reinitialized (this is something that must be done if the program is to be used in a real VMC)

  • Code is not optimized (e.g. Readline must be called after write2Serial, so this could be put in a function)

  • The goal of this example is to demonstrate and keep it simple, this is not suitable for "Real" VMCs. However, it can serve as a starting point.

from os import read, write
import serial,sys,time
#Commands that need to be sent to the interface
# M,1 -> Activate Master
# R,08 -> Reset Coin Changer
# R,0B -> Obtain Just Reset from Changer~
# R,09
# R,0F,00 -> Request additional Features (LVL 3+ Only)
# R,0F,01ZZZZZZZZ -> To enable desired features (depends on the changer's reply to previous command) (LVL 3+ Only)
# R,0A -> Tube Status
# R,0C,000F0000 # No manual Dispense (Last 2 Bytes), Coin Types 1,2,3 and 4 are accepted (000F , on first 2 bytes)
# R,0B -> Poll (In Loop)


# COMMAND DEFINITION
ENABLE_MASTER="M,1"
RESET_COIN_ACCEPTOR="R,08"
REQUEST_SETUP_INFO="R,09"
EXPANSION_REQUEST="R,0F,00"
EXPANSION_FEATURE_ENABLE="R,0F,0100000000"
TUBE_STATUS_REQUEST="R,0A"