12-08-2010 03:17 PM
PLease find attached jpeg file showing outlay of my program. I am using queued state machine architecture for my program and I find it very useful. Although I have some doubts regarding its implementation. I understand the qsm architecture very well now, thanks to the coke machine example. But, my application has more to it than what the coke machine shows. Anyway, the event structure cases handle "value changes" and those controls will change values when they receive commands from a "3rd" parallel loop that receives hex codes through RS232 port from another software.
When for example a code A0 is received, Boolean State1 = TRUE and the corresponding case in State machine is run. But, some commands are followed by data. For eg. A4 0025 means speed = 2.5mph. Which means, A4 handles State2=TRUE but 2.5mph has to be sent to control in "main SM" . What is the best way to handle data transfer between parallel loops? Would property nodes work perfectly or should the data be handled in a more complex way like this article says.
http://expressionflow.com/2007/10/01/labview-queued-state-machine-architecture/
Any help would be really appreciated. Thanks!
Vj
12-08-2010 03:25 PM
Oops! I also forgot. There is also a fourth parallel loops that constantly acquires voltages from 3 analog inputs and this data is read by different states in main state machine to perform digital and analog outputs.
12-08-2010 05:08 PM
No need to doubt whether it would work. It can work. Though one question I have is that in your code screen shot, I don't see anywhere that you are dequeuing the elements from the queue.
Many implementations of queued state machines will use a cluster as the queue element. It will contain the enum which is the command or next state you want to send. The other element is a variant. With that, you can pack any kind of data into the queue element to be passed along with the command. In the command for A4, you could pass along the data. Your consumer loop will unbundle the command enum, and the variant. When the case for the A4 command runs, you can use the variant to be able to convert it back to meaningful data that you can place in the appropriate indicator terminal.
12-09-2010 02:01 AM
What's usually done is to use Dequeue in the consumer loop so the queue is optimally 0 length. That way you wont really need the wait 1000ms (you can have a timeout to the deqeue which will fire your Wait).
/Y
12-09-2010 04:12 AM
My suggestion would be to send data via user events to the event handling loop. See my nugget here how I do it.
Also make sure that the message handling SM is decoupled from the messages. This means that the state type def isn't the same as the queue message type def.
Felix
12-09-2010 03:05 PM - edited 12-09-2010 03:14 PM
@ ravens fan.
I am dequeuing states in the wait state of stATE machine. I have attached the vi. (It is just a layout). THe third loops receives data from RS232 port. commands for event handler and data for main vi. Similarly, feedback from mainvi has to be sent back through RS232 (loop) along with ACK. In this structure that I have, how do I split command and data like you mentioned? I have explained in my previous attachment jpeg about my requirements.
@ Yamaeda
For some reason, after dequeing. length isnt 0. How do I make sure that happens? Sometimes, after the test is done and when I get to STOP state, it oscillates between STOP and state1. Hope I am making this clear.
@ Schubert
I followed the example provided by NI. Coke machine example. Here the State type def is enum and the queue message type def is the same. Am I missing something here?
PLease refer to my attachment vi. I really need help in getting this right because it is an interesting coding architecture and I am glad I atleast got the basics right.
VJ
12-09-2010 03:14 PM - edited 12-09-2010 03:17 PM
Unbundle the cluster.
By the way, your dequeueing is rather awkward. You are dequeing a command, but passing it to the next iteration of the for loop through a shift register. Usually, you dequeue and then immediately act on that command in the same iteraiton. This probably explains your bouncing between state 1 and stop.
12-09-2010 03:23 PM - edited 12-09-2010 03:30 PM
THanks raven fan for your immediate response. So what you are saying is that I wouldn't need an event handler at all? OK I will explain what I have on my RS232 driver program.
It is a loop that constantly listens for commands from COM port and based on what command is read, I have a case structure within this loop itself which sets (for eg )STATE 1 BOOLEAN = TRUE using a property node or reference. When the event handler see that STATE 1 BOOLEAN is TRUE, it sends the STATE enum for STATE 1 on the queue and main vi SM reads that state and executes it.
I have attached my RS232 driver program to show what it does. THanks a ton!
VJ
12-09-2010 03:25 PM - edited 12-09-2010 03:26 PM
To put it in simpler terms, I am kinda (but not quite UNBUNDLE CLUSTER) unbundling the command and data in the RS232 driver program itself. If that makes any sense. And the RS232 driver program is the third parallel loop I was talking about
12-13-2010 09:44 AM - edited 12-13-2010 09:52 AM
@ ravens fan! Hello!
The data coming in from RS232 port is all of the same format (command and data). They are all in hex form. I am creating a case structure like in the program I attached, and convert the hex code to decimal and check if certain value is read, I go into that case value and in that I read the next four bytes to read data. There is no clear distinction like command and data. I should have explained clearer. All that comes from the port are values and based on a data sheet, values for eg. 160, 161, 162, 163 and 164 (decimal) etc are commands; next 4 bytes following each of those is data .
Jay