feat:增加测试打印接口
This commit is contained in:
parent
8fb13e026b
commit
aa46f4c66f
|
@ -21,17 +21,18 @@ public class AutoReplyPrintController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取打印机固件版本
|
* 获取打印机固件版本
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
@GetMapping("CPPrinterGetPrinterFirmwareVersion")
|
@GetMapping("CPPrinterGetPrinterFirmwareVersion")
|
||||||
public Result<?> CPPrinterGetPrinterFirmwareVersion() {
|
public Result<?> CPPrinterGetPrinterFirmwareVersion(@RequestParam(defaultValue = "VID:0x0FE6,PID:0x811E") String USBName) {
|
||||||
try {
|
return autoReplyPrintService.CPPrinterGetPrinterFirmwareVersion(USBName);
|
||||||
return autoReplyPrintService.CPPrinterGetPrinterFirmwareVersion();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.info("获取打印机固件版本失败 {}", e.getMessage());
|
|
||||||
return Result.error("获取打印机固件版本失败");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试打印
|
||||||
|
*/
|
||||||
|
@GetMapping("/testWrite")
|
||||||
|
private Result<?> testWrite(@RequestParam(defaultValue = "VID:0x0FE6,PID:0x811E") String USBName){
|
||||||
|
return this.autoReplyPrintService.testWrite(USBName);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,5 +5,15 @@ import com.dpkj.common.vo.Result;
|
||||||
|
|
||||||
public interface AutoReplyPrintService {
|
public interface AutoReplyPrintService {
|
||||||
|
|
||||||
Result<?> CPPrinterGetPrinterFirmwareVersion();
|
/**
|
||||||
|
* 测试打印
|
||||||
|
* @param USBName USB名称
|
||||||
|
*/
|
||||||
|
Result<?> CPPrinterGetPrinterFirmwareVersion(String USBName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试打印
|
||||||
|
* @param USBName USB名称
|
||||||
|
*/
|
||||||
|
Result<?> testWrite(String USBName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,17 @@
|
||||||
package com.dpkj.modules.autoReplyPrint.service.impl;
|
package com.dpkj.modules.autoReplyPrint.service.impl;
|
||||||
|
|
||||||
|
import com.dpkj.common.exception.RRException;
|
||||||
import com.dpkj.common.vo.Result;
|
import com.dpkj.common.vo.Result;
|
||||||
import com.dpkj.modules.autoReplyPrint.service.AutoReplyPrintService;
|
import com.dpkj.modules.autoReplyPrint.service.AutoReplyPrintService;
|
||||||
import com.dpkj.modules.autoReplyPrint.utils.AutoReplyPrint;
|
import com.dpkj.modules.autoReplyPrint.utils.AutoReplyPrint;
|
||||||
|
import com.dpkj.modules.autoReplyPrint.utils.TestFunction;
|
||||||
import com.sun.jna.Pointer;
|
import com.sun.jna.Pointer;
|
||||||
|
import com.sun.jna.ptr.IntByReference;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
|
@ -15,11 +20,33 @@ public class AutoReplyPrintServiceImpl implements AutoReplyPrintService {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<?> CPPrinterGetPrinterFirmwareVersion() {
|
public Result<?> CPPrinterGetPrinterFirmwareVersion(String USBName) {
|
||||||
Pointer pointer = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb("VID:0x0FE6,PID:0x811E", 1);
|
Result<String> ok = Result.ok();
|
||||||
|
try {
|
||||||
|
Pointer handle = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb(USBName, 1);
|
||||||
|
if ( handle == null ) throw new NullPointerException();
|
||||||
|
ok.setResult(AutoReplyPrint.CP_Printer_GetPrinterFirmwareVersion_Helper.GetPrinterFirmwareVersion(handle));
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.info("获取打印机固件版本失败: {}", e.getMessage(), e);
|
||||||
|
throw new NullPointerException("获取打印机固件版本失败");
|
||||||
|
}
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<?> testWrite(String USBName) {
|
||||||
|
Pointer handle = AutoReplyPrint.INSTANCE.CP_Port_OpenUsb(USBName, 1);
|
||||||
|
AutoReplyPrint.CP_Printer_GetPrinterFirmwareVersion_Helper.GetPrinterFirmwareVersion(handle);
|
||||||
|
|
||||||
|
try {
|
||||||
|
TestFunction fun = new TestFunction();
|
||||||
|
Method m = TestFunction.class.getDeclaredMethod("Test_Port_Write", Pointer.class);
|
||||||
|
m.invoke(fun, handle);
|
||||||
|
}catch (Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RRException("反射调用TestFunction错误");
|
||||||
|
}
|
||||||
|
|
||||||
//String s = autoReplyPrint2Sdk.CPPrinterGetPrinterFirmwareVersion();
|
|
||||||
// log.info("壁挂机打印机版本信息{}", s);
|
|
||||||
return Result.ok("");
|
return Result.ok("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue