write method
Creates a temporary connection and writes the given metric
Creates a temporary connection and writes the given metric. Requires either AddConnectionS7 or AddConnectionModbus or AddConnectionOPCUA object as request body. Requires also the associated metrics as an array of MetricS7, MetricModbus or MetricOPCUA objects and the value that must be written. Return an array of written values as Value objects or a Error if the write went wrong. You should always ensure that the values were written correctly by reading them right after their writing. If an Internal Server Error occours, an Error object will be returned.
Parameters:
-
WriteRequest writeRequest (required):
-
String uuidToken: Used for remote connections to device
Implementation
Future<List<Status>?> write(
WriteRequest writeRequest, {
required String uuidToken,
}) async {
final response = await writeWithHttpInfo(
writeRequest,
uuidToken: uuidToken,
);
LogbotLogger().simple("ResponseJOJO: ${response.body}");
if (response.statusCode >= HttpStatus.badRequest) {
throw ApiException(response.statusCode, await _decodeBodyBytes(response));
}
// When a remote server returns no body with a status of 204, we shall not decode it.
// At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
// FormatException when trying to decode an empty string.
if (response.body.isNotEmpty &&
response.statusCode != HttpStatus.noContent) {
final responseBody = await _decodeBodyBytes(response);
return (await apiClient.deserializeAsync(responseBody, 'List<Status>')
as List)
.cast<Status>()
.toList();
}
return null;
}