ATTENTION

This 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

Go Back   FlexSim Community Forum > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 09-06-2007
Anthony Timmiss Anthony Timmiss is offline
Flexsim User
 
Join Date: Aug 2007
Location: Sunderland - UK
Posts: 78
Downloads: 41
Uploads: 0
Thanks: 65
Thanked 45 Times in 28 Posts
Rep Power: 187
Anthony Timmiss will become famous soon enoughAnthony Timmiss will become famous soon enough
Default 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
Attached Files
File Type: zip AxleTest.zip (248.1 KB, 501 views)
  #2  
Old 09-06-2007
Jason Lightfoot Jason Lightfoot is offline
Flexsim Consultant
 
Join Date: Aug 2007
Location: Somerset, UK
Posts: 719
Downloads: 20
Uploads: 0
Thanks: 123
Thanked 953 Times in 446 Posts
Rep Power: 773
Jason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond reputeJason Lightfoot has a reputation beyond repute
Default

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  
Old 09-06-2007
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

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)
  #4  
Old 09-07-2007
Anthony Timmiss Anthony Timmiss is offline
Flexsim User
 
Join Date: Aug 2007
Location: Sunderland - UK
Posts: 78
Downloads: 41
Uploads: 0
Thanks: 65
Thanked 45 Times in 28 Posts
Rep Power: 187
Anthony Timmiss will become famous soon enoughAnthony Timmiss will become famous soon enough
Default Thanks

Thanks for the help from Saker and Steve. I've got the problem resolved now.

Anth
  #5  
Old 10-03-2007
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 225
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

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  
Old 10-04-2007
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

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  
Old 10-04-2007
Anthony Johnson's Avatar
Anthony Johnson Anthony Johnson is offline
Manager of Product Development
 
Join Date: Jul 2007
Posts: 440
Downloads: 86
Uploads: 4
Thanks: 171
Thanked 899 Times in 288 Posts
Rep Power: 735
Anthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond reputeAnthony Johnson has a reputation beyond repute
Default

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  
Old 10-05-2007
AlanZhang's Avatar
AlanZhang AlanZhang is offline
Flexsim Super Moderator
 
Join Date: Aug 2007
Location: CA
Posts: 289
Downloads: 64
Uploads: 0
Thanks: 88
Thanked 91 Times in 47 Posts
Rep Power: 225
AlanZhang is a jewel in the roughAlanZhang is a jewel in the roughAlanZhang is a jewel in the rough
Default

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  
Old 01-03-2008
kedar kedar is offline
Flexsim User
 
Join Date: Dec 2007
Posts: 2
Downloads: 0
Uploads: 0
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
kedar is on a distinguished road
Default 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  
Old 01-03-2008
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

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  
Old 08-13-2008
Yasemin Vatandas's Avatar
Yasemin Vatandas Yasemin Vatandas is offline
Flexsim User
 
Join Date: Jul 2008
Location: Hamburg, Germany
Posts: 36
Downloads: 9
Uploads: 0
Thanks: 29
Thanked 3 Times in 3 Posts
Rep Power: 146
Yasemin Vatandas is on a distinguished road
Question 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  
Old 08-13-2008
tobias.biemueller tobias.biemueller is offline
Flexsim User
 
Join Date: Aug 2007
Location: Bielefeld, Germany
Posts: 42
Downloads: 22
Uploads: 0
Thanks: 23
Thanked 18 Times in 16 Posts
Rep Power: 164
tobias.biemueller is on a distinguished road
Default

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)..
If you have to differ severel more cases..then use at first time the 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  
Old 08-13-2008
Yasemin Vatandas's Avatar
Yasemin Vatandas Yasemin Vatandas is offline
Flexsim User
 
Join Date: Jul 2008
Location: Hamburg, Germany
Posts: 36
Downloads: 9
Uploads: 0
Thanks: 29
Thanked 3 Times in 3 Posts
Rep Power: 146
Yasemin Vatandas is on a distinguished road
Default

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);
Does the above statement refer to the state of the first, second or the third processor?
How can I refer to three different msgsendingobjects and to their msg-parameters?

I hope this explains my question better.
  #14  
Old 08-13-2008
Pablo Concha Pablo Concha is offline
Flexsim User
 
Join Date: Aug 2007
Posts: 104
Downloads: 100
Uploads: 1
Thanks: 103
Thanked 52 Times in 37 Posts
Rep Power: 232
Pablo Concha is just really nicePablo Concha is just really nicePablo Concha is just really nicePablo Concha is just really nice
Default

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  
Old 08-13-2008
Yasemin Vatandas's Avatar
Yasemin Vatandas Yasemin Vatandas is offline
Flexsim User
 
Join Date: Jul 2008
Location: Hamburg, Germany
Posts: 36
Downloads: 9
Uploads: 0
Thanks: 29
Thanked 3 Times in 3 Posts
Rep Power: 146
Yasemin Vatandas is on a distinguished road
Default

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  
Old 08-13-2008
Xavier Jackson's Avatar
Xavier Jackson Xavier Jackson is offline
Flexsim User
 
Join Date: Jun 2008
Posts: 20
Downloads: 11
Uploads: 0
Thanks: 21
Thanked 4 Times in 3 Posts
Rep Power: 147
Xavier Jackson is on a distinguished road
Default

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  
Old 08-13-2008
Pablo Concha Pablo Concha is offline
Flexsim User
 
Join Date: Aug 2007
Posts: 104
Downloads: 100
Uploads: 1
Thanks: 103
Thanked 52 Times in 37 Posts
Rep Power: 232
Pablo Concha is just really nicePablo Concha is just really nicePablo Concha is just really nicePablo Concha is just really nice
Default

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  
Old 08-13-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

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  
Old 08-13-2008
Yasemin Vatandas's Avatar
Yasemin Vatandas Yasemin Vatandas is offline
Flexsim User
 
Join Date: Jul 2008
Location: Hamburg, Germany
Posts: 36
Downloads: 9
Uploads: 0
Thanks: 29
Thanked 3 Times in 3 Posts
Rep Power: 146
Yasemin Vatandas is on a distinguished road
Default

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  
Old 08-13-2008
Brandon Peterson's Avatar
Brandon Peterson Brandon Peterson is offline
The Flexsim Consultant
 
Join Date: Jul 2007
Location: Salt Lake City, Utah
Posts: 382
Downloads: 29
Uploads: 6
Thanks: 192
Thanked 516 Times in 235 Posts
Rep Power: 490
Brandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant futureBrandon Peterson has a brilliant future
Default

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)



All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.