09-23-2020 03:19 AM
Hi All,
I've been having issues with a state machine, which due to numerous complications and hassles, has now become a master/slave setup. I'm using notifications to communicate between a master loop (which relies upon hardware digital inputs to detect state changes), and the various slave loops. The only message in the notification is the current state.
I have some logic which would ideally like to see what the previous state was, so I can detect when a state changes and trigger things to happen at certain state transitions, so being able to see what the previous notification was would be very helpful. I can't seem to figure this out though, as none of the usual tactics like shift registers or feedback loops seem to work with notifiers. Is there a method to do this? I figure that I'm missing something simple.
Cheers,
Kevin
Solved! Go to Solution.
09-23-2020 03:31 AM - edited 09-23-2020 03:33 AM
Hi Vartley,
@Vartley wrote:
I have some logic which would ideally like to see what the previous state was, so I can detect when a state changes and trigger things to happen at certain state transitions, so being able to see what the previous notification was would be very helpful. I can't seem to figure this out though, as none of the usual tactics like shift registers or feedback loops seem to work with notifiers. Is there a method to do this? I figure that I'm missing something simple.
Use a shift register to store the value of the last notification - don't store the notifier reference in the shift register! (That's what I guess from your text.)
When you have problems with your code it most often helps to find them when you would attach that code to your message…
WaitOnNotification also has two options which might help in your case: "Ignore previous?" and TimeOut (with "timed out?" output)!
Why do you use notifications and no queues for your master/slave approach?
09-23-2020 03:51 AM
Hi GerdW,
Sorry, completely forgot the vi.
This is how I attempted to do things, but yeah, didn't work.
I went with notification instead of queues due to the need to have one loop controlling state, and multiple other loops reacting to the state. Queues look unsuited to that task (but I am a newbie so i might be missing something there).
I also played with keeping the shift register uninitialised and putting the control inside the loop, but notifiers just don't seem to work the same way that other data does.
As for shift registering the value, that doesn't work for me either, as the state is controlled in another loop that hang on, I think I know what you mean. I'll give that a go.
09-23-2020 03:59 AM - edited 09-23-2020 04:04 AM
09-23-2020 04:19 AM
Thanks for this GerdW. i got so hung up on trying to get the previous notifier, that I didn't realise that the next step involved me extracting the data from the notifier anyway. Greatly simplified.
Thanks again,
Kevin