import com.serotonin.bacnet4j.LocalDevice;
import com.serotonin.bacnet4j.RemoteDevice;
import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
import com.serotonin.bacnet4j.npdu.ip.IpNetworkBuilder;
import com.serotonin.bacnet4j.transport.DefaultTransport;
import com.serotonin.bacnet4j.type.Encodable;
import com.serotonin.bacnet4j.type.enumerated.ObjectType;
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;
import com.serotonin.bacnet4j.type.primitive.UnsignedInteger;
import com.serotonin.bacnet4j.util.PropertyValues;
import com.serotonin.bacnet4j.util.ReadListener;
import com.serotonin.bacnet4j.util.RequestUtils;
import java.util.Arrays;
import java.util.List;
/**
* 启动Yabe的天气模拟
* @author Jfei
*
*/
// 读数据操作
public class BACnetUtil {
/**
* Yabe在本地电脑上启动
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
LocalDevice d = null;
try {
//创建网络对象
IpNetwork ipNetwork = new IpNetworkBuilder()
.withLocalBindAddress("172.22.107.219")//本机的ip
.withSubnet("255.255.255.0", 24) //掩码和长度,如果不知道本机的掩码和长度的话,可以使用后面代码的工具类获取
.withPort(47808) //Yabe默认的UDP端口
.withReuseAddress(true)
.build();
//创建虚拟的本地设备,deviceNumber随意
d = new LocalDevice(123, new DefaultTransport(ipNetwork));
d.initialize();
d.startRemoteDeviceDiscovery();
RemoteDevice rd = d.getRemoteDeviceBlocking(3);//获取远程设备,instanceNumber 是设备的device id
System.out.println("modelName=" + rd.getDeviceProperty( PropertyIdentifier.modelName));
System.out.println("analogInput2= " +RequestUtils.readProperty(d, rd, new ObjectIdentifier(ObjectType.analogInput, 2), PropertyIdentifier.presentValue, null));
List<ObjectIdentifier> objectList = RequestUtils.getObjectList(d, rd).getValues();
//打印所有的Object 名称
for(ObjectIdentifier o : objectList){
System.out.println(o);
}
ObjectIdentifier oid = new ObjectIdentifier(ObjectType.analogInput, 0);
ObjectIdentifier oid1 = new ObjectIdentifier(ObjectType.analogInput, 1);
ObjectIdentifier oid2 = new ObjectIdentifier(ObjectType.analogInput, 2);
//获取指定的presentValue
PropertyValues pvs = RequestUtils.readOidPresentValues(d, rd,Arrays.asList(oid,oid1,oid2), new ReadListener(){
@Override
public boolean progress(double progress, int deviceId,
ObjectIdentifier oid, PropertyIdentifier pid,
UnsignedInteger pin, Encodable value) {
System.out.println("========");
System.out.println("progress=" + progress);
System.out.println("deviceId=" + deviceId);
System.out.println("oid="+oid.toString());
System.out.println("pid="+pid.toString());
System.out.println("UnsignedInteger="+pin);
System.out.println("value="+value.toString() + " getClass =" +value.getClass());
return false;
}
});
Thread.sleep(3000);
System.out.println("analogInput:0 == " + pvs.get(oid, PropertyIdentifier.presentValue));
//获取指定的presentValue
PropertyValues pvs2 = RequestUtils.readOidPresentValues(d, rd,Arrays.asList(oid,oid1,oid2),null);
System.out.println("analogInput:1 == " + pvs2.get(oid1, PropertyIdentifier.presentValue));
d.terminate();
} catch (Exception e) {
e.printStackTrace();
if(d != null){
d.terminate();
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
bacnet协议java实现_BACnet

共31个文件
xml:22个
lst:3个
class:2个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
14 浏览量
2022-09-25
01:36:08
上传
评论
收藏 20KB RAR 举报
BACnet协议的流量获取,使用java实现
资源详情
资源评论
资源推荐
收起资源包目录




















































共 31 条
- 1












刘良运
- 粉丝: 25
- 资源: 1万+

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制

评论0