Newbie question about Modbus

P

Thread Starter

patufet

Hello,
I'm writing a LabView application where I have to communicate to another process via Modbus. There is a LabView Modbus library and there is an example that works, but the whole is not very well documented.

As far as I have understood in the Modbus protocol the data is passed from master to slave or from slave to master through registers. The thing I don't understand very well is how the master (or the slave) knows the data he has written in a register have been read by the slave (or the master), and how does he know he can overwrite the registers without loosing data?
In serial communication via RS-232 for example, the data is just sended and it fills a buffer until it is read. Is there a way to operate similarly with Modbus?.

In our application the process we have to communicate to, makes some measurements and time to time must sends data (not necessarly at a defined interval). There is not a great amount of data (up to some acquisitions per second), but we would not want to loose any.

Any help will be greatly appreciated.

Patufet
 
I'm a Modbus user, not a Modbus developer, but here's what I've run into.

The Modbus slave registers are defined by the slave device. If the master writes a value to a slave register, the slave is obliged to change the contents of that register to the new value and the old value is lost. That's what Modbus is all about. The slave doesn't get to decide, that's why call it a "slave".

Masters generally have addressable registers that are defined by the user during configuration. For instance, I might assign a certain register to receive a floating point value from slave #3's register 40017 and assign another register to receive a binary point from slave register 10022. The slave's documentation attempts to tell me what value is mapped to which register and what format the data is in (binary, integer or floating point).

Regarding your question about how the master (or the slave) knows the data he has written in a register has been read by the slave (or the master):

The master sends out a request for data from a slave. Then it waits for a reply. Since a Modbus RTU network has only one master (Modbus Plus can have multiple masters), the network is not being used until the slave replies. If no reply comes before the established time limit, the master goes on to the next item on its agenda. If a reply comes, the reply can either be a reply message with data or a reply message with an error code. The master transfers the data from the reply message into appropriate register(s) in the master. Time outs and error messages clearly mean data has not been transferred.

If the master writes to a slave, it expects a reply confirming receipt of its request. Lack of a confirmation (time out, error, or just lost in cyberspace) means data hasn't successfully been transferred.

So part of comm scheme is to determine what to do when error msgs are received.

Some masters can read blocks of registers, or multiple registers, usually contiguous registers, from slaves.

Question:
how does he know he can overwrite the registers without loosing data?
Answer: How can you overwrite any memory location and not lose the data? Over write means over write. In with the new, out with the old.

Statement:
In serial communication via RS-232 for example, the data is just sended and it fills a buffer until it is read.

You are confusing a physical link, RS-232, with a communications protocol. Modbus is fully capable of doing "serial communication via RS-232", but it's Modbus, Modbus does not "send until it fills a buffer", because it wasn't designed to do that. Modbus is designed for a master to read or write a value to a slave, wait for a response from the slave, then go on to its next task.

Most masters have a update rate, for example, once per second, for their polling rate. Some masters can be enabled or disabled, so that if your process is not changing, and there's no need to get new data, then you can disable the master.

Dave
 
S
Can you alter the program in the slave? if so, you could use one of the registers for a sequential batch counter, so the master will at least be aware that it does or does not have all data packets.

All decisions about when to exchange data are made by the master, so it's difficult to operate in an even driven mode if the node which has new data, and knows when new data is present, is the slave. If this is your configuration, can you exchange the slave and master functions on the two nodes?
--
Steve Myres, PE
Automation Solutions
(480) 813-1145
 
C

Curt Wuollet

Why not just call some open registers a buffer and send to them then copy to your working registers as needed. That would, it seems, accomplish the same thing. At worst you might have to move your working registers if you can't control which get written. Buffer, register, it's all just memory to me.

Regards

cww
 
Hello,

Thanks very much for all of your replies. I see now a little better how to write the modbus master functions of the application.

Part of my confusion came from the fact that for instance I don't know anything about the slave device operating mode and I still have not received any protocol from the device manufacturer.

On the other side, as the only reference I have is the LabView library example, I could not understand very well typical mode of operation of modbus devices.

If you have any references of typical examples written in C or other languages this could be helpful too.

Thank you again.

Patufet
 
Top