byte[] result = new byte[3];
result[0] = ESC;
result[1] = 97;
result[2] = 0;
return result;
}
/**
* 居中对齐
* @return
*/
public static byte[] alignCenter()
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 97;
result[2] = 1;
return result;
}
/**
* 右对齐
* @return
*/
public static byte[] alignRight()
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 97;
result[2] = 2;
return result;
}
/**
* 水平方向向右移动col列
* @param col
* @return
*/
public static byte[] set_HT_position( byte col )
{
byte[] result = new byte[4];
result[0] = ESC;
result[1] = 68;
result[2] = col;
result[3] = 0;
return result;
}
//------------------------字体变大-----------------------------
/**
* 字体变大为标准的n倍
* @param num
* @return
*/
public static byte[] fontSizeSetBig(int num)
{
byte realSize = 0;
switch (num)
{
case 1:
realSize = 0;break;
case 2:
realSize = 17;break;
case 3:
realSize = 34;break;
case 4:
realSize = 51;break;
case 5:
realSize = 68;break;
case 6:
realSize = 85;break;
case 7:
realSize = 102;break;
case 8:
realSize = 119;break;
}
byte[] result = new byte[3];
result[0] = 29;
result[1] = 33;
result[2] = realSize;
return result;
}
//------------------------字体变小-----------------------------
/**
* 字体取消倍宽倍高
* @param num
* @return
*/
public static byte[] fontSizeSetSmall(int num)
{
byte[] result = new byte[3];
result[0] = ESC;
result[1] = 33;
return result;
}
//------------------------切纸-----------------------------
/**
* 进纸并全部切割
* @return
*/
public static byte[] feedPaperCutAll()
{
byte[] result = new byte[4];
result[0] = GS;
result[1] = 86;
result[2] = 65;
result[3] = 0;
return result;
}
/**
* 进纸并切割(左边留一点不切)
* @return
*/
public static byte[] feedPaperCutPartial()
{
byte[] result = new byte[4];
result[0] = GS;
result[1] = 86;
result[2] = 66;
result[3] = 0;
return result;
}
//------------------------切纸-----------------------------
public static byte[] byteMerger(byte[] byte_1, byte[] byte_2){
byte[] byte_3 = new byte[byte_1.length+byte_2.length];
System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length);
System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length);
return byte_3;
}
public static byte[] byteMerger(byte[][] byteList){
int length = 0;
for(int i=0;i
{
length += byteList[i].length;
}
byte[] result = new byte[length];
int index = 0;
for(int i=0;i
{
byte[] nowByte = byteList[i];
for(int k=0;k
{
result[index] = nowByte[k];
index++;
}
}
return result;
}
}
4.在以上都完成之后,就可以把你需要的字符串转换成byte数组并调用sendCommand方法来进行打印了
@SuppressLint("NewApi")
public boolean sendCommand(byte[] Content) {
boolean Result;
synchronized (this) {
int len = -1;
if (mConnection != null) {
len = mConnection.bulkTransfer(mEndpointIntr, Content, Content.length, 10000);
}
if (len < 0) {
Result = false;
Log.i(TAG, "发送失败! " + len);
} else {
Result = true;
Log.i(TAG, "发送" + len + "字节数据");
推荐阅读
- android使用ViewPager实现轮播效果教程 android banner轮播图
- Android流式布局如何实现历史搜索记录
- Android安装apk文件并适配Android 安卓怎么安装apk文件
- Android startActivityForResult实例详解
- Android 12 Beta下载地址
- composition什么成分
- 剩下的饺子皮可以做什么美食
- 抖音极速版是什么 抖音极速版是什么旗下的
- 蚂蚁庄园12月7日答案最新:大雪节气不上冻明年可能会出现?冬天下的鹅毛大雪其实是?
- 马化腾旗下的软件有哪些APP 马化腾旗下的软件有哪些
