State Values

ITAsset
Not applicable
0 Views
5 Replies
Message 1 of 6

State Values

ITAsset
Not applicable

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?

Accepted solutions (1)
1 View
5 Replies
Replies (5)
Message 2 of 6

ben_wilson5K2EV
Autodesk
Autodesk
Accepted solution

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.

Message 3 of 6

ITAsset
Not applicable

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;

51-image002.jpg

0 Likes
Message 4 of 6

ben_wilson5K2EV
Autodesk
Autodesk

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

Message 5 of 6

ben_wilson5K2EV
Autodesk
Autodesk

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.

Message 6 of 6

brandon_peterson6BCRW
Autodesk
Autodesk

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
img src="https://damassets.autodesk.net/content/dam/autodesk/logos/autodesk-logo-primary-rgbblack-small_forum.png" >

Brandon Peterson
Principal Technology Consultant
>