日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

Android下的POS打印機調(diào)用的簡單實現(xiàn)教程( 二 )


if (mConnection == null) {
HashMap deviceList = mUsbManager.getDeviceList();
Iterator deviceIterator = deviceList.values().iterator();
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
mUsbManager.requestPermission(device, mPermissionIntent);
}
}
} else {
HashMap deviceList = mUsbManager.getDeviceList();
Iterator deviceIterator = deviceList.values().iterator();
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
mUsbManager.requestPermission(device, mPermissionIntent);
}
}
}
3.當(dāng)上面兩部都走完了之后,我們就可以發(fā)送指令來控制已經(jīng)建立連接的打印機了,這里我們使用的是標準的ESC/POS指令集,為硬件默認,貼出代碼,這里的指令集采用的是十進制表示形式,也可以替換成十六進制 。
public class printerCmdUtils {
/**
* 這些數(shù)據(jù)源自愛普生指令集,為POS機硬件默認
*/
public static final byte ESC = 27;//換碼
public static final byte FS = 28;//文本分隔符
public static final byte GS = 29;//組分隔符
public static final byte DLE = 16;//數(shù)據(jù)連接換碼
public static final byte EOT = 4;//傳輸結(jié)束
public static final byte ENQ = 5;//詢問字符
public static final byte SP = 32;//空格
public static final byte HT = 9;//橫向列表
public static final byte LF = 10;//打印并換行(水平定位)
public static final byte CR = 13;//歸位鍵
public static final byte FF = 12;//走紙控制(打印并回到標準模式(在頁模式下) )
public static final byte CAN = 24;//作廢(頁模式下取消打印數(shù)據(jù) )
//------------------------打印機初始化-----------------------------
/**
* 打印機初始化
* @return
*/
public static byte[] init_printer()
{
byte[] result = new byte[2];
result[0] = ESC;
result[1] = 64;
return result;
}
//------------------------換行-----------------------------
/**
* 換行
* @param lineNum要換幾行
* @return
*/
public static byte[] nextLine(int lineNum)
{
byte[] result = new byte[lineNum];
for(int i=0;i
{
result[i] = LF;
}
return result;
}
//------------------------下劃線-----------------------------
/**
* 繪制下劃線(1點寬)
* @return
*/
public static byte[] underlineWithOneDotWidthOn()
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 45;
result[2] = 1;
return result;
}
/**
* 繪制下劃線(2點寬)
* @return
*/
public static byte[] underlineWithTwoDotWidthOn()
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 45;
result[2] = 2;
return result;
}
/**
* 取消繪制下劃線
* @return
*/
public static byte[] underlineOff()
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 45;
result[2] = 0;
return result;
}
//------------------------加粗-----------------------------
/**
* 選擇加粗模式
* @return
*/
public static byte[] boldOn()
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 69;
result[2] = 0xF;
return result;
}
/**
* 取消加粗模式
* @return
*/
public static byte[] boldOff()
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 69;
result[2] = 0;
return result;
}
//------------------------對齊-----------------------------
/**
* 左對齊
* @return
*/
public static byte[] alignLeft()
{

推薦閱讀