资讯详情

JAVA 调用 DLL 文件 TSCLIB.DLL TSC打印机

这是一段JAVA调用TSC条码打印机代码;详细注释!

1,需要把dll文件拷贝到c:\windows\system32目录下

2.工程需要加载JNative.jar包(网上很多下载)

/******************************************************************************* * $Header$ * $Revision$ * $Date$ * *============================================================================== * * Copyright (c) 2001-2006 Primeton Technologies,Ltd. * All rights reserved. *  * Created on 2011-11-30 Dicky Penghuaibing *******************************************************************************/package com.sie.barcode;import org.xvolks.jnative.JNative;   import org.xvolks.jnative.exceptions.NativeException; public class BarcodeTest {	/**	 * @param args	 */	public static void main(String[] args)throws NativeException,IllegalAccessException { 		BarcodeTest.barcode_print("BAR03743902");	}		//打印方法,传入需要打印的条码参数	public static void barcode_print(String barcode_str)throws NativeException,IllegalAccessException { 		// TODO Auto-generated method stub		 //系统加载dll文件有两种写法1.loadLibrary方法:把dll文件拷贝到c:\windows\system32目录下,引用时只需写dll名字2.load方法:写dll文件的完整路径  		    System.loadLibrary("TSCLIB");//TSCLIB是TES打印机的dll文件  			 		   //参数说明InterfaceFun dll名,AddZhiYe函数名  		    JNative openport = new JNative("TSCLIB","openport");		    //openport.setRetVal(Type.STRING);		    openport.setParameter(0,"TSC TTP-342 Pro");  		    //函数执行  		    openport.invoke();  		    		    int i=0; 		    /*setup(a,b,c,d,e,f,g)			说明: 设定卷标的宽度、高度、打印速度、打印浓度、感应器类别、gap/black mark 垂直间距,gap/black mark 偏移距离)			参数: 			a: 字符串类型,设置卷标宽度,单位 mm				b: 字符串类型,设置卷标高度,单位 mm				c: 字符串类型,设定打印速度,(打印速度随机型不同而有不同的选项)							1.0: 每秒1.0寸打印速度							1.5: 每秒1.5寸打印速度							2.0: 每秒2.0寸打印速度							3.0: 每秒3.0寸打印速度							4.0: 每秒4.0寸打印速度							5.0: 每秒5.0寸打印速度							6.0: 每秒6.0寸打印速度				d: 字符串类别,设置打印浓度,			0~15,数字愈大打印结果愈黑				e: 字符串类别,设置使用感应器类别			0 表示使用垂直间距传感器(gap sensor) 			1 表示使用黑标传感器(black mark sensor)			f: 字符串类别,设置gap/black mark 垂直间距高度,单位: mm			g: 字符串类别,设置gap/black mark 偏移距离,单位: mm,此参数若使用一般卷标时均设为0		    * */		    JNative setup = new JNative("TSCLIB","setup");  		    setup.setParameter(i  ,"50");		    setup.setParameter(i  ,"25");  		    setup.setParameter(i  ,"3");  		    setup.setParameter(i  ,"5");  		    setup.setParameter(i  ,"5");  		    setup.setParameter(i  ,"0");  		    setup.setParameter(i  ,"5");  		    setup.setParameter(i  ,"0");		    setup.invoke();		    		    /*使用条形码机内建条形码打印		     * 5.	barcode(a,b,c,d,e,f,g,h,I)				说明: 使用条形码机内建条形码打印				参数: 				a: 字符串型,条形码X方向起点,以点(point)表示。				(200 DPI,1点=1/8 mm,300 DPI,1点=1/12 mm)				b: 字符串型,条形码Y方向起点,以点(point)表示。				(200 DPI,1点=1/8 mm,300 DPI,1点=1/12 mm)				c: 字符串型,				128				Code 128,switching code subset A,B,C 				automatically 				128M			Code 128,switching code subset A,B,C 				manually.				EAN128			Code 128,switching code subset A,B,C 				automatically							25				Interleaved 2 of 5							25C				Interleaved 2 of 5 with check digits							39				Code 39							39C				Code 39 with check digits							93				Code 93 							EAN13			EAN 13							EAN13 2		EAN 13 with 2 digits add-on							EAN13 5		EAN 13 with 5 digits add-on							EAN8			EAN 8 					EAN8 2			EAN 8 with 2 digits add-on							EAN8 5			EAN 8 with 5 digits add-on							CODA			Codabar							POST			Postnet							UPCA			UPC-A							UPCA 2			UPC-A with 2 digits add-on							UPCA 5			UPC-A with 5 digits add-on							UPCE			UPC-E 							UPCE 2			UPC-E with 2 digits add-on							UPCE 5			UPC-E with 5 digits add-on									d: 字符串型,设定条形码高度,高度以点来表示					e: 字符串型别,设定是否打印条形码码文						0: 不打印码文						1: 打印码文					f: 字符串型别,设定条形码旋转角度						0: 旋转0度						90: 旋转90度						180: 旋转180度						270: 旋转270度					g: 字符串类型,设置条形码窄bar 比例因子,请参考TSPL使用手册					h: 字符串类型,设置条形码窄bar 比例因子,请参考TSPL使用手册					I: 字符串型别,条形码内容 		     */		    i =0;		    JNative barcode = new JNative("TSCLIB","barcode");  		    barcode.setParameter(i  ,"40");  		    barcode.setParameter(i  ,"80");  		    barcode.setParameter(i  ,"39");  		    barcode.setParameter(i  ,"88");  		    barcode.setParameter(i  ,"1"); 		    barcode.setParameter(i  ,"0");  		    barcode.setParameter(i  ,"2");   		    barcode.setParameter(i  ,"4");		    barcode.setParameter(i  ,barcode_str);		    barcode.invoke();  		    /*7.	sendcommand(command)				说明: 送内建指令到条形码打印机				参数: 详细指令请参考TSPL		     */		    JNative sendcommand = new JNative("TSCLIB","sendcommand");  		    sendcommand.setParameter(0,"BAR 400,200,300,100");		    sendcommand.invoke();  		    /*8.	printlabel(a,b)			说明: 打印卷标内容			参数: 				a: 字符串类型,设置打印卷标准数(set)				b: 字符串类型,设置打印卷标记数(copy)			*/		    JNative printlabel = new JNative("TSCLIB","printlabel");  		    printlabel.setParameter(0,"1");		    printlabel.setParameter(1,"1"); 		    printlabel.invoke();  		    //清除		    JNative clearbuffer = new JNative("TSCLIB","clearbuffer"); 		    clearbuffer.invoke();  		    //关闭		    JNative closeport = new JNative("TSCLIB","closeport"); 		    closeport.invoke(); 	}}

 

标签: 黑标传感器

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台