Executing Controls
You can construct arbitrary sequences of controls using the Commands
builder class. You can then send these commands to a particular outstation using the association id.
- Rust
- C
- C++
- Java
- C#
if let Err(err) = association
.operate(
CommandMode::SelectBeforeOperate,
CommandBuilder::single_header_u16(
Group12Var1::from_op_type(OpType::LatchOn),
3u16,
),
)
.await
{
tracing::warn!("error: {}", err);
}
note
The Rust API calls the builder class 'CommandBuilder'.
void on_command_success(dnp3_nothing_t nothing, void* arg)
{
printf("command success!\n");
}
void on_command_error(dnp3_command_error_t result, void *arg)
{
printf("command failed: %s\n", dnp3_command_error_to_string(result));
}
dnp3_command_set_t *commands = dnp3_command_set_create();
dnp3_group12_var1_t g12v1 = dnp3_group12_var1_init(dnp3_control_code_init(DNP3_TRIP_CLOSE_CODE_NUL, false, DNP3_OP_TYPE_LATCH_ON), 1, 1000, 1000);
dnp3_command_set_add_g12_v1_u16(commands, 3, g12v1);
dnp3_command_task_callback_t cb = {
.on_complete = &on_command_success,
.on_failure = &on_command_error,
.on_destroy = NULL,
.ctx = NULL,
};
dnp3_master_channel_operate(channel, association_id, DNP3_COMMAND_MODE_SELECT_BEFORE_OPERATE, commands, cb);
dnp3_command_set_destroy(commands);
class CommandTaskCallback : public dnp3::CommandTaskCallback {
void on_complete(dnp3::Nothing result) override {
std::cout << "command succeeded!" << std::endl;
}
void on_failure(dnp3::CommandError error) override {
std::cout << "command failed: "<< dnp3::to_string(error) << std::endl;
}
};
dnp3::CommandSet commands;
commands.add_g12_v1_u8(3, dnp3::Group12Var1(dnp3::ControlCode(dnp3::TripCloseCode::nul, false, dnp3::OpType::latch_on), 0, 1000, 1000));
channel.operate(assoc, dnp3::CommandMode::direct_operate, commands, std::make_unique<CommandTaskCallback>());
CommandSet commands = new CommandSet();
Group12Var1 control = Group12Var1.fromCode(ControlCode.fromOpType(OpType.LATCH_ON));
commands.addG12V1U16(ushort(3), control);
channel
.operate(association, CommandMode.SELECT_BEFORE_OPERATE, commands)
.toCompletableFuture()
.get();
var commands = new CommandSet();
commands.AddG12V1U8(3, Group12Var1.FromCode(ControlCode.FromOpType(OpType.LatchOn)));
var result = await channel.Operate(association, CommandMode.SelectBeforeOperate, commands);
Console.WriteLine($"Result: {result}");
The asynchronous operation will return a single CommandResult
enum that indicates the result. CommandResult.Success
means the outstation responded with Success
for all controls in the message. Consult the language-specific documentation for the meaning
of each error code.