/**
*
*/
package com.jdgroup.utilwork.util;
import org.jawin.DispatchPtr;
import org.jawin.win32.Ole32;
/**
* @author Guo Long
*
* Oct 16, 2008
*/
public class ComUtil {
public ComUtil() {
}
public static String getXmlFromComByTcp(String _xml) throws Exception {
String rXml = "";
DispatchPtr objCom = null;
try {
Ole32.CoInitialize();
objCom = new DispatchPtr("KACom.KACom.1");
if (null == objCom)
return "";
rXml = (String) objCom.invoke("TCPSend", ConstantKey.IP,
new Integer(7600), _xml);
if(null!=rXml){
System.out.println("接收xml字符串:" + rXml);
// 去掉xml文件头,再加带gbk的头,解决中文问题
int p = rXml.indexOf("?>");
rXml = rXml.substring(p + 2);
rXml = "<?xml version=\"1.0\" encoding=\"gbk\" ?>" + rXml;
}else{
System.out.println("COM组件没有返回数据!rXml: " + rXml);
}
} catch (Exception error) {
error.printStackTrace();
} finally {
if (objCom != null)
objCom.close();
Ole32.CoUninitialize();
}
return rXml;
}
/*
* 获得加密码后的密码ecyPwd
*/
public static String getEncodePasswordFromComByTcp(String strPassword)
throws Exception {
String ecyPwd = "";
DispatchPtr objCom = null;
try {
Ole32.CoInitialize();
objCom = new DispatchPtr("KACom.KACom.1");
if (null == objCom)
return "";
ecyPwd = (String) objCom.invoke("EncodePassword", strPassword);
} catch (Exception error) {
error.printStackTrace();
} finally {
if (objCom != null)
objCom.close();
Ole32.CoUninitialize();
}
return ecyPwd;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
java com串口组件调用实例.rar (1个子文件)
java com串口组件调用实例
ComUtil.java 2KB
共 1 条
- 1
资源评论
guogang3411
- 粉丝: 10
- 资源: 48
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功