在使用utgard访问OPC服务器,使用异步(Async20Access)读取数据时,总是出错,同步读取就可以,我想问一下,这是什么问题? 下面是console输出:Recieved FAULT 最后接到一个FAULT,不知道什么原因,请赐教!
代码:
public static void main ( final String[] args ) throws Throwable
{
// create connection information
final ConnectionInformation ci = new ConnectionInformation ();
ci.setHost("127.0.0.1"); // 电脑IP
ci.setDomain(""); // 域,为空就行
ci.setUser("opcuser"); // 电脑上自己建好的用户名
ci.setPassword("123456"); //密码
// 使用KEPServer的配置
ci.setClsid("7BC0CC8E-482C-47CA-ABDC-0FE7F9C6E729");
final Set<String> items = new HashSet<String> ();
if ( items.isEmpty () )
{
items.add ("ch1.d1.tag1");
items.add ("ch1.d1.tag2");
}
// create a new server
final Server server = new Server ( ci, Executors.newSingleThreadScheduledExecutor () );
try
{
// connect to server
server.connect ();
// add sync accessfinalAccessBase access =newAsync20Access ( server,100,false);for(finalStringitemId :items ){ access.addItem ( itemId,newDataCallbackDumper () );}// start readingaccess.bind ();// wait a little bit_log.info ("Sleep for some seconds to give events a chance...");Thread.sleep (10*1000);_log.info ("Returned from sleep");// stop readingaccess.unbind ();
}
catch ( final JIException e )
{
System.out.println ( String.format ( "%08X: %s", e.getErrorCode (), server.getErrorMessage ( e.getErrorCode () ) ) );
}
}
}
我发现同样的代码,采用同步读取就没有问题,这是为什么?是不是对异步需要对环境进一步配置?
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4565/viewspace-3153678/ ,如需转载,请注明出处,否则将追究法律责任。