flagmoon / nmodbus

Automatically exported from code.google.com/p/nmodbus
0 stars 0 forks source link

Modbus RTU slave exceptions not being correctly handled by NModbus #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. Attempt to Read RTU from an unsupported slave address. (Or any read 
which causes a slave exception response).

2. NMOdbus will throw an exception "Function code 131 not supported".

What is the expected output? What do you see instead?

NModbus should throw a ModbusSlaveException : "Funcion code 3 Error code 2"

What version of the product are you using? On what operating system?

1.2 Beta on XP.

Please provide any additional information below.

I've tried to report this a couple of times and not been sucessful. I'm 
pretty sure it's a bug.

The problem is caused because the function ResponseBytesToRead(byte[] 
frameStart) in the class ModbusRTUTransport is throwing an exception on an 
slave error flagged response (i.e. + 0X80 higher than a normal response).

This is a valid response and would be correctly handled when passed to 
CreateResponse() in the ModbusTransport class, but the thrown exception 
means that function is never called.

Quick fix:

default:
  if (functionCode > 128)
  {
    numBytes = 1;
    break;
  }
  string errorMessage = String.Format("Function code {0} not 
supported.",   functionCode);
throw new NotImplementedException(errorMessage);

Original issue reported on code.google.com by simon.ba...@westinstruments.com on 19 Jun 2007 at 10:51

GoogleCodeExporter commented 8 years ago
Simon, 

Thanks for the detailed bug report. I finally have some time and will be 
looking into
it this week.

Scott

Original comment by sja...@gmail.com on 20 Jun 2007 at 12:14

GoogleCodeExporter commented 8 years ago
Fix in the repository. I'll release a new version w/ the fix at the end of the 
week.

Original comment by sja...@gmail.com on 20 Jun 2007 at 5:42