ATTENTIONThis FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices. |
flexsim.com |
#1
|
|||
|
|||
On Message Trigger
Attached is the first major model I have been trying to get running in Flexsim. I think its nearly working ok however there is 1 problem.
When the combiners on the left hand side output a pallet they send a message to each of the 12 queues (Q1-Q2). The code in the onMessage trigger of the queues does not seem to execute properly. I have similar code on the OnEntryTrigger for the same objects that appears to work fine. The pallets have a label called "Full" if this =2 then its full and =1 is empty. The idea is that if an empty pallet is in a Q and its itemtype is at the top of the global table "Demand" then when it receives a message it will open the output port of the queue. This logic appears to work for the OnEntryTrigger without any problems. If anybody can offer any advice or guidance then it is greatly appreciated. Anth |
#2
|
|||
|
|||
Hi Anthony,
It looks like the entry code has been copied directly to the messagetrigger which is not good for trying to access the item in the queue. John is making the change to your model (and some other tweaks) and will send you a new copy soon. Best wishes Jason |
#3
|
||||
|
||||
Hi Anthony,
I've take a look at your model. If you use the sendmessage or senddelayedmessage command you have the commands "msgsendingobject msgparam(1,2 or 3)" available to query the parameters that you have passed in the sendmessage or senddelayedmessage call. Actually these commands are just wrappers for parval(1...4) or parnode(1..4) parnode(1) will give you the messagesendingobject, while parval(2,3 and 4) give you the passed other parameters. When I look at the onmessage code of the queue, you define an item variable as parnode(1). This means that your item equals the message sendingobject which also means that querying the labels and the itemtypes don't work. You can check by writing something like pt(getname(parnode(1))) to the outputconsole. So you can either passthe item as the messagesendingobject where you create the sendmessage or you can pass the item as a parameter. Hope this helps you further. Steven |
The Following User Says Thank You to Steven Hamoen For This Useful Post: | ||
arunkrmahadeva (02-26-2016) |
#5
|
||||
|
||||
Steven,
Your post is very helpful for me to understand how OnMessage trigger works. Since msgsendingobject and msgparam are just wrappers of parnode and parval, does this mean we can actually using parnode and parval in the OnMessage trigger and we are actually able to pass more than 3 values? Thanks. Alan |
#6
|
||||
|
||||
Hi Alan,
Basically if you would call the onmessage with the nodefunction command, yes. But then there is no delay in calling it, so that would only work if you used it instead of sendmessage. (the sendmessage/senddelayedmessage commands are the limiting factors here concerning the no of parameters) As far as I understood, the no of parameters could probably be expanded in those 2 commands but for speed reasons, it is kept as it right now. Maybe Anthony or AJ could confirm this. Regards, Steven |
#7
|
||||
|
||||
Right now you're limited to 3 message parameters because the sendmessage command is routed through the FlexsimObject, which only passes 3 of the parameters on to the message trigger nodefuncton. The senddelayedmessage command also has to convert the parameters into a space delimited string in order to be able to put it on the event queue, and this can be pretty slow, so that is another reason we've limited it to 3 parameters. We may add more parameters in the future though, especially if we are able to get a faster method working for senddelayedmessage()
|
#8
|
||||
|
||||
Steven and Anthony,
Thanks for the reply. One way to pass more than 3 parameters is to pass a treenode and put parameter values under that treenode. Actually this should work for all commands. I guess as long as doing this will not bring any running speed issue, it should be fine. Alan |
#9
|
|||
|
|||
A doubt to learner..
Dear Steven,
Please refer your reply dated 09-06-07, Inform me how to define an item as msg sending object (msg param 1) and what are the others (msgparam2,3). Can I have a small example along with your reply? |
#10
|
||||
|
||||
Dear Kedar,
If you have the statement; "sendmessage( current, item, 1, 2, 3);" and you write this statement on your onentry trigger of any object , the moment a product enters a message will be send to the object which entry trigger is fired. Inside the message trigger if you query the msgsendingobject it will point to the item. So for instance if you would write pt( getname(msgsendingobject)); The name of the item would be written to the tracer window. with the command msgparam(1), msgparam(2) and msgparam(3) you get access to the last 3 parameters of the sendmessage command. So in this case they would return 1,2 and 3. I hope this is sufficient, if not please try it yourself and if it doesn't do what you want, post the model and I'll take a look. Steven |
#11
|
||||
|
||||
Multiple messages on the same object
Hello,
how can we refer to separate message-sending objects and msg-parameters in 'OnMessage-trigger' of the msg-receiving object, if there are more than one object sending messages to that object at the same time, with own msg-parameters? Thanks. |
#12
|
|||
|
|||
Hi,
i dont know if i understand it correct, but normaly i write my code like: Code:
/* the message looks like: senddelayedmessage(outobject(current,1),0,current,1,4,tonum(item)); */ /* On Message Trigger */ ... // declaring the sending object treenode fs_sender = msgsendingobject(); // number variables int i_var1 = msgparam(1); double d_var2 = msgparam(2); // referencing to an object treenode fs_var3 = tonode(msgparam(3)); // i_var1 = switchcondition switch(i_var1).. Maybe you have a second condition, then use the second one.. Its also possible to make a overview and a custom condition list. In this case you build up a matrix with 2 variables. ie. i_var1 - 1 to 10: sending object 1; 11 to 20: sending object 2;... d_var2 - 1 to 5: ... and so on. Thats how i solve most of my problems.. Hope you understand what i mean, and hope i´m right in understanding what you mean ^^ regards tobias |
#13
|
||||
|
||||
Thank you Tobias for your suggestion, but I think I couldn't state my question clearly:
Let's say I have a queue and 3 processors connected to that. OnEntry trigger of the queue, processors send their state-variable (getstatenum(processor1/2/3)) as a message to the queue, which means the queue receives 3 different messages from different objects at the same time, each one including one msg-parameter in it. Then, in OnMessage trigger of the queue, I'd like to send items to processors, depending on their state-variables that they sent in the message. When I define the following, for example: Code:
int processorstate1 = msgparam(1); How can I refer to three different msgsendingobjects and to their msg-parameters? I hope this explains my question better. |
#14
|
|||
|
|||
Yasemin,
the command msgsendingobject() returns a reference to the ofbject that sent the message... example from the documentation: treenode sender = msgsendingobject(); so you could use int processorstate1 = getstatenum(sender); to get the state of the processor that sent the message... hope this helps.. regards, Pablo Concha E. |
The Following User Says Thank You to Pablo Concha For This Useful Post: | ||
Yasemin Vatandas (08-13-2008) |
#15
|
||||
|
||||
Thank you Pablo, the problem is that there are 3 different objects that I want to refer to as msgsendingobjects.
What I want to do is something like this: int processorstate1 = getstatenum(msgsendingobject1); int processorstate2 = getstatenum(msgsendingobject2); int processorstate3 = getstatenum(msgsendingobject3); Since msgsendingobject() does not have any indexes, I cannot implement the above code. Maybe I should try a different way. Thanks. |
#16
|
||||
|
||||
I think you are trying to send messages with parameters and you can use
send[delayed]message(too,[time,]from[,Param1 or [getstatenum(current)],Param2,Param3]) [optional] then on the Message trigger if(msgparam(1) == Param1) {woot code;} Last edited by Xavier Jackson; 08-13-2008 at 07:48 AM. Reason: better |
#17
|
|||
|
|||
Don't think i see the problem, the onmessage trigger gets executed at the time the message is received.. if the delay of the message is zero, the onmessage will be executed for each message on order.. not all three at the same time...
int processorstate = getstatenum(msgsendingobject); will have the state of the processor of the object that sent the message at that time... so you could set the code you want: if(processorstate == number) { command(msgsendingobject); } if you want different code depending the processor that sent the message, you could put a label "processor" on each processor with different values (1/2/3).. and the you could do: if(processorstate == number && getlabelnum(msgsendingobject,"processor") == 1) { command1(msgsendingobject); } if(processorstate == number && getlabelnum(msgsendingobject,"processor") == 1) { command2(msgsendingobject); } if(processorstate == number && getlabelnum(msgsendingobject,"processor") == 1) { command3(msgsendingobject); } (you could also send the number of the processor as a parameter of the message..) maybe i'm not understanding the question, my english is not that good regards, Pablo Concha E. |
#18
|
||||
|
||||
Yasemin,
When you have each processor send a message to the object you will only get one message at a time not three. They will occur as seperate events (if they are delayed messages or are sent in different events) or will occur as seperate function calls (if they are direct messages sent in the same event). I am assuming that you want to be able to have one message that will contain a pointer to each object. If this is the case then you can use the tonum() and tonode() commands. This would allow you to use the getstatenum() command in the message trigger instead of sending the states as parameters. So, for example if I wanted to send pointers in a message I might have te following line of code: sendmessage(centerobject(current, 1), current, tonum(processor1), tonum(processor2), tonum(processor3) //I am assuming I already have pointers to processors 1/2/3 In the message I could then have the following code: treenode p1 = tonode(msgparam(1)); treenode p2 = tonode(msgparam(2)); treenode p3 = tonode(msgparam(3)); From here I could use the treenodes to get the states or whatever else I wanted from the three processors. However, I would normally not do it this way. I would use center port connections. So, if I were sending a message to another object I would make sure that the objects I wanted to check were connected to the center ports of the receiving or sending object. This way I wouldn't have to use the extra commands. Good Luck, Brandon
__________________
thats not normal. |
The Following 3 Users Say Thank You to Brandon Peterson For This Useful Post: | ||
Yasemin Vatandas (08-13-2008) |
#19
|
||||
|
||||
Xavier, Pablo, thanks for the replies.
I thought that the messages would be received at the same time, since I do not use a senddelayedmessage. Brandon, thanks for the explanation. It is clear to me now. |
#20
|
||||
|
||||
Yasemin,
The reason that they still don't happen at the same time is because they are different function calls. Think of it like a tree, and every time you come to a new branch (function) you have to follow that branch all the way to the tip before retuning back to the trunk to go to the next branch. So your code actually executes as follows: 1. Sendmessage(); 1a. Message Trigger on Recieving object 2. Sendmessage(); 2a. Message Trigger on Recieving object 2a-1. Openinput(); 2a-1a. OnExit of incoming object 2a-1b. OnEntry of Object 3. Sendmessage(); 3a. Message Trigger on Recieving object I hope this illustrates a the point clearly. Many people, including advanced users, will run into cases where they are getting confusing result because the code is executing in a sequence that they didn't expect. Brandon
__________________
thats not normal. |
The Following User Says Thank You to Brandon Peterson For This Useful Post: | ||
Yasemin Vatandas (08-13-2008) |