Skip to content

Commit 9601c38

Browse files
committed
🚧 add BACnet write test
1 parent 0e6e605 commit 9601c38

File tree

2 files changed

+51
-9
lines changed

2 files changed

+51
-9
lines changed

IOT-Guide-Bacnet/src/main/java/iot/technology/bacnet/BacnetYabeReadTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,22 @@ public static void main(String[] args) throws BACnetException {
4747
public boolean progress(double progress, int deviceId,
4848
ObjectIdentifier oid, PropertyIdentifier pid,
4949
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());
50+
log.info("========");
51+
log.info("progress=" + progress);
52+
log.info("deviceId=" + deviceId);
53+
log.info("oid="+oid.toString());
54+
log.info("pid="+pid.toString());
55+
log.info("UnsignedInteger="+pin);
56+
log.info("value="+value.toString() + " getClass =" +value.getClass());
5757
return false;
5858
}
5959

6060
});
6161
Thread.sleep(3000);
62-
System.out.println("analogInput:0 == " + pvs.get(oid, PropertyIdentifier.presentValue));
62+
log.info("analogInput:0 == " + pvs.get(oid, PropertyIdentifier.presentValue));
6363
//获取指定的presentValue
6464
PropertyValues pvs2 = RequestUtils.readOidPresentValues(localDevice, remoteDevice, Arrays.asList(oid,oid1,oid2),null);
65-
System.out.println("analogInput:1 == " + pvs2.get(oid1, PropertyIdentifier.presentValue));
65+
log.info("analogInput:1 == " + pvs2.get(oid1, PropertyIdentifier.presentValue));
6666
} catch (Exception e) {
6767
e.printStackTrace();
6868
} finally {
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package iot.technology.bacnet;
2+
3+
import com.serotonin.bacnet4j.LocalDevice;
4+
import com.serotonin.bacnet4j.RemoteDevice;
5+
import com.serotonin.bacnet4j.exception.BACnetException;
6+
import com.serotonin.bacnet4j.npdu.ip.IpNetwork;
7+
import com.serotonin.bacnet4j.type.enumerated.ObjectType;
8+
import com.serotonin.bacnet4j.type.enumerated.PropertyIdentifier;
9+
import com.serotonin.bacnet4j.type.primitive.ObjectIdentifier;
10+
import com.serotonin.bacnet4j.type.primitive.Real;
11+
import com.serotonin.bacnet4j.util.RequestUtils;
12+
import com.serotonin.bacnet4j.type.primitive.Boolean;
13+
import iot.technology.bacnet.util.BACnetUtil;
14+
import lombok.extern.slf4j.Slf4j;
15+
16+
import java.util.concurrent.CancellationException;
17+
18+
@Slf4j
19+
public class BacnetYabeWriteTest {
20+
21+
public static void main(String[] args) throws Exception {
22+
IpNetwork ipNetwork = BACnetUtil.initIpNetwork("172.20.16.1", 47808);
23+
LocalDevice localDevice = BACnetUtil.initLocalDevice(123, ipNetwork);
24+
25+
try {
26+
RemoteDevice remoteDevice = localDevice.getRemoteDevice(3309642).get();
27+
//必须先修改out of service为true
28+
RequestUtils.writeProperty(localDevice, remoteDevice, new ObjectIdentifier(ObjectType.analogValue, 0), PropertyIdentifier.outOfService, Boolean.TRUE);
29+
Thread.sleep(1000);
30+
//修改属性值
31+
RequestUtils.writePresentValue(localDevice, remoteDevice, new ObjectIdentifier(ObjectType.analogValue, 0), new Real(76));
32+
Thread.sleep(2000);
33+
log.info("analogValue0: {}", RequestUtils.readProperty(localDevice, remoteDevice, new ObjectIdentifier(ObjectType.analogValue, 0),
34+
PropertyIdentifier.presentValue, null));
35+
} catch (Exception e) {
36+
e.printStackTrace();
37+
} finally {
38+
localDevice.terminate();
39+
}
40+
41+
}
42+
}

0 commit comments

Comments
 (0)