How to open and close port based on object reference?

How to open and close port based on object reference?

rajankur6494
Collaborator Collaborator
2,311 Views
10 Replies
Message 1 of 11

How to open and close port based on object reference?

rajankur6494
Collaborator
Collaborator

[ FlexSim 23.0.0 ]

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!

0 Likes
Accepted solutions (1)
2,312 Views
10 Replies
Replies (10)
Message 2 of 11

FelixMoehlmann
Collaborator
Collaborator
Accepted solution

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)

0 Likes
Message 3 of 11

rajankur6494
Collaborator
Collaborator

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
Message 4 of 11

rajankur6494
Collaborator
Collaborator
I am looking for something through which we can find the port number of Queue1 at Processor1 and control it.



0 Likes
Message 5 of 11

joerg_vogel_HsH
Mentor
Mentor

Commands

ipopno(..)

opipno(..)


0 Likes
Message 6 of 11

rajankur6494
Collaborator
Collaborator

Hi @Joerg Vogel,

In this method, it is not serving the purpose I need.

I would like to know the port number at which Queue1 is connected to Processor without checking it manually. Since I have multiple cases in my model, I want to automate the process.

Thank you!

0 Likes
Message 7 of 11

joerg_vogel_HsH
Mentor
Mentor

@Ankur A3, you have one set of information input port number and your current object:

The current.inObjects are an array in order of input port connections!

The output port number of your inobjects is the result of ipopno(current,input port number).

I do not understand what you mean by manually. You do this by code to gather this set of information.


0 Likes
Message 8 of 11

FelixMoehlmann
Collaborator
Collaborator

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
Message 9 of 11

jason_lightfoot_adsk
Autodesk
Autodesk

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

0 Likes
Message 10 of 11

rajankur6494
Collaborator
Collaborator
Thank you so much! @Felix Möhlmann

I was looking for exactly same.

0 Likes
Message 11 of 11

Jeanette_Fullmer
Community Manager
Community Manager

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