80,362
社区成员
发帖
与我相关
我的任务
分享
private void printSensorInfoLabel(String sensorType, String sensorSn, String sensorIndex) {
LabelCommand tsc = new LabelCommand();
tsc.addSize(20, 10);
tsc.addGap(2); // 设置标签间隙,按照实际尺寸设置,如果为无间隙纸则设置为0
tsc.addDirection(DIRECTION.BACKWARD, MIRROR.NORMAL);// 设置打印方向
tsc.addReference(0, 0);// 设置原点坐标
tsc.addTear(ENABLE.ON); // 撕纸模式开启
tsc.addCls();// 清除打印缓冲区
// 20*10尺寸
tsc.add1DBarcode(20, 10, BARCODETYPE.CODE128, 40, READABEL.DISABLE, ROTATION.ROTATION_0, 1, 35, sensorSn);
if (sensorType.equals("综合控制单元")) {
// 20*10尺寸
tsc.addText(5, 45, FONTTYPE.SIMPLIFIED_CHINESE, ROTATION.ROTATION_0, FONTMUL.MUL_1, FONTMUL.MUL_1, sensorType + " " + sensorSn);
} else {
// 20*10尺寸
tsc.addText(10, 45, FONTTYPE.SIMPLIFIED_CHINESE, ROTATION.ROTATION_0, FONTMUL.MUL_1, FONTMUL.MUL_1, sensorType + " " + sensorIndex + " " + sensorSn);
}
tsc.addPrint(1, 1); // 打印标签
tsc.addSound(2, 100); // 打印标签后 蜂鸣器响
tsc.addCashdrwer(LabelCommand.FOOT.F5, 255, 255);
Vector<Byte> datas = tsc.getCommand(); // 发送数据
byte[] bytes = GpUtils.ByteTo_byte(datas);
String str = Base64.encodeToString(bytes, Base64.DEFAULT);
int rel;
try {
rel = mGpService.sendLabelCommand(0, str);
GpCom.ERROR_CODE r = GpCom.ERROR_CODE.values()[rel];
if (r != GpCom.ERROR_CODE.SUCCESS) {
Toast.makeText(getApplicationContext(), GpCom.getErrorText(r), Toast.LENGTH_SHORT).show();
}
} catch (RemoteException e) {
e.printStackTrace();
}
}