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
- 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_complete(dnp3_command_result_t result, void *arg)
{
printf("CommandResult: %s\n", dnp3_command_result_to_string(result));
}
dnp3_commands_t *commands = dnp3_commands_new();
dnp3_g12v1_t g12v1 = dnp3_g12v1_init(dnp3_control_code_init(DNP3_TRIP_CLOSE_CODE_NUL, false, DNP3_OP_TYPE_LATCH_ON), 1, 1000, 1000);
dnp3_commands_add_g12v1_u16(commands, 3, g12v1);
dnp3_command_task_callback_t cb = {
.on_complete = &on_command_complete,
.on_destroy = NULL,
.ctx = NULL,
};
dnp3_master_channel_operate(channel, association_id, DNP3_COMMAND_MODE_SELECT_BEFORE_OPERATE, commands, cb);
dnp3_commands_destroy(commands);
Commands commands = new Commands();
G12v1 g12v1 =
new G12v1(
new ControlCode(TripCloseCode.NUL, false, OpType.LATCH_ON),
ubyte(1),
uint(1000),
uint(1000));
commands.addG12v1u16(ushort(3), g12v1);
CommandResult result =
channel
.operate(association, CommandMode.SELECT_BEFORE_OPERATE, commands)
.toCompletableFuture()
.get();
System.out.println("Result: " + result);
var commands = new Commands();
commands.AddG12v1u8(3, new G12v1(new ControlCode(TripCloseCode.Nul, false, OpType.LatchOn), 1, 1000, 1000));
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.