I need to register some values of a gas analyser. The connection is RS232 Modbus RTU Salve.
I already did this (Fig.1), but I can not have the results.
Can you help me please?
An incomplete picture of VI doesn't tell the story. Why don't you attach your actual VI? For instance, I can't see if this is running in a loop.
I see three issues.
1. If this is in a while loop that is off screen, you don't want to initialize inside a loop because it will wipe clean the port. Initialization should only be done before a while loop.
2. The Modbus Init in that library assumes a number of stop bits. I have found cases where the device I talk to has a different number of stop bits. I just use a regular VISA Serial Configure to initialize the port. Also, you have a constant 2 wired to the subVI and it shows a coercion dot. Delete that constant, right click on the input, and pick Create Constant. Now you'll have the right data type (an enum) for the parity. Select the correct one.
3. The biggest one and most likely problem, your use of local variables. Why didn't you wire from the Index array to the top of the Division function? You've generated a race condition. The local variables for "element" will get read before the Modbus Read completes.
LabVIEW doesn't work from "left to right". It works on data flow. (Take those LabVIEW tutorials again.) A node will run once all the wires coming into it have values on it. A node will not return value until all the code inside of it has completed.
Hello and thank you for the attention.
I am so sorry, I am a student without experience in Labview.
I tried to do the second point, but I guess I can't.
I understand the 3 point, thank you so much.
However, in relation to the communication I have the same problem. Can you see the file VI?
You did not explain what is exactly the problem. Does the MB Read vi outputs an error? Which one? Or you get some values you believe are wrong? Are you sure that 808 is the right address? The VISA constant in your picture is empty...
Here is a screen shot of what I'm talking about.
I see in some VI's you are using the purple Modbus library, and others the older white library. That should be okay as long as they are working with different serial ports. But it still seems kind of awkward. I'd standardize on one particular library.
I see all over that VI you are abusing local variables, if you are reading from a local variable, you should be reading from the wire that feeds the terminal. Just like I showed in the screenshot.
I also see a lot of "Bytes at Port". That is the wrong thing to use 99% of the time. Depending on the protocol, there is a good chance you are reading partial messages, in which case your decoding scheme will fall apart and you'll get errors or just default data.
What devices are you talking to? Do they have a good protocol that is documented? A good protocol would have a full message as a response that ends with a termination character such as a line feed. You would not use Bytes at Port, but a large number of bytes to read, larger than the length of the response, which would return the full message once it receives the termination character. Look at Crossrulz's recent VI Week presentation for tips on how to do serial communication properly in LabVIEW.
The other thing that concerns me is that you are doing a lot of different things in parallel with serial and DAQmx and modbus all in the same loop. There isn't enough code there to know how quickly each of those activities take. So if let's say a serial port is sending data faster than you are able to service a DAQmx Read function, the slowest thing is going to determine the loop rate, and stuff happening faster might flood the serial port.
I didn't fix everything. This just has what I showed in the screen shot.
Thank you very much for the help.
I change like you said and I do not have the data.
When I trie "1" in the Stop Bits, there is a error message. In the other casos the programme runs but without data (always 0).
The starting adress is correct and the number of the elements too.
Other suggestion? =(
The only suggestions I have are:
1. Read the manuals. Particularly with respect to communication settings.
2. Start small. Don't write one big program that does everything. Write a small program that does one thing like read your modbus device.
3. Once you get one thing working, then start looking at how to add the next piece to get working.
Wait. I do see something else.
In your MB Read Holding registers, you failed to wire a constant to the top of the subVI. It is a cluster that tells it is RTU, and the slave ID. Do you know what your device's slave ID address is? With that input unwired, it defaults to RTU and ID=0. ID is not a valid address for a slave. It is broadcast message so that all slaves will read and react to it, but they are forbidden to respond. Wire up that constant and set the slave ID value to whatever address your slave is set for.