博..条码打印机的java开发

xiaoxiao2021-02-28  84

1。新建java工程

2。然后导入jna.jar

3。把64位的dll和lib拷贝到windows/system32下

4。最后建立自己的main

5。运行代码,如果没有装驱动,会提示没有装驱动

 

系统环境:window7 64bit

开发环境:eclipse mars2,JDK 7 64位

 

注意:.dll文件需要和系统匹配,否则出现找不到dll的情况

 

示例代码:

public class Main {     public interface TscLibDll extends Library {                           TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary("TSCLIB", TscLibDll.class);         int about ();         int openport (String pirnterName);         int closeport ();         int sendcommand (String printerCommand);         int setup (String width,String height,String speed,String density,String sensor,String vertical,String offset);         int downloadpcx (String filename,String image_name);         int barcode (String x,String y,String type,String height,String readable,String rotation,String narrow,String wide,String code);         int printerfont (String x,String y,String fonttype,String rotation,String xmul,String ymul,String text);         int clearbuffer ();         int printlabel (String set, String copy);         int formfeed ();         int nobackfeed ();         int windowsfont (int x, int y, int fontheight, int rotation, int fontstyle, int fontunderline, String szFaceName, String content);     }     public static void main(String[] args) {         //TscLibDll.INSTANCE.about();         TscLibDll.INSTANCE.openport("TSC TTP-2410M");         //TscLibDll.INSTANCE.downloadpcx("C:\\UL.PCX", "UL.PCX");         TscLibDll.INSTANCE.sendcommand("REM ***** This is a test by JAVA. *****");         TscLibDll.INSTANCE.setup("100", "100", "5", "8", "0", "0", "0");         TscLibDll.INSTANCE.clearbuffer();         //TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");         TscLibDll.INSTANCE.printerfont ("100", "10", "3", "0", "1", "1", "(JAVA) DLL Test!!");         TscLibDll.INSTANCE.barcode("100", "40", "128", "50", "1", "0", "2", "2", "123456789");         TscLibDll.INSTANCE.windowsfont(400, 200, 48, 0, 3, 1, "arial", "DEG 0");         TscLibDll.INSTANCE.windowsfont(400, 200, 48, 90, 3, 1, "arial", "DEG 90");         TscLibDll.INSTANCE.windowsfont(400, 200, 48, 180, 3, 1, "arial", "DEG 180");         TscLibDll.INSTANCE.windowsfont(400, 200, 48, 270, 3, 1, "arial", "DEG 270");         TscLibDll.INSTANCE.printlabel("1", "1");         TscLibDll.INSTANCE.closeport();     } }

 

转载请注明原文地址: https://www.6miu.com/read-34176.html

最新回复(0)