主要是操作LDE。 java 来操作dll动态链接库。
包含 四个文件 JNative.jar. 动态链接库BxADLL.dll.
需要放到 c:\windows\system32目录下面的。 JNativeCpp.dll
源代码:
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.HeapMemoryBlock;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
import org.xvolks.jnative.misc.basicStructures.INT64;
import org.xvolks.jnative.misc.basicStructures.LONG;
import org.xvolks.jnative.misc.basicStructures.HWND;
import org.xvolks.jnative.misc.basicStructures.LPARAM;
import org.xvolks.jnative.misc.basicStructures.HANDLE;
import org.xvolks.jnative.util.Callback;
public class catchDLL2 {
private static JNative v = null;
/**
* 加载的DLL
*/
private static final String DLL_LIB = "BxADLL.dll";
// 强制关机
static void SetScreenState(int a){
int i=0;
try{
v = new JNative(DLL_LIB, "SetScreenState");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
v.setParameter(i++,1);
v.setParameter(i++,a);
p.setStringAt(0,"ScreenStateData1");
v.setParameter(i++,p);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//设置亮度
static void SetScreenLight(int a){
int i=0;
try{
v = new JNative(DLL_LIB, "SetScreenLight");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
v.setParameter(i++,1);
v.setParameter(i++,a);
p.setStringAt(0,"ScreenLight1");
v.setParameter(i++,p);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//设置显示屏参数
static void SetScreenParameter() throws NativeException, IllegalAccessException{
int i = 0;
v = new JNative(DLL_LIB, "SetScreenParameter");
Pointer p3 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p3.setStringAt(0,"ParametetData1");
//设置参数
v.setParameter(i++,1);
v.setParameter(i++,64);
v.setParameter(i++,32);
v.setParameter(i++,2);
v.setParameter(i++,2);
v.setParameter(i++,0);
v.setParameter(i++,0);
v.setParameter(i++,p3);
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}
//发送命令 参数是包含命令的文件
static int SendDataToComm(String pchar,int i){
int ret=1;
try{
v = new JNative(DLL_LIB, "SendDataToComm");
System.out.println(v.getDLLName());
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
Pointer p2 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
//设置参数
v.setParameter(0,1);
v.setParameter(1,i);
v.setParameter(2,64);
v.setParameter(3,32);
v.setParameter(4,2);
p.setStringAt(0,"Com1");
v.setParameter(5,p);
v.setParameter(6,57600);
p2.setStringAt(0,pchar);
v.setParameter(7,p2);
//设置返回值类型
v.setRetVal(Type.LONG);
v.invoke();
//System.out.println("LED设备="+p2.getAsString());
ret = Integer.parseInt(v.getRetVal());
}catch(Exception e){
e.printStackTrace();
}
return ret;
}
//取得发送全部显示屏数据的数据头信息,在添加显示区域信息前添加。
static void GetAllDataHead(){
try{
int i = 0;
v = new JNative(DLL_LIB, "GetAllDataHead");
/*Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p.setStringAt(0,"SendAllDataHead1");*/
//设置参数===================
//显示屏屏号
v.setParameter(i++,1);
//显示屏中区域的个数
v.setParameter(i++,2);
//字幕区域的宽度
v.setParameter(i++,64);
//字幕区域的高度
v.setParameter(i++,32);
//显示屏类型
v.setParameter(i++,2);
//字幕区域信息保存的文件名;
v.setParameter(i++,"SendAllDataHead1");
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//合并显示区域信息文件
static void UnionAreaDataToFile(int a,int b,String file,int c){
try{
int i = 0;
v = new JNative(DLL_LIB, "UnionAreaDataToFile");
/*Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
Pointer p1 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p.setStringAt(0,file);
p1.setStringAt(0,"SendAllData1");*/
//设置参数===================
//pSourceFile是否是区域文件;1:区域文件;0:非区域文件;
v.setParameter(i++,a);
//区域序号;从1开始;
v.setParameter(i++,b);
//预合并信息文件名称
v.setParameter(i++,file);
//合并目标文件名称。
v.setParameter(i++,"SendAllData1");
//0:在原文件下添加合并信息文件;1:删除原文件信息,重新创建合并信息文件
v.setParameter(i++,c);
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//转换 字幕区域显示信息 SendDataTitle1 D1
static void SetScreenTitle(int nAreaOrdID,int x,int y,int hight,int big,String pTitle,int nStunt,int nRunSpeed,int nShowTime){
try{
int i = 0;
v = new JNative(DLL_LIB, "SetScreenTitle");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
//Pointer p1 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
Pointer p2 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p.setStringAt(0,"宋体");
//p1.setStringAt(0,pTitle);
p2.setStringAt(0,"SendDataTitle1");
//设置参数===================
//区域序号
v.setParameter(i++,nAreaOrdID);
//字幕区域的横坐标
v.setParameter(i++,x);
//字幕区域的纵坐标
v.setParameter(i++,y);
//字幕区域的长度
v.setParameter(i++,64);
//字幕区域的高度
v.setParameter(i++,hight);
//显示屏类型
v.setParameter(i++,2);
//点阵类型
v.setParameter(i++,1);
//字幕区域显示字体
v.setParameter(i++,p);
//字幕区域显示字号
v.setParameter(i++,big);
//字幕区域显示颜色; 1:红色;2:绿色;3:黄色
v.setParameter(i++,1);
//粗体;1:粗体;0正常
v.setParameter(i++,0);
//斜体;1:斜体;0正常
v.setParameter(i++,0);
//下划线;1:下划线;0正常
v.setParameter(i++,0);
//字幕区域显示的字幕滚动信息
v.setParameter(i++,pTitle);
//字幕区域显示特技;具体特技特征字见注1;
v.setParameter(i++,nStunt);
//字幕区域信息运行速度
v.setParameter(i++,nRunSpeed);
//字幕区域信息停留时间
v.setParameter(i++,nShowTime);
//字幕区域信息保存的文件名;
v.setParameter(i++,p2);
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//设置亮度
static void setLight(int a){
//设置亮度 SetScreenLight(1--15) ScreenLight1
SetScreenLight(a);
int ret=SendDataToComm("ScreenLight1",0xc8);
if(ret==1) System.out.println("亮度设置发送成功");
else System.out.println("亮度设置发送失败");
}
//强制开关机
static void setState(int a){
//强制开关机 SetScreenState(1表示开机 0表示关闭); ScreenStateData1
SetScreenState(a);
int opendown=SendDataToComm("ScreenStateData1",0xC4);
if(opendown==1) System.out.println("开关机发送成功");
else System.out.println("开关机发送失败");
}
//设置屏参
static void setParameter() throws NativeException, IllegalAccessException{
//设置显示屏参数 SetScreenParameter(); ParametetData1
SetScreenParameter();
int par=SendDataToComm("ParametetData1",0xC1);
if(par==1) System.out.println("显示屏参数发送成功");
else System.out.println("显示屏参数发送失败");
}
// UnionAreaDataToFile 1:区域文件;0:非区域文件; 区域序号;从1开始;
//0:在原文件下添加合并信息文件;1:删除原文件信息,重新创建合并信息文件
//发送字幕 message1显示上面 message2显示下面
public static void SendMessage(String message1,String message2){
GetAllDataHead();
UnionAreaDataToFile(0,0,"SendAllDataHead1",1);
//16是字幕显示高度 12是字体大小
SetScreenTitle(1,0,0,16,12,message1,1,1,2);
UnionAreaDataToFile(1,1,"SendDataTitle1",0);
SetScreenTitle(2,0,16,16,12,message2,1,1,2);
UnionAreaDataToFile(1,2,"SendDataTitle1",0);
//设置字幕 SetScreenTitle(); SendDataTitle1
//SetScreenTitle();
int title=SendDataToComm("SendAllData1",0xD1);
if(title==1) System.out.println("向显示屏发送数据成功");
else System.out.println("向显示屏发送数据失败");
}
// 发送字幕 message1显示上面 全屏显示
public static void SendOne(String message1){
GetAllDataHead();
UnionAreaDataToFile(0,0,"SendAllDataHead1",1);
SetScreenTitle(1,0,0,32,24,message1,1,1,2);
UnionAreaDataToFile(1,1,"SendDataTitle1",0);
//设置字幕 SetScreenTitle(); SendDataTitle1
//SetScreenTitle();
int title=SendDataToComm("SendAllData1",0xD1);
if(title==1) System.out.println("向显示屏发送数据成功");
else System.out.println("向显示屏发送数据失败");
}
public static void main(String[] args) {
try{
//1~15 亮度增加
//setLight(1);
//0关机 1 开机
//setState(1);
//设置屏参
//setParameter();
SendMessage("浙A-T56865","杭州威玛计算机系统有限公司");
//SendOne("中国你好");
}catch(Exception ne){
System.err.println("listAllDevice NativeException!");
//releaseCard();
ne.printStackTrace();
}
}
}
包含 四个文件 JNative.jar. 动态链接库BxADLL.dll.
需要放到 c:\windows\system32目录下面的。 JNativeCpp.dll
源代码:
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.HeapMemoryBlock;
import org.xvolks.jnative.pointers.memory.MemoryBlockFactory;
import org.xvolks.jnative.misc.basicStructures.INT64;
import org.xvolks.jnative.misc.basicStructures.LONG;
import org.xvolks.jnative.misc.basicStructures.HWND;
import org.xvolks.jnative.misc.basicStructures.LPARAM;
import org.xvolks.jnative.misc.basicStructures.HANDLE;
import org.xvolks.jnative.util.Callback;
public class catchDLL2 {
private static JNative v = null;
/**
* 加载的DLL
*/
private static final String DLL_LIB = "BxADLL.dll";
// 强制关机
static void SetScreenState(int a){
int i=0;
try{
v = new JNative(DLL_LIB, "SetScreenState");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
v.setParameter(i++,1);
v.setParameter(i++,a);
p.setStringAt(0,"ScreenStateData1");
v.setParameter(i++,p);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//设置亮度
static void SetScreenLight(int a){
int i=0;
try{
v = new JNative(DLL_LIB, "SetScreenLight");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
v.setParameter(i++,1);
v.setParameter(i++,a);
p.setStringAt(0,"ScreenLight1");
v.setParameter(i++,p);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//设置显示屏参数
static void SetScreenParameter() throws NativeException, IllegalAccessException{
int i = 0;
v = new JNative(DLL_LIB, "SetScreenParameter");
Pointer p3 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p3.setStringAt(0,"ParametetData1");
//设置参数
v.setParameter(i++,1);
v.setParameter(i++,64);
v.setParameter(i++,32);
v.setParameter(i++,2);
v.setParameter(i++,2);
v.setParameter(i++,0);
v.setParameter(i++,0);
v.setParameter(i++,p3);
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}
//发送命令 参数是包含命令的文件
static int SendDataToComm(String pchar,int i){
int ret=1;
try{
v = new JNative(DLL_LIB, "SendDataToComm");
System.out.println(v.getDLLName());
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
Pointer p2 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
//设置参数
v.setParameter(0,1);
v.setParameter(1,i);
v.setParameter(2,64);
v.setParameter(3,32);
v.setParameter(4,2);
p.setStringAt(0,"Com1");
v.setParameter(5,p);
v.setParameter(6,57600);
p2.setStringAt(0,pchar);
v.setParameter(7,p2);
//设置返回值类型
v.setRetVal(Type.LONG);
v.invoke();
//System.out.println("LED设备="+p2.getAsString());
ret = Integer.parseInt(v.getRetVal());
}catch(Exception e){
e.printStackTrace();
}
return ret;
}
//取得发送全部显示屏数据的数据头信息,在添加显示区域信息前添加。
static void GetAllDataHead(){
try{
int i = 0;
v = new JNative(DLL_LIB, "GetAllDataHead");
/*Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p.setStringAt(0,"SendAllDataHead1");*/
//设置参数===================
//显示屏屏号
v.setParameter(i++,1);
//显示屏中区域的个数
v.setParameter(i++,2);
//字幕区域的宽度
v.setParameter(i++,64);
//字幕区域的高度
v.setParameter(i++,32);
//显示屏类型
v.setParameter(i++,2);
//字幕区域信息保存的文件名;
v.setParameter(i++,"SendAllDataHead1");
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//合并显示区域信息文件
static void UnionAreaDataToFile(int a,int b,String file,int c){
try{
int i = 0;
v = new JNative(DLL_LIB, "UnionAreaDataToFile");
/*Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
Pointer p1 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p.setStringAt(0,file);
p1.setStringAt(0,"SendAllData1");*/
//设置参数===================
//pSourceFile是否是区域文件;1:区域文件;0:非区域文件;
v.setParameter(i++,a);
//区域序号;从1开始;
v.setParameter(i++,b);
//预合并信息文件名称
v.setParameter(i++,file);
//合并目标文件名称。
v.setParameter(i++,"SendAllData1");
//0:在原文件下添加合并信息文件;1:删除原文件信息,重新创建合并信息文件
v.setParameter(i++,c);
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//转换 字幕区域显示信息 SendDataTitle1 D1
static void SetScreenTitle(int nAreaOrdID,int x,int y,int hight,int big,String pTitle,int nStunt,int nRunSpeed,int nShowTime){
try{
int i = 0;
v = new JNative(DLL_LIB, "SetScreenTitle");
Pointer p = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
//Pointer p1 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
Pointer p2 = new Pointer(MemoryBlockFactory.createMemoryBlock(100));
p.setStringAt(0,"宋体");
//p1.setStringAt(0,pTitle);
p2.setStringAt(0,"SendDataTitle1");
//设置参数===================
//区域序号
v.setParameter(i++,nAreaOrdID);
//字幕区域的横坐标
v.setParameter(i++,x);
//字幕区域的纵坐标
v.setParameter(i++,y);
//字幕区域的长度
v.setParameter(i++,64);
//字幕区域的高度
v.setParameter(i++,hight);
//显示屏类型
v.setParameter(i++,2);
//点阵类型
v.setParameter(i++,1);
//字幕区域显示字体
v.setParameter(i++,p);
//字幕区域显示字号
v.setParameter(i++,big);
//字幕区域显示颜色; 1:红色;2:绿色;3:黄色
v.setParameter(i++,1);
//粗体;1:粗体;0正常
v.setParameter(i++,0);
//斜体;1:斜体;0正常
v.setParameter(i++,0);
//下划线;1:下划线;0正常
v.setParameter(i++,0);
//字幕区域显示的字幕滚动信息
v.setParameter(i++,pTitle);
//字幕区域显示特技;具体特技特征字见注1;
v.setParameter(i++,nStunt);
//字幕区域信息运行速度
v.setParameter(i++,nRunSpeed);
//字幕区域信息停留时间
v.setParameter(i++,nShowTime);
//字幕区域信息保存的文件名;
v.setParameter(i++,p2);
//设置返回值类型
//v.setRetVal(Type.INT);
v.invoke();
}catch(Exception e){
e.printStackTrace();
}
}
//设置亮度
static void setLight(int a){
//设置亮度 SetScreenLight(1--15) ScreenLight1
SetScreenLight(a);
int ret=SendDataToComm("ScreenLight1",0xc8);
if(ret==1) System.out.println("亮度设置发送成功");
else System.out.println("亮度设置发送失败");
}
//强制开关机
static void setState(int a){
//强制开关机 SetScreenState(1表示开机 0表示关闭); ScreenStateData1
SetScreenState(a);
int opendown=SendDataToComm("ScreenStateData1",0xC4);
if(opendown==1) System.out.println("开关机发送成功");
else System.out.println("开关机发送失败");
}
//设置屏参
static void setParameter() throws NativeException, IllegalAccessException{
//设置显示屏参数 SetScreenParameter(); ParametetData1
SetScreenParameter();
int par=SendDataToComm("ParametetData1",0xC1);
if(par==1) System.out.println("显示屏参数发送成功");
else System.out.println("显示屏参数发送失败");
}
// UnionAreaDataToFile 1:区域文件;0:非区域文件; 区域序号;从1开始;
//0:在原文件下添加合并信息文件;1:删除原文件信息,重新创建合并信息文件
//发送字幕 message1显示上面 message2显示下面
public static void SendMessage(String message1,String message2){
GetAllDataHead();
UnionAreaDataToFile(0,0,"SendAllDataHead1",1);
//16是字幕显示高度 12是字体大小
SetScreenTitle(1,0,0,16,12,message1,1,1,2);
UnionAreaDataToFile(1,1,"SendDataTitle1",0);
SetScreenTitle(2,0,16,16,12,message2,1,1,2);
UnionAreaDataToFile(1,2,"SendDataTitle1",0);
//设置字幕 SetScreenTitle(); SendDataTitle1
//SetScreenTitle();
int title=SendDataToComm("SendAllData1",0xD1);
if(title==1) System.out.println("向显示屏发送数据成功");
else System.out.println("向显示屏发送数据失败");
}
// 发送字幕 message1显示上面 全屏显示
public static void SendOne(String message1){
GetAllDataHead();
UnionAreaDataToFile(0,0,"SendAllDataHead1",1);
SetScreenTitle(1,0,0,32,24,message1,1,1,2);
UnionAreaDataToFile(1,1,"SendDataTitle1",0);
//设置字幕 SetScreenTitle(); SendDataTitle1
//SetScreenTitle();
int title=SendDataToComm("SendAllData1",0xD1);
if(title==1) System.out.println("向显示屏发送数据成功");
else System.out.println("向显示屏发送数据失败");
}
public static void main(String[] args) {
try{
//1~15 亮度增加
//setLight(1);
//0关机 1 开机
//setState(1);
//设置屏参
//setParameter();
SendMessage("浙A-T56865","杭州威玛计算机系统有限公司");
//SendOne("中国你好");
}catch(Exception ne){
System.err.println("listAllDevice NativeException!");
//releaseCard();
ne.printStackTrace();
}
}
}