BeeEyeBye Posted June 3, 2021 Report Share Posted June 3, 2021 I'm trying to read six input registers from a remote device but the software I put together doesn't seem to do much; no errors but no read-backs either. I'm a beginner, so the answer is probably simple. The remote device input registers start at 200 hex. The device uses TCP and the IP address is correct. My computer communicates well with the remote device through QmodMaster. Any help you could give would be appreciated. Thanks, Mike. Modbus Read 01.pdf So far 01.vi Quote Link to comment
Rolf Kalbermatter Posted June 4, 2021 Report Share Posted June 4, 2021 Most problems about Modbus communication are related to the different address notations that are commonly used and the fact that some are 0 based while others are 1 based. I also find the distinction between registers, holding registers, coils, and discrete inputs rather confusing. Basically discrete inputs are boolean inputs, coils are boolean outputs and registers are 16 bit inputs and holding registers are 16 bit outputs. Then there is the fact that two registers can often be used together as a 32-bit register or a 32-bit floating point number but as far as the Modbus protocol is concerned need to be treated as 2 consecutive 16-bit values. The valid address range for each of these four types is 0 - 0xFF00 But there is an alternative address writing called entity form. Here the first digit indicates the type of register (0 - coils, 1 - discrete input, 3 - input register, 4 - holding register) and the next four digits indicate the entity address which is 1 based. There are many LabVIEW libraries to do Modbus, but most of them do use the standard address and function code input. Not sure which library you exactly use, but that 256 needs some checkin. 0x200 would be 512 in decimal notation. Quote Link to comment
Mads Posted June 4, 2021 Report Share Posted June 4, 2021 (edited) A couple of notes: a) The code you have will work for reading *Holding* registers (not input) from a slave/server on the given IP and port, but only if that server ignores the unit id or happens to have unit id=1. If it requires a different unit id (many Modbus TCP servers expect it to be 0), right click on the modbus master wire and insert the "Set Unit ID"-function, then wire the correct id to that. b) Assuming the unit id is not preventing the server from bothering to answer you should still get replies from the device even if it does not have any holding registers available, but the replies will then be exception responses and the functions you use will then return an error looking like this (create an indicator within the loop to see it imemdiately): Error -389112 occurred at an unidentified location Possible reason(s): LabVIEW: (Hex 0xFFFA1008) The Modbus slave does not accept the data address contained in the query. Function 3 c) Why two Modbus master connections to the same device? It might support it, but during troubleshooting I would remove the second loop and focus on getting one working. Edited June 4, 2021 by Mads Quote Link to comment
BeeEyeBye Posted June 4, 2021 Author Report Share Posted June 4, 2021 Mads, Thanks for your help. Wouldn't the software read the register specified by the starting address whether it was an input register or holding register? Or is there some built-in protocol that would get confused? Quote Link to comment
Rolf Kalbermatter Posted June 4, 2021 Report Share Posted June 4, 2021 5 minutes ago, BeeEyeBye said: Mads, Thanks for your help. Wouldn't the software read the register specified by the starting address whether it was an input register or holding register? Or is there some built-in protocol that would get confused? Input registers are a totally different entity than holding registers and the Modbus protocol uses different function codes to read them. And a third function code to write to the holding registers. The LabVIEW VIs hide this function code from the user but you have to use the correct read function to cause the correct registers to be read. Quote Link to comment
BeeEyeBye Posted June 4, 2021 Author Report Share Posted June 4, 2021 Rolf, Thanks for your help. I switched the Master Holding Register Read to a Master Input Register Read but still get nothing. The slave doesn't seem to care about the unit id. Qmodmaster returns data whether the unit id is 0, 1 or 2. Address hex 100 works well for Qmodmaster so I used 256 decimal in Labview. Tried 100 hex also, just in case. I'm wondering if Labview is finding its way out of the computer at all. There are no messages and no data. The register value window is greyed out. The DATA TYPE tab is greyed out on the Properties window. Any thoughts? Thanks for your help. Quote Link to comment
Mads Posted June 4, 2021 Report Share Posted June 4, 2021 (edited) 1 hour ago, BeeEyeBye said: Rolf, Thanks for your help. I switched the Master Holding Register Read to a Master Input Register Read but still get nothing. The slave doesn't seem to care about the unit id. Qmodmaster returns data whether the unit id is 0, 1 or 2. Address hex 100 works well for Qmodmaster so I used 256 decimal in Labview. Tried 100 hex also, just in case. I'm wondering if Labview is finding its way out of the computer at all. There are no messages and no data. The register value window is greyed out. The DATA TYPE tab is greyed out on the Properties window. Any thoughts? Thanks for your help. What error code does the Modbus VIs return, if any? Can you try it towards a local Modbus TCP server/simulator, does that work better? Can you temporarily disable the firewall? I used your code as it was, just changed the IP, and it connected immediately to my local Modbus server and was able to read the registers, I also changed the addresses out of that server's range to verify that I got the expected exception response/error I showed earlier. If you can install Wireshark I would use that to sniff and compare the traffic from the LabVIEW code with the one you generate with Qmodmaster (post the Modbus traffic here and we can decode, Wireshark can help you as it is able to decode Modbus too). Edited June 4, 2021 by Mads Quote Link to comment
BeeEyeBye Posted June 8, 2021 Author Report Share Posted June 8, 2021 Mads, Thanks for your help. I got rid of the leading zeros in the IP address and the software reads back the data now! Thanks again for taking the time. Quote Link to comment
herbrtsimth23 Posted December 3, 2021 Report Share Posted December 3, 2021 (edited) I really appreciate your help. It still does nothing when I change the Master Holding Register Read to a Master Input Register Read. It does not appear that the slave cares about the input unit ID. Qmodmaster returns data regardless of the input unit ID. For Qmodmaster, hex 100 works fine, so I used 256 decimal for Labview. I also tried 100 hex. Labview might be making its way out of the computer in some way. No data or messages are available. All the register values are greyed out. When the Properties window is opened, the DATA TYPE tab is greyed out. What could be the problem? Edited December 19, 2021 by herbrtsimth23 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.