question

A Kamphaus avatar image
1 Like"
A Kamphaus asked Brandon Peterson edited

State Values

I've noticed a lot of objects have states that change values as events occur. I can not seem to find in the user manual which states the values correspond to. The latest one I was trying to find was for the photoeyes so I could determine if it was blocked or not and make a decision based on that. Can someone tell me where I can find the documentation on these?

photo eyestatesstate valuesmacros
5 |100000

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

1 Answer

·
Ben Wilson avatar image
3 Likes"
Ben Wilson answered Brandon Peterson commented

updated answer

Looking in the conveyor's source code we found the following:

InClearTime = 1,
Cleared = 2,
InBlockTime = 3,
Blocked = 4

As of FlexSim 16.0 there are no macros defined to correspond to the above values. Macros would be great, allowing you to use something human readable like PHOTOEYE_STATE_CLEARED instead of just the number 2. I'll send that over to the dev team to consider adding into the software - it seems like something that we should have and that should be documented.

original answer

The state numbers each correspond to a macro value like STATE_IDLE, STATE_PROCESSING, etc, the complete list of which you can find in the Help > User Manual, Under Miscellaneous Concepts > State List. You can use those macros in your FlexScript code if you ever need to check state on an object. For instance:

if (getstate(current)==STATE_IDLE) {
	// do something
}

Let me know if you have any questions or if I misunderstood the question.

· 4
5 |100000

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

Brandon Peterson avatar image Brandon Peterson ♦ commented ·

If you want to define the macros yourself you can do so in at least two different ways.

First (Locally), you can define the macros in the code/trigger where you are using them.

Second (Globally), you can define the macros globally by going in the Tool Box to Modeling Logic > Global Macros.

Here is some sample code to define the macros:

//Define Photoeye State Macros
#define PHOTOEYE_STATE_CLEARING 1
#define PHOTOEYE_STATE_CLEAR 2
#define PHOTOEYE_STATE_BLOCKING 3
#define PHOTOEYE_STATE_BLOCKED 4
3 Likes 3 ·
A Kamphaus avatar image A Kamphaus commented ·

Hi Ben I don't see the PE states in the state list aside from STATE_BLOCKED. What would be the numbers for cleared, clearing, and blocking I was trying to reference it in the following code. It looks like I guessed correctly that 4 is blocked.

/**Custom Code*/

treenode current = param(1);
treenode activity = param(2);
treenode token = param(3);
treenode processFlow = ownerobject(activity);

string nextPE = concat("PE", numtostring(getlabel(token, "Station")+1));

int condition;

condition = getvarnum(node(nextPE, model()),"state") == 4; //blocked?

var value1 = 1;//yes
var value2 = 2;//no

return condition ? value1 : value2;

0 Likes 0 ·
image002.jpg (81.3 KiB)
Ben Wilson avatar image Ben Wilson ♦♦ A Kamphaus commented ·

Sorry I overlooked the bit about photoeyes. I've updated the answer.

2 Likes 2 ·
Ben Wilson avatar image Ben Wilson ♦♦ A Kamphaus commented ·

On a different note, in your code you declare a variable "condition", then you initialize its value on the next line. You could do this all at once like so:

int condition = getvarnum(node(nextPE, model()),"state") == 4;

Its generally discouraged to declare a variable without setting its value, as this can result in junk data being held in that variable. If there is ever a condition where the variable is eventually used without having been instantiated, that junk data can give unpredictable and unrepeatable results, and makes debugging your model more painful.

You do set the variable's value in the very next line, so your particular code will not have any errors, but its best practice to make sure that a variable has a known value right when you declare it, just to avoid debug headaches down the road.

2 Likes 2 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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