Creating Associations
You can create associations on a MasterChannel
by specifying configuration and callback interfaces.
- Rust
- C
- Java
- C#
let mut association = channel
.add_association(
EndpointAddress::from(1024)?,
get_association_config(),
NullReadHandler::boxed(),
DefaultAssociationHandler::boxed(),
)
.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;
err = dnp3_master_channel_add_association(channel, 1024, get_association_config(), get_read_handler(), get_association_handler(), &association_id);
// check error
AssociationId association =
channel.addAssociation(
ushort(1024),
getAssociationConfig(),
new TestReadHandler(),
new TestAssociationHandler());
var association = channel.AddAssociation(
1024,
GetAssociationConfig(),
new TestReadHandler(),
new TestAssocationHandler()
);
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.