我正在与门禁控制和考勤机连接 我发现这个项目在github中使用java连接到相同类型 但在我想设置CardNumber属性的行中,我有一个例外 “ com.jacob.com.ComFailException:无法将名称映射为dispid:CardNumber [0]” 有人可以帮我
https://github.com/lookskystar/ZKKQProject/blob/master/ZKKQProject/src/com/zkkq/uitl/ZkemSDK.java
public class ZkemSDK
{
private static ActiveXComponent zkem ;
public ZkemSDK(){
zkem = new ActiveXComponent("zkemkeeper.ZKEM.1");
System.out.println("done ");
}
public boolean connect(String address,int port, int machineNum) throws Exception{
boolean result = zkem.invoke("Connect_NET",address,port).getBoolean();
}
public boolean SetUserInfo(int machineNum,int enrollNo2,String userName,String password,int privelage ,boolean flag) {
Variant dwUserName = new Variant(userName,true);
Variant dwPassword = new Variant(password,true);
Variant dwPrivelage = new Variant(privelage,true);
Variant dwEnrollNo = new Variant(enrollNo2,true);
Variant dwMachineNum= new Variant(machineNum,true);
/****/
zkem.setProperty("CardNumber[0]",454545);
/****/
Variant vResult = Dispatch.call(zkem,"SetUserInfo",dwMachineNum, dwEnrollNo, dwUserName, dwPassword, dwPrivelage,true);
return true;
}
}
答案 0 :(得分:0)
我发现有人可以覆盖setProperty来添加数组 在此链接 setParameter for an array property with JACOB 我的代码就是这个
public static void setProperty(Dispatch d, String sName, String sIndex, String sValue) {
Variant av[] = { new Variant(sIndex), new Variant(sValue) };
int j[]= {0};
Dispatch.invokev(d, sName, Dispatch.Put, av,j).safeRelease();
av[0].safeRelease(); av[1].safeRelease();
}
呼叫就像这样
this.setProperty(zkem,"CardNumber","0","2599970");
此行之前
Variant vResult = Dispatch.call(zkem,"SetUserInfo",dwMachineNum, dwEnrollNo, dwUserName, dwPassword, dwPrivelage,true);