Python Samples
Here you can find example code, free of charge, unlocked, for download.
All code and examples are provided "as is", no warranties, for informational purposes. You can also use it commercially with our products :)
The code will run both with the MDB-USB Interface as well as with the MDB Pi Hat Interface, unless indicated otherwise.
Master (VMC) Mode
In this mode, you use a MDB-USB Interface, connected to a host, to simulate a vending machine and to talk to standard peripherals (like a cashless acceptance device). There are two possible ways to use our MDB-USB Interfaces. Low level you run the MDB Protocol yourself (the below Java example does this). High level you can use simple ASCII commands to receive a payment.
That is described, for example, in the following video:
Python source code to do a vending cycle with a cashless reader:
https://firmware.qibixx.com/mdb_dialog.py
To run this script just connect a MDB-USB Interface to your PC or Raspberry and run it with high permissions;
Accepts following arguments (default):
parameter | alternative parameter | default | description |
---|---|---|---|
-debug | -d | 0 | 1=debug mode ; 0=only essential logs |
-port | -p | /dev/ttyACM0 | set serial port where MDB device is attached to |
-output | -o | 1 | 1 = enable output ; 0=disable output |
python3 mdb_dialogV5.py -d 1 -p /dev/ttyACM2 -o 1
If your user is not in the dialout group, you may have to run the above snippet as root or you must enter the following command:
sudo usermod -a -G dialout $USER
Peripheral (Device Side) Mode
Also in the Peripheral Mode, you have the choice to implement the MDB protocol yourself to do "anything" or to use our high level cashless device simulation.
Here is an example on how to do this with a terminal program. If you want to see the communication being established we provide the source code (Python) below:
Python trivial source code to send commands to enable and operate a cashless device: http://firmware.qibixx.com/examples/commands.py
Python trivial source code to activate the sniffer and see MDB traffic real time
http://firmware.qibixx.com/examples/sniffer.py
Coin Acceptor Command Line
This example consists of a simple Python Program that implements a basic Coin Acceptor implementation. You can download it here
The coin acceptor has the following characteristics:
It is not capable of giving change/dispensing coins.
It is able to give credit for 3 types of coins: 0.50€,1€ and 2€.
Credits are given to the VMC by pressing numeric keys 1(0.5€) ,2 (1€) and 3 (2€)
To be able to run this program, the following programs/packages must be installed:
- Python 3
- Python Packages time and pyserial
- Elevation (sudo in unix)
To run the Program (Linux OS) just run the following command:
sudo python3 CoinAcceptor.py /dev/ttyACM0
Once the Vending Machine initializes the Coin Acceptor , a prompt will be presented where the 3 types of coins can be "inserted" with the numeric pad.