USB to MDB Master & MDB Slave Interface.


Contents:

Introduction

USB to MDB Interface

MDB implementation on the interface controller

    1. MDB master implementation

    2. MDB slave implementation

Electrical connections

    1. USB connector

    2. Interface connector

    3. Interface connection details

    4. LED functional description

Software API

    1. Available endpoints

    2. Available commands

    3. Device enable options

    4. Wrapper functions

        OpenDriver

        CloseDriver

        GetData

        PutData

        SetResetState

        ResetTarget

        DownloadTarget

    5. Sample usage of wrapper class CUSB

Technical Data

Copyright 2002 by BonusData AG

Download area

Links to related information's

Frequent asked questions   

Introduction:

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:

USB to MDB Interface:

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. 

interface.jpg (14743 bytes)
  • Compliant with the timing of the MDB 2.0 Specification
  • MDB master electrical interface
  • MDB slave electrical interface
  • RS-232 electrical interface
  • Professional hardware implementation
  • Low system costs

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.

1. MDB Master Implementation:

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.

2. MDB Slave Implementation:

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.

Electrical Connections:

Description of the interface connection. 

1. USB connector:

usb_connector.jpg (22280 bytes) Standard USB Type B connector

2. Interface connector:

vmc_connector.jpg (24912 bytes) 12 pin Molex connector

Part # 39-29-1128

3. Interface connection details:

pin_info.jpg (7506 bytes)
Pin: Name: Description:
1 SR- MDB Slave Receive (Ground)
2 ST- MDB Slave Transmit (Ground)
3 SR+ MDB Slave Receive (Signal)
4 ST+ MDB Slave Transmit (Signal)
5 MR MDB Master Receive
6 MT MDB Master Transmit
7 GND Interface Ground
8 VCC Interface Supply Voltage +5VDC
9 RX2 RS-232 COM2 Receive Data
10 TX2 RS-232 COM2 Transmit Data
11 RX1 RS-232 COM1 Receive Data
12 TX2 RS-232 COM1 Transmit Data

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.

tn_mdb_maser_cable.jpg (2618 bytes)

The MDB master requires a power supply for the connected slave devices.

Cable schematics as PDF file.

tn_mdb_slave_cable.jpg (3148 bytes)

The MDB slave requires a cable with a male and female connector to plug into the chain of slave devices.

Cable schematics as PDF file.

4. LED functional description

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.

Software API:

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:

1. Available endpoints:

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

 

2. Available commands:

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)

3. Device enable options

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

4. Wrapper functions

All the wrapper functions return true if successful.

Header file: USB.H

OpenDriver

bool OpenDriver(DWORD dwDevice=0);

Parameters:

    dwDewice

        [IN] Device number on the USB bus if more than one is connected. First device = 0.

CloseDriver

bool CloseDriver();

Parameters:

    None.

GetData

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.

PutData

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.

SetResetState

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.

ResetTarget

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();

DownloadTarget

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.

Technical Data: 

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

Download area

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.

Frequent asked questions:

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