modbusPalProject.notifyPDUnotServiced();
return 0;
}
// get the slave:
ModbusSlave slave = modbusPalProject.getModbusSlave(slaveID);
// process the "no reply" error rate of the slave:
if( Math.random() < slave.getNoReplyErrorRate() )
{
System.err.println("Slave "+slaveID+" will no reply (check value error rate)" );
modbusPalProject.notifyPDUnotServiced();
return 0;
}
byte functionCode = buffer[offset+0];
ModbusPduProcessor mspp = slave.getPduProcessor(functionCode);
if( mspp == null )
{
System.err.println("Unsupported function code "+functionCode);
int length = makeExceptionResponse(functionCode,XC_ILLEGAL_FUNCTION, buffer, offset);
ModbusPalRecorder.recordOutgoing(slaveID,buffer,offset,length);
modbusPalProject.notifyExceptionResponse();
return length;
}
int length = mspp.processPDU(functionCode, slaveID, buffer, offset, modbusPalProject.isLeanModeEnabled());
if(length<0)
{
System.err.println("Illegal function code "+functionCode);
length = makeExceptionResponse(functionCode,XC_ILLEGAL_FUNCTION, buffer, offset);
}
if( isExceptionResponse(buffer,offset)==true )
{
modbusPalProject.notifyExceptionResponse();
}
else
{
modbusPalProject.notifyPDUprocessed();
}
// delay the reply
try {
Thread.sleep(slave.getReplyDelay());
} catch (InterruptedException ex) {
Logger.getLogger(ModbusSlaveProcessor.class.getName()).log(Level.SEVERE, null, ex);
}
ModbusPalRecorder.recordOutgoing(slaveID,buffer,offset,length);