java通过jnative的sendcommand方法发送打印二维码的命令给打印机,但是打印机打印出的是空白,其他的命令都是可以打印的,只有二维码打印出来的是空白(打印机支持二维码打印,通过赠送的软件是可以打印的)。命令是官方给的,就是不知道为什么打印不了!
enter code here
public class BarcodeTest {
public static void main(String[] args) {
System.out.println(System.getProperty("java.library.path"));
try {
BarcodeTest.barcode_print("xxxxxx");
} catch (NativeException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public static void barcode_print(String barcode_str)throws NativeException, IllegalAccessException {
System.load("C:/WINDOWS/system32/TSCLib.dll");
JNative openport = new JNative("TSCLib.dll","openport");
openport.setParameter(0,"Gprinter GP-3120TL");
openport.invoke();
JNative size = new JNative("TSCLib","sendcommand");
size.setParameter(0, "SIZE 40mm,30mm");
size.invoke();
JNative gap = new JNative("TSCLib","sendcommand");
gap.setParameter(0, "GAP 0mm,0mm");
gap.invoke();
JNative cls = new JNative("TSCLib","sendcommand");
cls.setParameter(0, "CLS");
cls.invoke();
JNative sendcommand = new JNative("TSCLib.dll","sendcommand");
sendcommand.setParameter(0,BarcodeTest.CMD_QRCODE_FROMT_GP3150TN(barcode_str));
sendcommand.invoke();
JNative print = new JNative("TSCLib.dll","sendcommand");
print.setParameter(0, Type.STRING,"PRINT 1,1");
print.invoke();
//清除
JNative clearbuffer = new JNative("TSCLib","clearbuffer");
clearbuffer.invoke();
//关闭
JNative closeport = new JNative("TSCLib","closeport");
closeport.invoke();
}
public static String CMD_QRCODE_FROMT_GP3150TN(String barCode){
StringBuffer sb = new StringBuffer("QRCODE");
sb.append(" ");
sb.append("45,");
sb.append("55,");
sb.append("L,");
sb.append("5,");
sb.append("A,");
sb.append("0,");
sb.append("1,");
sb.append("7,");
sb.append("\"");
sb.append(barCode);
sb.append("\"");
return sb.toString();
}
}