> I wouldn't assume that. I have never had problems with
> inconsistent data within one packet. I have had problems when
> the PLC could not send all the data in one scan so the gap
> between scans caused our controller to think the first part
> of the packet was complete and the second part of the packet
> was the start of a new packet. Obviously the checksums didn't
> work out so communications failed. This problem was fixed by
> keeping the packet size limited to what could be sent in one
> scan.
eeek.
Isn't that just a basic failure to do modbus properly? the slave should pre-build a buffer and transmit it continuously or it isn't working.
> Modbus messages can't be 150 words long.
sorry, for 150 read 120. I had misremembered the limit.
> If you requires 100 words you should receive a packet of 100
> words of consistent data. What I am saying is that the PLC
> may not be able to send more than 20 words in a scan so the
> packet times out after the 20 words. The checksum will fail
> and the driver should return an error.
I assume the documentation for a device like that should say somewhere "never ask me for more than n registers at once or I will fail"
> This means your driver needs to have a message length limit
> that can be adjusted for each slave device.
yup, that's on the to-do list. Have to have a limit of 125 anyway of course.
> Modbus does not have a 32 byte restriction. Do you have the
> specifications?
No, but a particular slave whose spec I was reading said it could only build it's reply up at the rate of 32 registers per scan. It said it wouldn't start to stream the reply out till it was complete though, so it would be a valid modbus packet with no gaps.
> I have not seen you mention character times.
I'm hoping I will never have to care, at the level at which I'm working.
> A proper Modbus driver is going to have two internal buffers
> of about 256 bytes, one for sending and one for receiving.
> The data the goes into and out of the buffer should be
> consistent as long as one doesn't modify the buffer while
> sending or receiving.
well if the sending buffer is built up in, say, 32 register chunks each scan, then the final buffer contents would be inconsistent in time by 4 to 5 scans. Shouldn't matter much usually.
But if any floating-point value spanned the gap across 2 32-register chunks, I don't see how one can say it isn't possible to get half of an old value and half a new one.
And the flowmeter I'm looking at actually returns 18-byte strings packed into 9 successive registers. I don't want to be able to pick up an inconsistent result from them either, if an error message happens just at the wrong moment.
> The problem that arises is that the data in these buffers
> must be sent and received one character after the other with
> gaps greater than 3.5 character times. This is where I have
> seen problems with some PLCs.
pray God I never meet one of those
> or at least prove the problem is not yours. We have excellent
> diagnostics with our product and a good log will save you
> many hours in the end.
Yup, if we run into problems I can chuck technology at it.
What I'm trying to do is to set up a set of rules the modbus master driver must obey when building up it's list of data requests.
Like, say
1. Keep packet sizes below 32 bytes for this particular PLC,
even if all values in it are single-register .
2. Ensure a 2-register fpt value is always fetched within
a single packet. Ditto 9-byte strings.
> Our product is a slave device. It has a scatter/gather
> feature so data from many places within our slave device can
> be sent in one Modbus packet.
The flowmeter I'm looking at has a feature like that.
In the modbus master we have to do some sort-gather-post stuff, if we are not to fetch each register in a separate modbus read.
We need to ensure a single fetch stays under 125 registers anyway - to meet the modbus spec. But it seems we should have a per-device lower limit, and a "don't break objects across packets" rule too.
> This way our slave can send consistent data to the master.
> If the slave devices do not have this feature then they must
> have a way of copying data from many different parts into one
> buffer that can be sent in one message if you expect all the
> data to be consistent.
> You cannot expect consistent data with multiple reads or
> writes
I have a lower target than that at present. I just want make absolutely sure that 4-byte ints and floats, and 9-register strings are not read half way through changing.
David