資源簡介
使用java實現調用打印機動態指令打印條碼。
代碼片段和文件信息
import?org.xvolks.jnative.JNative;
import?org.xvolks.jnative.Type;
import?org.xvolks.jnative.exceptions.NativeException;
import?org.xvolks.jnative.pointers.Pointer;
import?org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
/**
?*?條形碼打印工具類
?*?
?*?@author?xiaobin_luo
?*?
?*/
public?class?NativeDllFacadeUtil?{
private?static?JNative?term?=?null;
private?static?String?szSavePath?=?“C:\\Argox“;
private?static?String?szSaveFile?=?“C:\\Argox\\PPLA_Example.Prn“;
?private?static?final?String?PRINTER_DLL?=?“Winppla.dll“;?
/**
?*?加載dll文件
?*/
static?{
System.load(“G:\\kd_work\\dll\\BCLW32.dll“);
System.load(“G:\\kd_work\\dll\\WinPort.dll“);
System.load(“G:\\kd_work\\dll\\Winppla.dll“);
System.load(“G:\\kd_work\\dll\\Winpplb.dll“);
}
?private?static?JNative?getJNativeByFunction(String?functionName)?throws?NativeException{?
????????return?new?JNative(PRINTER_DLL?functionName);?
????}?
/**
?*?取得或秀出此函數庫版本資訊。
?*?
?*?@param?nShowMessage
?*????????????0?->?訊息視窗不顯現.?1?->?訊息視窗顯現。
?*?@return
?*?@throws?NativeException
?*?@throws?IllegalAccessException
?*/
private?static?String?A_Get_DLL_Version(int?nShowMessage)
throws?NativeException?IllegalAccessException?{
if?(term?!=?null)?{
term?=?null;
}
String?value?=?““;
term?=?new?JNative(“Winppla.dll“?“A_Get_DLL_Version“/*?函數名?*/);
//term?=?new?JNative(“Winpplb.dll“?“B_Get_DLL_Version“/*?函數名?*/);
term.setRetVal(Type.INT);?/*?返回值類型?*/
term.setParameter(0?0);?/*?左起第一個參數,索引為0?*/
term.invoke();
value?=?term.getRetVal();
return?value;
};
/**
?*?傳回?USB?的資料長度
?*?
?*?@return
?*?@throws?NativeException
?*?@throws?IllegalAccessException
?*/
private?static?int?A_GetUSBBufferLen()?throws?NativeException
IllegalAccessException?{
if?(term?!=?null)?{
term?=?null;
}
int?value?=?0;
term?=?new?JNative(“Winppla.dll“?“A_GetUSBBufferLen“/*?函數名?*/);
//term?=?new?JNative(“Winpplb.dll“?“B_GetUSBBufferLen“/*?函數名?*/);
term.setRetVal(Type.INT);?/*?返回值類型?*/
term.invoke();
value?=?term.getRetValAsInt();
return?value;
};
/**
?*?儲存?USB?埠的資料
?*?
?*?@param?buf
?*????????????儲存?USB?Printer?資料
?*?@return??0?->?OK.
?*?@throws?NativeException
?*?@throws?IllegalAccessException
?*/
private?static?int?A_EnumUSB(byte[]?buf)?throws?NativeException
IllegalAccessException?{
if?(term?!=?null)?{
term?=?null;
}
int?value?=?0;
Pointer?pointer?=?new?Pointer(MemoryBlockFactory.createMemoryBlock(buf.length));??????
pointer.setByteAt(0?buf[0]);
term?=?new?JNative(“Winppla.dll“?“A_EnumUSB“/*?函數名?*/);
//term?=?new?JNative(“Winpplb.dll“?“B_EnumUSB“/*?函數名?*/);
term.setRetVal(Type.INT);?/*?返回值類型?*/
//term.setParameter(0?pointer);?/*?左起第一個參數,索引為0?*/
term.setParameter(0Type.PSTRUCT?buf);
term.invoke();
value?=?term.getRetValAsInt();
return?value;
};
/**
?*?取得?USB?埠的裝置名稱和裝置路徑。
?*?
?*?@param?nPort
?*?@param?pDevice
- 上一篇:javaba
se64-1.3.1 - 下一篇:文本相似度對比器Java
評論
共有 條評論