question

Ankur A3 avatar image
0 Likes"
Ankur A3 asked Jeanette F commented

How to open and close port based on object reference?

Hi Team,

I am developing a model where I need to use object reference directly irrespective of port number to close or input the port between them.


For eg: I would like to open/close the ports of "Processor1" and "Queue1" based on content condition in Queue1.

1676626264900.png

Can you help me with it?

Thank you!

FlexSim 23.0.0
objectreferenceconnectionport
1676626264900.png (9.1 KiB)
· 1
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Jeanette F avatar image Jeanette F ♦♦ commented ·

Hi @Ankur A3, was one of Jason Lightfoot's or Felix Möhlmann's answers helpful? If so, please click the "Accept" button at the bottom of the one that best answers your question. Or if you still have questions, add a comment and we'll continue the conversation.

If we haven't heard back from you within 3 business days we'll auto-accept an answer, but you can always unaccept and comment back to reopen your question.

0 Likes 0 ·
Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Ankur A3 commented

You shouldn't open/close individual port connections, as those are controlled by the internal logic of the fixed resource and your command might be overridden.

To stop items from flowing in your example you would only close the (entire) input of Queue1. For that you only need a reference to Queue1 ("object.input.close()").

If Queue1 had multiple input connections and you only wanted to prevent items flowing through one, you could use intermediate queues with only one input each and close their input.

For completeness: You can get the port number which an object connects to on an upstream or downstream object with "ipopno()" and "opipno" (see command helper in FlexSim for further explanation)

· 7
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Ankur A3 avatar image Ankur A3 commented ·

Hi @Felix Möhlmann,


If Queue1 has multiple input ports, then using your approach may break the space constraint. What will you recommend in this case?

1676631907608.png

Thank you!

0 Likes 0 ·
1676631907608.png (11.7 KiB)
Ankur A3 avatar image Ankur A3 Ankur A3 commented ·
I am looking for something through which we can find the port number of Queue1 at Processor1 and control it.



0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Ankur A3 commented ·

Commands

ipopno(..)

opipno(..)


0 Likes 0 ·
Show more comments
Felix Möhlmann avatar image Felix Möhlmann Ankur A3 commented ·

Based on your example, why would simply limiting the content of the queues to 10 not work in this case? That would require no closing/opening whatsoever.

Update:

If you only have the object reference, then the only option is to loop through the connected objects and compare them to the target. See the user command in the attached model.

getportrank_fm.fsm

0 Likes 0 ·
getportrank-fm.fsm (34.6 KiB)
Ankur A3 avatar image Ankur A3 Felix Möhlmann commented ·
Thank you so much! @Felix Möhlmann

I was looking for exactly same.

0 Likes 0 ·
Jason Lightfoot avatar image
0 Likes"
Jason Lightfoot answered Jason Lightfoot edited

It might be simplest to create your own object using a BasicFR and control the ports yourself.

Or you could use the pull to determine if you are taking items from the upstream object as described below using a Map.

In the attached model at reset I create a Map label 'portMapIn' that is keyed on the input objects so that you can look up the port number quickly - this is a user command 'createPortMapIn'.

There are two other commands closeConnection() and openConnection() that take the receiver and send objects as parameters and update a portClosed label array on the receiver that is referenced by the pull.

If you run to the stop point in the model and step past it you'll see Queue2 received an item from Processor1. If you then repeat that but run the script to close the connection between those two, the transfer does not take place when you perform a step. The transfer then takes place immediately when you open the connection.

portMapforReferencingInobjects.fsm


5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.