|
4 | 4 | import com.serotonin.bacnet4j.RemoteDevice; |
5 | 5 | import com.serotonin.bacnet4j.exception.BACnetException; |
6 | 6 | import com.serotonin.bacnet4j.npdu.ip.IpNetwork; |
| 7 | +import com.serotonin.bacnet4j.type.Encodable; |
| 8 | +import com.serotonin.bacnet4j.type.enumerated.ObjectType; |
| 9 | +import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier; |
7 | 10 | import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier; |
| 11 | +import com.serotonin.bacnet4j.type.primitive.UnsignedInteger; |
| 12 | +import com.serotonin.bacnet4j.util.PropertyValues; |
| 13 | +import com.serotonin.bacnet4j.util.ReadListener; |
8 | 14 | import com.serotonin.bacnet4j.util.RequestUtils; |
9 | 15 | import iot.technology.bacnet.util.BACnetUtil; |
10 | 16 | import lombok.extern.slf4j.Slf4j; |
11 | 17 |
|
| 18 | +import java.util.Arrays; |
12 | 19 | import java.util.List; |
13 | 20 |
|
14 | 21 | @Slf4j |
15 | 22 | public class BacnetYabeReadTest { |
16 | 23 |
|
17 | 24 | public static void main(String[] args) throws BACnetException { |
18 | | - IpNetwork ipNetwork = BACnetUtil.initIpNetwork("172.30.176.1", 47808); |
| 25 | + IpNetwork ipNetwork = BACnetUtil.initIpNetwork("172.20.16.1", 47808); |
19 | 26 | LocalDevice localDevice = BACnetUtil.initLocalDevice(123, ipNetwork); |
20 | 27 |
|
21 | | - RemoteDevice remoteDevice = localDevice.getRemoteDeviceBlocking(2130082); |
| 28 | + try { |
| 29 | + RemoteDevice remoteDevice = localDevice.getRemoteDeviceBlocking(3309642); |
22 | 30 |
|
23 | | - List<ObjectIdentifier> objectList = RequestUtils.getObjectList(localDevice, remoteDevice).getValues(); |
24 | | - objectList.forEach(objectIdentifier -> { |
25 | | - log.info("objectIdentifier: {}", objectIdentifier); |
26 | | - }); |
| 31 | + log.info("modelName: {}", remoteDevice.getDeviceProperty(PropertyIdentifier.modelName)); |
| 32 | + log.info("analogInput2: {}", RequestUtils.readProperty(localDevice, remoteDevice, |
| 33 | + new ObjectIdentifier(ObjectType.analogInput, 2), |
| 34 | + PropertyIdentifier.presentValue, null)); |
| 35 | + |
| 36 | + List<ObjectIdentifier> objectList = RequestUtils.getObjectList(localDevice, remoteDevice).getValues(); |
| 37 | + objectList.forEach(objectIdentifier -> { |
| 38 | + log.info("objectIdentifier: {}", objectIdentifier); |
| 39 | + }); |
| 40 | + ObjectIdentifier oid = new ObjectIdentifier(ObjectType.analogInput, 0); |
| 41 | + ObjectIdentifier oid1 = new ObjectIdentifier(ObjectType.analogInput, 1); |
| 42 | + ObjectIdentifier oid2 = new ObjectIdentifier(ObjectType.analogInput, 2); |
| 43 | + |
| 44 | + //获取指定的presentValue |
| 45 | + PropertyValues pvs = RequestUtils.readOidPresentValues(localDevice, remoteDevice, Arrays.asList(oid,oid1,oid2), new ReadListener(){ |
| 46 | + @Override |
| 47 | + public boolean progress(double progress, int deviceId, |
| 48 | + ObjectIdentifier oid, PropertyIdentifier pid, |
| 49 | + UnsignedInteger pin, Encodable value) { |
| 50 | + System.out.println("========"); |
| 51 | + System.out.println("progress=" + progress); |
| 52 | + System.out.println("deviceId=" + deviceId); |
| 53 | + System.out.println("oid="+oid.toString()); |
| 54 | + System.out.println("pid="+pid.toString()); |
| 55 | + System.out.println("UnsignedInteger="+pin); |
| 56 | + System.out.println("value="+value.toString() + " getClass =" +value.getClass()); |
| 57 | + return false; |
| 58 | + } |
| 59 | + |
| 60 | + }); |
| 61 | + Thread.sleep(3000); |
| 62 | + System.out.println("analogInput:0 == " + pvs.get(oid, PropertyIdentifier.presentValue)); |
| 63 | + //获取指定的presentValue |
| 64 | + PropertyValues pvs2 = RequestUtils.readOidPresentValues(localDevice, remoteDevice, Arrays.asList(oid,oid1,oid2),null); |
| 65 | + System.out.println("analogInput:1 == " + pvs2.get(oid1, PropertyIdentifier.presentValue)); |
| 66 | + } catch (Exception e) { |
| 67 | + e.printStackTrace(); |
| 68 | + } finally { |
| 69 | + localDevice.terminate(); |
| 70 | + } |
27 | 71 | } |
28 | 72 | } |
0 commit comments