question

sanaz karamimoghaddam avatar image
1 Like"
sanaz karamimoghaddam asked sanaz karamimoghaddam commented

Code for opening and closing of output port of processor based on value from global table?

I want to compile a custom code that: 1. checks the item type of the first processed item when the processing finishes, (the item type of flow items are available in a global table and in the arrival schedule table of the source.) 2. checks the item type of the next arrival. if the item type of the next flow item is the same as the processed item, keeps the output port closed. But if the item type of the next arrival is different than the processed item, the out put port of the processor should now become open for transporters to pick the items up from the processor.

I will put this code at the processFinish trigger of the processor. I would appreciate help on coding since I am not very familiar with C++ coding.

FlexSim 16.2.0
itemflowcustomecodecloseoutputportitemlookupitemreference
· 2
5 |100000

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

Sam Stubbs avatar image Sam Stubbs ♦ commented ·

Could we see an example of the model? I can give you some general code ideas, but without seeing your model specifically, it's possible that what I'm telling you won't work well in the context of your model. Things like how you're pulling items into the processor could change how you approach this.

1 Like 1 ·
sanaz karamimoghaddam avatar image sanaz karamimoghaddam commented ·

Thanks @Sam Stubbs . I have attached an example of the model here. I want the code to close and open the output port for processor named "Load" in that model.

model-draft-rev-21-sample.fsm

0 Likes 0 ·

1 Answer

Sam Stubbs avatar image
2 Likes"
Sam Stubbs answered sanaz karamimoghaddam commented

In order to achieve what you're looking for, I first added a numeric label to the "Load" processor named "arrival" and set it at 1 to start with. This counts the rows of arrivals from your table. Next I entered the following code in your processor's OnProcessFinish trigger:

/**Custom Code*/
treenode item = param(1);
treenode current = ownerobject(c);


int nextitemtype = gettablenum("SourceArrivalTable",getlabel(current,"arrival")+1,3);


if (getitemtype(item)==nextitemtype) {
	closeoutput(current);
}
else {
	openoutput(current);
}


setlabel(current,"arrival",getlabel(current,"arrival")+1);

This initializes an int variable which gets the itemtype of the next item scheduled to arrive. Then the if else statements check if the current item's itemtype matches the next item scheduled to arrive. If so, then the ports are closed, otherwise they are opened and the transport can take all of the items accumulated there.

Finally after the if else statements the code increments the "arrival" label by one for the next incoming item.

I've reattached your model below with the changes.

2391-model-draft-rev-21-sample.fsm


· 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.

sanaz karamimoghaddam avatar image sanaz karamimoghaddam commented ·

Thanks a lot @Sam Stubbs

0 Likes 0 ·