oil-station/fuintBackend/fuint-application/src/test/java/dyj.java

119 lines
4.1 KiB
Java
Raw Normal View History

2024-08-27 10:18:27 +08:00
import com.fuint.common.util.TscLibDll;
import com.fuint.fuintApplication;
import com.sun.jna.Library;
import com.sun.jna.Native;
import javafx.print.Printer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.StandardCharsets;
@RunWith(SpringJUnit4ClassRunner.class)
//@RunWith(SpringRunner.class)
@SpringBootTest(classes = fuintApplication.class)
@Transactional
public class dyj {
private static final String LOAD_LIBRARY = "TSCLIB";
public interface TscLibDll extends Library {
TscLibDll INSTANCE = (TscLibDll) Native.loadLibrary("TSCLIB", TscLibDll.class);
// 以下为dll函数库支持的方法方法的作用与参数说明见附件【dll函数库api文档】
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);
}
@Test
public void tt() {
// TscLibDll.INSTANCE.openport("GP-58MB Series");
// System.loadLibrary(LOAD_LIBRARY);
System.setProperty("jna.encoding", "GBK");
// TscLibDll.INSTANCE.about();
// TscLibDll.INSTANCE.openport("TSC TTP-2410M");
TscLibDll.INSTANCE.openport("GP-58MB Series");
TscLibDll.INSTANCE.sendcommand("------------交班统计------------");
// // 2.设置打印机纸张规格
// TscLibDll.INSTANCE.setup("100", "100", "5", "8", "0", "0", "0");
// // 3.清除上次打印后的缓存
// TscLibDll.INSTANCE.clearbuffer();
// // 4.将字体写入暂存区准备打印
// TscLibDll.INSTANCE.printerfont ("100", "10", "3", "0", "1", "1", "(JAVA) DLL Test!!");
// // 5.调用打印机打印
// TscLibDll.INSTANCE.printlabel("1", "1");
// 6.断开和打印机的连接
TscLibDll.INSTANCE.closeport();
// TscLibDll.INSTANCE.sendcommand("REM ***** This is a test by JAVA. *****");
// TscLibDll.INSTANCE.sendcommand("PUTPCX 550,10,\"UL.PCX\"");
// 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");
}
/**
* 蜂鸣
*/
public static void buzzing(Printer printer) {
// System.loadLibrary(LOAD_LIBRARY);
//
//// TscLibDll.INSTANCE.openport(printer.getName());
// TscLibDll.INSTANCE.openport("GP-58MB Series");
//
//// TscLibDll.INSTANCE.sendBinaryData(Command.BUZZING.getCommandBytes(), Command.BUZZING.getCommandBytes().length);
// TscLibDll.INSTANCE.closeport();
}
}
enum Command {
/** 切纸 */
CUT_PAPER(new byte[]{0x1D, 0x56, 1}),
/** 蜂鸣 */
BUZZING(new byte[]{0x1B,0x42,2,6 }),
/** 水平居中 */
ALINE_CENTER(new byte[]{0x1B,0x61,1 }),
/** 左对齐 */
ALINE_LEFT(new byte[]{0x1B,0x61,0 }),
/** 右对齐 */
ALINE_RIGHT(new byte[]{0x1B,0x61,2 }),
/** 行间距 */
LINE_HEIGHT_DEFAULT(new byte[]{0x1B,0x32}),
/** 横向跳格 */
SKIP_SPACE(new byte[]{0x1B,0x44,16,20,24,28 });
Command(byte[] commandBytes) {
this.commandBytes = commandBytes;
}
private byte[] commandBytes;
public byte[] getCommandBytes() {
return commandBytes;
}
}