readProperty method
Future<BacnetValue>
readProperty(
- int deviceId,
- BacnetObjectType objectType,
- int instance,
- BacnetPropertyId propertyId, {
- int arrayIndex = -1,
- Duration? timeout,
- bool background = false,
- BacnetCancelToken? cancelToken,
override
Reads a property of an object.
Returns the value with its BACnet datatype (BacnetReal, BacnetEnumerated, BacnetCharacterString, ...; see BacnetValue); arrays and lists are a BacnetList. Errors returned by the device throw a BacnetProtocolException.
Concurrent reads of one device are merged into ReadPropertyMultiple
requests unless BacnetConfig.coalesceReads is off; reads of an
arrayIndex are always sent alone.
final value = await client.readProperty(
1234,
BacnetObjectType.analogInput,
1,
BacnetPropertyId.presentValue,
);
switch (value) {
case BacnetReal(:final value):
print('$value °C');
default:
print('unexpected $value');
}
print(value.asDouble); // or null for other datatypes
Implementation
@override
Future<BacnetValue> readProperty(
int deviceId,
BacnetObjectType objectType,
int instance,
BacnetPropertyId propertyId, {
int arrayIndex = -1,
Duration? timeout,
bool background = false,
BacnetCancelToken? cancelToken,
}) {
requests.add(
FakeBacnetRequest(
'readProperty',
deviceId: deviceId,
object: BacnetObject(type: objectType, instance: instance),
propertyId: propertyId,
),
);
return _request(
BacnetConfirmedService.readProperty,
deviceId,
cancelToken,
(device) {
final value = device._read(objectType, instance, propertyId);
if (arrayIndex < 0) return value;
if (value is! BacnetList) {
throw device._error(
BacnetErrorClass.property,
BacnetErrorCode.propertyIsNotAnArray,
);
}
if (arrayIndex == 0) return BacnetUnsigned(value.length);
if (arrayIndex > value.length) {
throw device._error(
BacnetErrorClass.property,
BacnetErrorCode.invalidArrayIndex,
);
}
return value[arrayIndex - 1];
},
);
}