Creating Associations
You can create associations on a MasterChannel
by specifying configuration and callback interfaces.
- Rust
- C
- C++
- Java
- C#
let mut association = channel
.add_association(
EndpointAddress::try_new(1024)?,
get_association_config(),
ExampleReadHandler::boxed(),
Box::new(ExampleAssociationHandler),
Box::new(ExampleAssociationInformation),
)
.await?;
note
The Rust API and the binding APIs handle associations in two different ways:
- Bindings return an association token to use on the channel.
- Rust API returns an object that has its own methods for performing operations on the association.
dnp3_association_id_t association_id;
dnp3_param_error_t err =
dnp3_master_channel_add_association(
channel,
1024,
get_association_config(),
get_read_handler(),
get_association_handler(),
get_association_information(),
&association_id
);
// check error
auto assoc = channel.add_association(
1024,
get_association_config(),
std::make_unique<ReadHandler>(),
std::make_unique<AssociationHandler>(),
std::make_unique<AssociationInformation>()
);
AssociationId association =
channel.addAssociation(
ushort(1024),
getAssociationConfig(),
new TestReadHandler(),
new TestAssociationHandler(),
new TestAssociationInformation());
var association = channel.AddAssociation(
1024,
GetAssociationConfig(),
new TestReadHandler(),
new TestAssociationHandler(),
new TestAssociationInformation()
);
The AssociationId
struct that is returned when adding an association is just a token. While it's required to perform operations on a particular outstation on the channel,
you don't need to keep a reference to it unless you need it to perform operations later. Allowing the AssociationId
to be garbage collected won't remove the association from the channel.
Removing
Remove associations from a channel by calling MasterChannel.removeAssociation
and passing in the AssociationId
. Doing so will stop all operations for that association.