USB to MDB Master & MDB Slave Interface.
Contents:
MDB implementation on the interface controller
3. Interface connection details
5. Sample usage of wrapper class CUSB
Copyright ©2002 by BonusData AG
Links to related information's
The interface allows to connect either a MDB master device or MDB slave device to a PC, running Microsoft Windows.
This is not as simple as it seems on the first glance. You will be confronted with three mayor problems:
It is not possible to implement an MDB slave with response timing as required by the MDB specification.
It is not possible to control the mode bit as the Windows API does not offer any such functions.
An electrical interface between RS-232 and MDB is needed when using a serial port.
Today BonusData AG offers a new USB to MDB interface solution. The interface makes it possible to implement sophisticated vending application using standard PC hardware and running Microsoft Windows 98/ME/2000/XP. The MDB to USB interface contains the electrical interface for MDB master, MDB slave and RS-232.
Connect a MDB vending machine controller (VMC) to the PC for new applications, like touch screens, network or internet connectivity.
Connect a MDB bill acceptor, card reader or change giver to a PC for revaluator applications, or implementing test equipment.
![]() |
|
MDB implementation on the interface controller:
Some low level parts of the MDB communication is implemented directly on the interface microcontroller. This allows to meet the MDB timing specifications and to control the mode bit of the MDB protocol. See also Software API below for further information's.
To communicate with a MDB slave, we must use the MDB master of the interface. The timing and mode bit control is handled by the interface microcontroller. The full MDB Data Frame, including command and checksum, is send to the interface endpoint #7. The response of the MDB slave is then read from interface endpoint #7.
Whenever the interface receives a frame on endpoint #7 it will react as follow:
1. The frame is send immediate to the MDB bus with the mode bit set on the first byte and mode bit reset an all following bytes.
2. After all the bytes are send, a timeout of 5 ms (default) is started, to wait for the slave response.
3A. If there is a slave response within the timeout period, the timeout is reset and the received response frame is send to endpoint #7.
3B. If there is no response within the timeout period, a timeout notification 0xFE is send to endpoint #7.
4. Any received bytes after this point are ignored.
To communicate with a MDB master, we must use the MDB slave of the interface. The timing and mode bit control is handled by the interface microcontroller. The interface is waiting to be addressed by a MDB master. If a MDB command is detected, address match and mode bit set, the frame will be collected. To determine the end of the frame, a inter character timeout of 2 ms (default) is used. This techniques allows, not to interpret all the MDB commands and their length of data. The PC is listening on endpoint #2 for any incoming frame of a MDB master.
Whenever the interface is addressed by a MDB master the interface will react as follow:
1. It will sample all the bytes of the MDB bus, until a timeout of more than 2 ms (default) is detected.
2. It will respond to the MDB master with an ACK to meet the MDB timing specification.
3. If the received frame is not a POLL command, it is send to the endpoint #2.
4. It will listen to endpoint #2 for any response to be send to the MDB master.
5. If a frame is received on endpoint #2, the interface will wait for the next POLL command of the MDB master.
6. It will respond with the frame data to the MDB master's POLL command.
Note: POLL commands of the MDB master are not send to endpoint #2. In idle condition, the interface will independently communicate with the MDB master.
Description of the interface connection.
![]() |
Standard USB Type B connector |
![]() |
12 pin Molex connector Part # 39-29-1128 |
3. Interface connection details:
![]() |
Attention: Do not apply any voltage to pin #8 of the interface connector! |
To connect a real MDB master or slave, special interface cables are required.
![]() |
The MDB master requires a power supply for the connected slave devices. |
![]() |
The MDB slave requires a cable with a male and female connector to plug into the chain of slave devices. |
The interface is equipped with 5 LED's to indicate information.
The red LED's are hardwired and indicate the state of the serial lines, even if there is no driver loaded.
If they are steady off, there is no communication.
If they are steady on, there may be some short circuit and it may indicate some electrical problems with the serial lines.
The green LED is software controlled and indicates the state of the interface.
If off: Error, the interface has no driver or is in reset state.
If on: Okay, the interface controller has started and is accessible with USB communication.
Note: After power up, the state of the LED's is not defined and they may randomly blink. This will vanish as soon as the interface is reset or the the firmware is downloaded.
The software interface is available as Microsoft Visual C++ 6.0 Class. This class wrap's the fundamental function call's to the USB driver.
The API calls are encapsulated by the wrapper class CUSB. See for the files USB.H and USB.CPP in the download area.
Some important notes to consider when implementing interface based application:
The maximum buffer size is limited to 64 bytes.
Listen on a endpoint will never return until any data is send to it by the interface.
Endpoint #0 is reserved for the driver to interface communication.
| Endpoint: | Usage: | Notes: |
| 0 | Used by driver | Reserved |
| 1 | Interface status and setup | See available commands below |
| 2 | MDB card reader communication Executive machine communication |
|
| 3 | MDB bill acceptor communication | Not implemented with version 01.00 |
| 4 | MDB change giver communication | Not implemented with version 01.00 |
| 5 | Reserved | For future usage |
| 6 | Reserved | For future usage |
| 7 | MDB master communication Executive master communication |
| Command: | Transmit: | Receive: |
| USB_VERSION Request interface version |
Byte #0 = USB_VERSION | Byte #0 = Version lower byte Byte #1 = Version upper byte |
| USB_STATUS Request interface status |
Byte #0 = USB_STATUS | Byte #0 = Device enable options Byte #1 = Inter character timeout low byte Byte #2 = Inter character timeout high byte Byte #3 = Response timeout low byte Byte #4 = Response timeout high byte |
| USB_START Start interface |
Byte #0 = USB_START Byte #1 = Device enable options |
No data |
| USB_STOP Stop interface |
Byte #0 = USB_STOP Byte #1 = Device enable options |
No data |
| USB_SETUP Interface setup |
Byte #0 = USB_SETUP Byte #1 = Inter character timeout low byte Byte #2 = Inter character timeout high byte Byte #3 = Response timeout low byte Byte #4 = Response timeout high byte |
No data |
| USB_READ | Byte #0 = USB_READ Byte #1 = EEPROM read address Byte #2 = Number of bytes to read |
Byte #0 = Result code (0=Failure/1=Okay) Byte #1..n = Data bytes read |
| USB_WRITE | Byte #0 = URB_WRITE Byte #1 = EEPROM write address Byte #2 = Number of bytes to write Byte #3..n = Databytes to write |
Byte #0 = Result code (0=Failure/1=Okay) |
| Option: | Description: |
| MDB_CARD_READER | Enable MDB card reader |
| MDB_BILL_ACCEPTOR | Enable MDB bill acceptor |
| MDB_CHANGE_GIVER | Enable MDB change giver |
| EXE_MACHINE | Enable Executive machine |
| EXE_CARD_READER | Enable Executive card reader |
| EXE_MASTER | Enable Executive master |
| MDB_MASTER | Enable MDB master |
All the wrapper functions return true if successful.
Header file: USB.H
bool OpenDriver(DWORD dwDevice=0);
Parameters:
dwDewice
[IN] Device number on the USB bus if more than one is connected. First device = 0.
bool CloseDriver();
Parameters:
None.
bool GetData(DWORD EndPoint, BYTE* pBuffer, DWORD* pdwBytes);
Parameters:
EndPoint
[IN] Source end point number. Use predefined constant.
pBuffer
[OUT] Pointer to a data buffer to fill in data from source end point. Buffer size is maximum 64 bytes. Use predefined constant MAX_BUFFER_SIZE.
pdwBytes
[OUT] Pointer to DWORD to return the number of bytes actually received.
bool PutData(DWORD EndPoint, BYTE* pBuffer, DWORD dwBytes);
Parameters:
EndPoint
[IN] Destination end point number. Use predefined constant.
pBuffer
[IN] Pointer to a data buffer with the contents to be send to the destination end point.
dwBytes
[IN] Number of bytes to send. Maximum 64 bytes.
bool SetResetState(bool bState);
Parameters:
bState
[IN] State of the interface reset.
Parameter bState = true will reset the interface and hold this state permanent until it is released by a next call with bState = false.
bool ResetTarget(DWORD dwDevice);
Parameters:
dwDevice
[IN] Device number on the USB bus if more than one is connected. First device = 0.
Note: This is a combination of calls as below, so do not use it on an driver already open.
OpenDriver(dwDevice);
SetResetState(true);
SetResetState(false);
CloseDriver();
bool DownloadTarget(DWORD
dwDevice, char* pFileName);
bool DownloadTarget(DWORD dwDevice, WORD wResourceID);
bool DownloadTarget(DWORD dwDevice, HANDLE hResource);
Parameters:
dwDevice
[IN] Device number on the USB bus if more than one is connected. First device = 0.
pFileName
[IN] Pointer to a buffer containing the full path of the driver file for download. The file must be a Intel Hex format. Default MDB.HEX.
wResouceID
[IN] The resource identification number if the driver file is placed within the instance resources. Default MDB.BIX.
hResource
[IN] A handle to a resource. The resource must be locked in memory.
5. Sample usage of wrapper class CUSB
Here we present the sample implementation "MDBEngine" using the wrapper class CUSB. A call to GetData will not return until at least one byte of data is received. This must be considered when implementing an application with this driver. So we believe, it's a good approach to use thread just for this task. The class CMDBEngine uses this techniques. The idle loop is used to read data from the UDB driver.
This implementation shows also how to terminate the application. As the thread will hang in the GetData call most of the time, a byte can be send to end point #1 with command USB_TERMINATE. This byte will be send back on all end points and release all waiting GetData calls. On detection of the byte inside the idle loop, a WM-QUIT is posted to terminate the thread.
See download area for the sample source files.
| Dimensions: | 40mm x 78.5mm x 21mm (WxLxH) |
| Weight: | 40 Gram |
| Temperature range: | 0..50° Grad Celsius |
| Power supply: | 5 VDC supplied by USB master (Interface only) |
| USB connector: | Standard USB connector, Type B |
| Interface connector: | 12 pin connector, Molex Part # 39-29-1128 |
| Indicator: | 5 LED, Ready, RX1 & TX1, RX2 & TX2 |
Copyright ©2002-2003 by BonusData AG
The copyright ©2002-2007 belongs to BonusData AG, Tiergartenweg 1, CH-4710 Balsthal, Switzerland.
Phone: +41 62 3919600 - Fax: +41 62 3919601 - E-Mail: mailto:team@bonusdata.net
Homepage: http://www.bonusdata.net
Note: The download files are zipped for security reasons.
EZUSB the USB interface driver:
| Contents: | Download EZUSB driver (11 kBytes) |
| EZUSB.SYS | USB interface driver. |
| EZUSB.INF | Installation script for ezusb.sys. |
| INSTALLATION.TXT | Additional instructions. |
MDBDemo, sample application 1.00, emulating a debit card reader:
| Contents: | Download MDBDemo (172 kBytes) |
| MDBDEMO.EXE | Sample application. |
| MDBDEMO.TXT | Short usage instruction. |
| MDBDemo Source | Microsoft Visual C++ 6.0 Project. |
Source of USB wrapper class:
| Contents: | Download source files (19 kBytes) |
| USB.H | Wrapper class header file. |
| USB.CPP | Wrapper class implementation file. |
| EZUSBSYS.H | Driver API header file. |
| MDB.BIX | Interface firmware as memory image file. |
| MDB.HEX | Interface firmware as Intel-hex file. |
Links to related information's:
Every thing about USB right here: http://www.usb.org/home
Information about vending: http://www.bonusdata.net/links/links.htm
MDB specification http://www.eva.be
Document history:
27.12.2002 - 1.00 First time published on the internet with the MDB master and MDB slave implementation.
16.05.2003 - 1.10 Added the executive master and executive slave implementation.
Q: Why is the MDB bill acceptor and change giver not implemented?
A: We just didn't have the time and equipment to implement it.
Q: Is the analyzer interface and the USB to MDB interface identical?
A: Yes, exactly the same. But with the analyzer you must purchase a software license.
[Home] - Copyright (C) 2002-2007 by BonusData AG, webmaster@bonusdata.net. Last update: 19.02.2007