How do i catch the Address out of range or object does not exist exception in this Sample?
i need the lasterrorcode but threre is none anymore. The dokumentation is not uptodate.
private async Task ReadDataBlock(SymbolInfo sym, CancellationToken stoppingToken)
{
try
{
sym.ActValue = await _plc.ReadSingleVariableAsync(sym.BitOffset, sym.TypeBitLength,
sym.DataBlockNumber, sym.eType, sym.eArea, stoppingToken);
await CheckData(sym, stoppingToken);
}
catch (Exception ex)
{
var offset = sym.BitOffset;
_logger.LogCritical($"PLC{_fileSuffix}: DB: {sym.DataBlockNumber}. ByteOffset: {(int)(offset / 8)}.{(int)(offset % 8)}");
_logger.LogCritical($"PLC{_fileSuffix}: {ex.Message}");
if (false)//Address out of range or object does not exist
{
_logger.LogCritical($"PLC{_fileSuffix}: Couldn't find the Variable.");
SymbolList.First().Item1.Remove(sym);
}
}
}
internal static void ValidateResponseCode(ReadWriteErrorCode statusCode)
{
switch (statusCode)
{
case ReadWriteErrorCode.ObjectDoesNotExist:
throw new Exception("Received error from PLC: Object does not exist.");
case ReadWriteErrorCode.DataTypeInconsistent:
throw new Exception("Received error from PLC: Data type inconsistent.");
case ReadWriteErrorCode.DataTypeNotSupported:
throw new Exception("Received error from PLC: Data type not supported.");
case ReadWriteErrorCode.AccessingObjectNotAllowed:
throw new Exception("Received error from PLC: Accessing object not allowed.");
case ReadWriteErrorCode.AddressOutOfRange:
throw new ArgumentOutOfRangeException("Received error from PLC: Address out of range.");
case ReadWriteErrorCode.HardwareFault:
throw new Exception("Received error from PLC: Hardware fault.");
case ReadWriteErrorCode.Success:
break;
default:
throw new Exception($"Invalid response from PLC: statusCode={(byte)statusCode}.");
}
}
How do i catch the Address out of range or object does not exist exception in this Sample? i need the lasterrorcode but threre is none anymore. The dokumentation is not uptodate.
ReadSingleVariableAsync calls this
The Exception is thrown here in S7.net