08-06-2014 01:04 PM
Hello there,
Looking for a much bit of advise.
I am using the NI labview modbus library, RTU mode, using a USB to 485 converter. The library works fine as expected and performs all the read/write operations implemented in the library.
I am trying to design an application to control 20 slaves to perform a simple operation and read a register back from each slave, evaluate the value and to increment a counter if this value read is a '1'.
Now, the application needs to be automatic, sort of pressing "start" button and then to sequentially perform the writing to each slave, wait 5 mins to perform the operation, and then read the register of each one, update the counter..and back again.. continuously until you press "stop".
I started to shape the application with a flat sequence structure, with a first sub diagram containing the writing operation, and then wait 5 mins and so the second sub diagram would undertake the reading and update the counters.
1)First problem I have encountered is a very silly one, how to increment the value of the register to address the slaves sequentially in the first subdiagram in an effective way.
Any advise about how to do it?
I have tried a for loop (see attached) and use the iteration index to try to increase the address register but I struggle to covert the type of data..is there any easy way to do it, for instance ensuring I send two times the command to each slave?
Ideally I would to send command to slave #1 and then slave #2..etc.. but I am not sure how to do that.
2)How to stop the execution for 5 mins to let the slaves operate, and then carry out the reading?
Solved! Go to Solution.
08-06-2014 02:56 PM
For loops are a basic concept. So is incrementing a value. You didn't attach whatever you were trying to attach so it is impossible to see what you are doing wrong.
Please attach the VI and it should be easy enough to see the problem and tell you how to correct it.
Also, instead of using flat sequence structures and long waits between frames, you should look at a state machine architecture. One state would be send data, another would be wait where it continually checks to see if the 5 minutes have passed. Other states could be any initialization and clean-up code.
08-07-2014 03:18 AM
Sorry about that RavensFan, and thanks for reply.
I think my message was trimmed, guess was too long.
I was also thinking that, the problem is that at this moment I do not know how to implement a state machine in labview. I have seen a couple of examples of state machines but at the moment I am not able to tweak them in order to do what I say above.
Please find attached.
Thanks in advance
08-07-2014 04:48 AM
Hi Rcano_1982,
Thank you for your question.
State machine is a very powerfull and scalable architecture.
In order to fully understand it, please have a read of the following articles:
1. Application Design Patterns: State Machines
http://www.ni.com/white-paper/3024/en/
2. Tutorial: State Machines
http://www.ni.com/white-paper/7595/en/
Then please do an exercise:
http://www.ni.com/white-paper/7604/en/
Once you went through the information above you should be able
to apply this concept to your application.
Kind Regards,
08-07-2014 05:39 AM
Thanks for the info.
It seems to be "dummy proof" like me..state machine creation is well explained
I will go through it and hopefully will come up with a less raw vi.
Thanks again
08-07-2014 10:22 AM
Attached is a modified VI to show how to get the VI to talk to both devices.
Note that intialization and closing of the serial port belong outside the while loop and not executed on every iteration of the while loop.
08-07-2014 10:37 AM
Many Thanks RavensFan,
I am looking into it right now, made some progress today hope in the right direction,,shortly will post a new version based on a state machine as per suggested.
08-07-2014 10:58 AM
Hello again
This is the progress done so far. As mentioned, I have impelmented a state machine with three states: "write command", "wait 5 mins", and "read registers".
Yet I am completing the reading state, which after reviewing RavensFan latest post I am not sure if I go in the right direction. Do I need to do the initialization outside of the while loop??
Regarding "reading data" state I am little bit confused about how to read the value of a register of each slave, sotring it in an arrey and then use indiviudally the value of each register information to update a counterfrom the register how do I store data in the
basically talking in "C" language terms" how to implement a pointer to the array, increment it, and populate each counter to show in the UI..
Thanks again in advance
08-07-2014 11:24 AM
First, all of your enums are different, as can be seen by the coercion dots wherever you compare them to eacy other or feed them into the shift register. Your enum constant that initializes the shift register looks complete. All the rest seem to be incomplete. When working with state machines, the first step that should be almost mandatory is to make your enum that defines all of your steps a typedef. That way when you compare them to each other, or add a new state, they all get updated and they can all be compared to each other properly.
Yes, the initialization should be before the while loop. Alternatively, Initialize could be a state within the while loop that you execute first before moving. Your "Start Application" state seems to be the perfect spot for this. (PS, you spelled "Disinfection" wrong.)
Your "pointer" question. Store your arrays in a shift register so their values are maintained from one iteration to the next. If you are incrementing an index, store the index value in a shift register as well.
08-08-2014 09:35 AM
Ravens Fan,
Thanks for your comments, I have understood a little bit better how to handle these variables, and solved the issues you pointed at.
Now, please see attached, my state machine is almost completed although not working fully ok. Modbus though is set up properly, at least is sending writing commands to the slaves.
But I have got two problems I am not able to solve at the moment.
1. First when I finish "5min" state and jumps to "reading" state the Elapse VI function does not stop counting.How do I stop it? and more importantly, why is it working, when the system is in a different state!?
2. When reading state is completed should go to writing again, but despite that state is actually being sent to the shift register, "reading" state remains why is this happening?
Thanks again