Vidmas30 Posted January 26, 2011 Report Share Posted January 26, 2011 Hi, everybody, We are having application where V120 connected through RS485 (port 1) to powermeter using Modbus RTU. We made in our program that PLC gets data from power meter (4 registers) 2 times in a day. I wanted to ask if someone could advice or maybe has a simple example how to do data request of these 4 registers. We done in that way: Data request MB1 MB2 ------[P]----------(S) MB2 MB0(function in progress) MB2 -----[ ]-----------[ / ]--------------------------------[Read holding register 1]----------( R ) MB2 MB3 ------[N]----------(S) MB3 MB0(function in progress) MB3 -----[ ]-----------[ / ]--------------------------------[Read holding register 2]----------( R ) MB3 MB4 ------[N]----------(S) MB4 MB0(function in progress) MB4 -----[ ]-----------[ / ]--------------------------------[Read holding register 3]----------( R ) MB4 MB5 MB1 ------[N]----------(S)----------( R ) MB5 MB0(function in progress) MB5 -----[ ]-----------[ / ]--------------------------------[Read holding register 4]----------( R ) At the beginning it works fine, but there are issues: data does'nt change couple days, then changes or we get answers not from all registers.. I mean we not always get data. Maybe we are doing something wrong. Thank you for your help! Link to comment Share on other sites More sharing options...
Ofir Posted January 26, 2011 Report Share Posted January 26, 2011 Hi Vidmas, Does all the 4 registers are consecutive? If yes then set the length of the RHR command to 4. If not then try to set a delay between the commands and test again. Link to comment Share on other sites More sharing options...
Vidmas30 Posted January 26, 2011 Author Report Share Posted January 26, 2011 Hi, Ofir, Thanks for quick reply! No, they're not consecutive. Their addresses are: Register1 - 3120, Register2 - 3122, Register3 - 3124, Register4 - 3126. And about delay: is there any sense to do delay? I think the bit conditions allow to read next register, only when previous been read? Or I understand not good? Link to comment Share on other sites More sharing options...
Ofir Posted January 26, 2011 Report Share Posted January 26, 2011 Hi Vidmas, According to our expirience the slave sometimes needs short silence between the commands and this is the reason why we recommend to set a small delay between the commands. I think first it is better to test it with the delay in order to know whether indeed this is the issue. Link to comment Share on other sites More sharing options...
Vidmas30 Posted January 26, 2011 Author Report Share Posted January 26, 2011 Thank you, Ofir, I'll try it and will post the results! Link to comment Share on other sites More sharing options...
Ziwi Posted February 2, 2011 Report Share Posted February 2, 2011 Hi, Ofir, Thanks for quick reply! No, they're not consecutive. Their addresses are: Register1 - 3120, Register2 - 3122, Register3 - 3124, Register4 - 3126. And about delay: is there any sense to do delay? I think the bit conditions allow to read next register, only when previous been read? Or I understand not good? Is there any reason why you can't pull down 7 registers (3120 - 3126) and just ignore the values of the 3 you don't need? Link to comment Share on other sites More sharing options...
Ofir Posted February 3, 2011 Report Share Posted February 3, 2011 Hi Ziwi, Good point. Yes, indeed you can read 7 registers and use only the relevant in your logic. Link to comment Share on other sites More sharing options...
Damian Posted February 3, 2011 Report Share Posted February 3, 2011 If he is reading them in as double intergers they may already be effectively consecutive. But yes, He would be much better served to get all 7 registers and just ignore the unnecessary values. He'll get much better updates rates and have a much simpler program. Link to comment Share on other sites More sharing options...
MVP 2023 Joe Tauser Posted February 4, 2011 MVP 2023 Report Share Posted February 4, 2011 I would bet they are double integers given the addressing scheme. If he's reading them as double integers then his length needs to be 8. I'd read the table in one block from the power meter and then examine the data received to determine the actual structure. The Modbus documentation with such a device often leaves out little tidbits such as true register mapping and which words represent the HI and LO values. Joe T. Link to comment Share on other sites More sharing options...
Vidmas30 Posted February 7, 2011 Author Report Share Posted February 7, 2011 Hello, Link to comment Share on other sites More sharing options...
Vidmas30 Posted February 7, 2011 Author Report Share Posted February 7, 2011 Hello, Thank you for the answers! The idea to read 7 registers and etc is good, but the question was not how to make a shortcuts or workarounds, but about the principle: is my ladder code bad and what may be the reason of such behavior.. I did't get a chance to test code with dealys so far, but maybe until next week I do. Thank you! Link to comment Share on other sites More sharing options...
Damian Posted February 8, 2011 Report Share Posted February 8, 2011 Hello, Thank you for the answers! The idea to read 7 registers and etc is good, but the question was not how to make a shortcuts or workarounds, but about the principle: is my ladder code bad and what may be the reason of such behavior.. I did't get a chance to test code with dealys so far, but maybe until next week I do. Thank you! The honest answer to that question is that your code isn't very robust. There is no error handling. There is nothing to check how successful the communications are. If you search the topic "Modbus Wha?" in the forum you will find a discussion on modbus communication and how various users have chosen to handle it. Some guys even poseted snippets of their code. If you want your code to be robust then this thread should give you ideas on how to make it so. Delays can sometimes help, but I have rarely seen times where it is necessary. All of the modbus I have done to date with Unitronics has not required any artificial delays inserted. In your case as well, it would be helpful to buffer your incoming data. Set the buffer to all zeros before your read request. This way, after your read request the buffer remains zero you know that you didn't receive new data. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now