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

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

sanaz_karamimoghaddam
Not applicable
193 Views
4 Replies
Message 1 of 5

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

sanaz_karamimoghaddam
Not applicable

[ FlexSim 16.2.0 ]

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.

Accepted solutions (1)
194 Views
4 Replies
Replies (4)
Message 2 of 5

sam_stubbsYXX86
Community Manager
Community Manager

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.

Message 3 of 5

sanaz_karamimoghaddam
Not applicable

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

sam_stubbsYXX86
Community Manager
Community Manager
Accepted solution

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

Message 5 of 5

sanaz_karamimoghaddam
Not applicable

Thanks a lot @Sam Stubbs

0 Likes