Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » Multiple instances of an attribute (Capsule/StateMachine)
Multiple instances of an attribute (Capsule/StateMachine) [message #1801766] Fri, 25 January 2019 21:54 Go to next message
Selvaganesh Murugan is currently offline Selvaganesh MuruganFriend
Messages: 10
Registered: December 2018
Junior Member
Hi,

I am trying to create a model (say CassettePlayer) with multiple channels (say more than 2). I created Player capsule, Channel capsule, Top capsule to control the Player and Channel capsules through MusicControlProtocol.

In order to add another Channel, I can drag & drop Channel capsule, rename it as Channel2, add another protocol in Top capsule to talk to Channel 2.

Is there a way to instantiate multiple instances of channel in the code instead of adding it in Top Capsule? If multiplicity can be used here, I am not sure how to do it? Could you please clarify with an example model if possible?

Attached model for reference
Re: Multiple instances of an attribute (Capsule/StateMachine) [message #1801767 is a reply to message #1801766] Fri, 25 January 2019 22:19 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 379
Registered: March 2011
Senior Member
Yes. That's what the "replication" property of parts and ports is for. I've modified your example. I've renamed the player.player port to player.playerChannelPort to avoid confusion. I made the "channel" part with replication 2 and the player.player port to have replication 2 as well (which is needed, since each instance of this port will be connected to the corresponding instance of the channel).

In action code you can send a message from the player to a single channel with

playerChannelPort.Play().sendAt(0);


where the parameter of the sendAt operation is the port index.

You can multi-cast to all channels with send:

playerChannelPort.Play().send();


If a port has multiplicity > 1 and a capsule receives a message on that port, it is possible to determine the port index on which it was received (typically in the transition that received the message) with the 'sapIndex' and 'sapIndex0' methods on the implicit 'msg' parameter of the transition:

int portIndex = msg.sapIndex0();


The difference between 'sapIndex' and 'sapIndex0' is that the first one returns an index counting from 1, whereas the second counts from 0.

When the replication (also known as multipliticy) is a fixed number, that sets a hard bound on the number of port or part instances. If it is set to *, there is no specific bound. The replication can actually be any arithmetic expression that uses variables (attributes) or constants defined in the model (using qualified names if necessary).

Re: Multiple instances of an attribute (Capsule/StateMachine) [message #1801771 is a reply to message #1801767] Sat, 26 January 2019 01:55 Go to previous message
Selvaganesh Murugan is currently offline Selvaganesh MuruganFriend
Messages: 10
Registered: December 2018
Junior Member
Thanks Ernesto! That helps a lot!
Previous Topic:Protocol Messages with user-defined datatype parameters
Next Topic:Use externally defined structure in a signal
Goto Forum:
  


Current Time: Mon May 20 19:45:50 GMT 2019

Powered by FUDForum. Page generated in 0.01849 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top