question

Carlos S3 avatar image
1 Like"
Carlos S3 asked Joerg Vogel edited

state of a process

Hello,

I'm trying to code the states of a certain processor. That is, I want to be able to determine the state: if it's busy or idle. Is there a way to code it?

Other
Other (please specify)
processorcode editoridlebusy
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

Arun Kr avatar image
3 Likes"
Arun Kr answered Joerg Vogel edited

Hi @Carlos S3,

Yes, you can use an if condition along with an object property method to access the state of the processor. Here I have used a state string. Similarly, you can use a state number.

State number and state string can be known from stats node of the processor tree.

string State = Processor.stats.state().valueString; // returns the state of an object as string
int Statenum = Processor.stats.state().value// returns the state of an object as integer

if condition along with the object property.

Object Processor = model().find("Processor1");
if(Processor.stats.state().valueString == "idle") // Similarly use busy state
{
	Processor.color = Color.red;
}

state-profile screen shot- statenum and statestring are taken from the profile node.

Regards,state.fsm

Arun KR


state.png (48.7 KiB)
state.fsm (14.9 KiB)
· 3
5 |100000

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

Mischa Spelt avatar image Mischa Spelt commented ·

Except instead of

Processor.stats.state().valueString == "idle"

I would recommend using numeric constants:

Processor.stats.state().value == STATE_IDLE
3 Likes 3 ·
Carlos S3 avatar image Carlos S3 commented ·

Hi, I tried your suggestion but I think my version doesn't let me proceed. I'm using an old one. Version 7.3.6

0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel Carlos S3 commented ·
setstate(node("/Processor",model()),STATE_IDLE);

Pre-Dot-syntax-time

getstatenum(node("/Processor",model())) == STATE_IDLE;
2 Likes 2 ·