rossmann-engineering / EasyModbusTCP.NET

Modbus TCP, Modbus UDP and Modbus RTU client/server library for .NET implementations
928 stars 402 forks source link

ReadInputRegisters returning array of 0 #36

Open ejcoutinho opened 4 years ago

ejcoutinho commented 4 years ago

I'm using this library to monitor some integers. I found some errors and after some debug it seems that ReadInputRegisters returns always an array even if had some problems during it executions. from what I checked in the implementation, it create the response array and after return it, even if data values are not correct: response = new int[quantity]; for (int i = 0; i < quantity; i++) { byte lowByte; byte highByte; highByte = data[9+i2]; lowByte = data[9+i2+1];

            data[9+i*2] = lowByte;
            data[9+i*2+1] = highByte;

            response[i] = BitConverter.ToInt16(data,(9+i*2));
        }
        return (response);

Here is my debug watchs, after the instruction int[] registers = client.ReadInputRegisters(bMap.from, bMap.lenght); Note that registers return values as exepcted, but some times it cames all with 0

Watchs: