Mpos Development Guidelines
Mpos Development Guidelines
Mpos Development Guidelines
Directory
Initialization TTLHandler................................................................................................................. 3
Activity Implement the listen interface........................................................................................... 3
Read Card....................................................................................................................................... 4
Read M1 card data.................................................................................................................. 4
Read Quick Pass and Visa pay Wave card data........................................................................5
Mpos Settings and configuration information................................................................................. 6
Mpos Print test............................................................................................................................... 7
Attentions....................................................................................................................................... 9
Initialization TTLHandler
TTLHandler handler;
Settings settings;
//com.imagpay.ttl.TTLHandler.TTLHandler(Context context)
handler = new TTLHandler(getApplicationContext());
// void com.imagpay.ttl.TTLHandler.setParameters(String devName, int baudrate)
handler.setParameters("/dev/ttyHSL1", 115200);
//com.imagpay.Settings.Settings(SwipeHandler handler)
settings = new Settings(handler);
handler.setShowLog(true);//Set the display print log
handler.addSwipeListener(this);//Add the monitor
implements SwipeListener
SwipeListener:
@Override
public void onCardDetect(CardDetected card) {
}
public void onConnected(SwipeEvent arg0) {
Log.i("xtztt","Connect ok...");
String ver = settings.readVersion();
ver = hexToSting(ver);
Log.i("xtztt","The version number:" + ver);
}
private String hexToSting(String ver) {
if (ver == null)
return "";
String[] tmps = ver.trim().replaceAll("..", "$0 ").split(" ");
StringBuffer sbf = new StringBuffer();
for (String str : tmps) {
sbf.append((char) Integer.parseInt(str, 16));
}
ver = sbf.toString();
return ver;
}
@Override
public void onDisconnected(SwipeEvent arg0) {
}
@Override
public void onParseData(SwipeEvent arg0) {
}
@Override
public void onPermission(SwipeEvent event) {
}
@Override
public void onReadData(SwipeEvent arg0) {
}
@Override
public void onStarted(SwipeEvent arg0) {
}
@Override
public void onStopped(SwipeEvent arg0) {
}
@Override
public void onEmvStatus(EmvStatus arg0) {
}
Read Card
System.arraycopy(Base16EnDecoder.Decode(dataWithAPDU.substring(4)), 0,
arg1, 0, dataWithAPDU.substring(4).length() / 2);
return arg1;
}
@Override
public String onGetDataPath() {
return path;
}
});
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
//Search card
String reset = settings.reset(Settings.SLOT_NFC);
if (reset != null) {
sendMessage("card near field");
}else{
sendMessage("no card near field");
return;
}
//Set the amount .The unit of the amount is a cent, 100 means 1
yuan
dds.EmvQTransParamInit(ISOUtil.zeropad("100",12));
byte[] bTransResult = new byte[1];
byte[] bCVMType = new byte[1];
byte[] bBalance = new byte[6];
int resp=dds.EmvQTrans(bBalance,bTransResult,bCVMType);
if(resp==0){
Toast.makeText(mctx, "quick pass read successful...........",
Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(mctx, "quick pass read failed.....<"+resp+">",
Toast.LENGTH_SHORT).show();
return;
}
if(bTransResult[0] == (byte)EmvCoreJNI.ONLINE_M){
}
else if(bTransResult[0] == (byte)EmvCoreJNI.APPROVE_M){
}
else if(bTransResult[0] == (byte)EmvCoreJNI.DECLINE_M){
}
}
Mpos Settings and configuration information
Initialization MposHandler
MposHandler _handler;
Settings _setting;
_handler = new MposHandler(this);
_setting = new Settings(_handler);
_handler.setParameters("/dev/ttyS2", 115200);
_handler.addSwipeListener(this);
Implement SwipeListener
Power on (_setting.mPosPowerOn())
Then Connect the serial port
try {
if (!_handler.isConnected()) {
sendMessage("Connect Res:" + _handler.connect());
} else {
_handler.close();
sendMessage("ReConnect Res:" + _handler.connect());
}
} catch (Exception e) {
sendMessage(e.getMessage());
}
Print
new Thread(new Runnable() {
public void run() {
settings.mPosPrintAlign(Settings.MPOS_PRINT_ALIGN_CENTER);
settings.mPosPrintTextSize(Settings.MPOS_PRINT_TEXT_DOUBLE_HEIGHT);
settings.mPosPrnStr("POS Signed Order");
settings.mPosPrintLn();
settings.mPosPrintTextSize(Settings.MPOS_PRINT_TEXT_NORMAL);
settings.mPosPrintAlign(Settings.MPOS_PRINT_ALIGN_LEFT);
settings.mPosPrnStr("The cardholder stub \nPlease
properly keep");
settings.mPosPrnStr("--------------------------");
settings.mPosPrnStr("Merchant Name:ABCDEFG");
settings.mPosPrnStr("Merchant No.:846584000103052");
settings.mPosPrnStr("Terminal no.:12345678");
settings.mPosPrnStr("categories: visa card");
settings.mPosPrnStr("Period of Validity:2016/07");
settings.mPosPrnStr("Batch no.:000101");
settings.mPosPrnStr("Card Number:");
settings.mPosPrnStr("622202400******0269");
settings.mPosPrnStr("Trade Type:consumption");
settings.mPosPrnStr("Serial No.:000024
\nAuthenticode:096706");
settings.mPosPrnStr("Date/Time:2016/09/01 11:27:12");
settings.mPosPrnStr("Ref.No.:123456789012345");
settings.mPosPrnStr("Amount:$ 100.00");
settings.mPosPrnStr("--------------------------");
settings.mPosPrintAlign(Settings.MPOS_PRINT_ALIGN_CENTER);
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
InputStream is =
getResources().openRawResource(R.drawable.ic_launcher);
Bitmap bitmap = BitmapFactory.decodeStream(is, null,
opt);
settings.mPosPrnImg(bitmap);
settings.mPosPrnStr("\n\n\n");
if (!bitmap.isRecycled()) {
bitmap.recycle();// Recycle image assets
}
bitmap = null;
}
}).start();
Print a picture
Settings.mPosPrnImg(Bitmap bit)
Attentions
Print and card reader module communicates with Android via serial port, this need for serial port
permissions. Serial port permissions are system-level, you need to refer to the following
documents.
Android Studio Automatic generation of APK with system signature.docx
apk_signature.doc