[En-Nut-Discussion] Industrial interfaces (Modbus TCP, Profinet, etc.)
Thiago A. Corrêa
thiago.correa at gmail.com
Thu Jul 17 19:59:43 CEST 2014
Please notice the API returns the number of actually received bytes.
The size is a maximum buffer size, not a minimum or required read
size. That's a fairly common bug, to expect reads to return with the
"requested" amount of bytes. Sometimes it does, sometimes it doesn't.
It's your job to loop thru receive calls until you get the amount of
bytes you want, something along:
int rcvCount = 0;
while( rcvCount < sizeof(mbap_header) )
rcvCount += receive( socket, &mbap_header + rcvCount,
sizeof(mbap_header) - rcvCount );
On Thu, Jul 17, 2014 at 2:46 PM, Philipp Burch <phip at hb9etc.ch> wrote:
> Hi Nathan!
> On 16.07.2014 22:32, Nathan Moore wrote:
>> Not an expert, but if you're using Modbus RTU over TCP then the MBAP
>> header has the length of the Modbus message in it, so you conceptually do:
>> receive(socket, &mbap_header, sizeof(mbap_header));
>> receive(socket, buffer, mbap_header.message_size);
> Thanks, that should really do it.
More information about the En-Nut-Discussion