diff --git a/src/Interfaces/ICachedRegisterBlock.cs b/src/Interfaces/ICachedRegisterBlock.cs index c259b39..e473329 100644 --- a/src/Interfaces/ICachedRegisterBlock.cs +++ b/src/Interfaces/ICachedRegisterBlock.cs @@ -42,6 +42,11 @@ public interface ICachedRegisterBlock : INotifyPropertyChanged /// bool HasChanges { get; } + /// + /// Gets the size of the cached block in bytes. + /// + int SizeInBytes { get; } + /// /// Reads a section of the cache. /// diff --git a/src/PanelFactory.cs b/src/PanelFactory.cs index 2cccfa4..1583868 100644 --- a/src/PanelFactory.cs +++ b/src/PanelFactory.cs @@ -143,6 +143,10 @@ private static double GetMaxPixelWidthOfNames(Value[] values) private static void AddValueControl(StackPanel panel, double nameWidth, Value value, ICachedRegisterBlock block) { + var end = value.Address + value.Length; + if (end > block.SizeInBytes) + throw new InvalidOperationException($"The panel value '{value.Name}' at {value.Address} (length {value.Length}) ends at {end}, which exceeds the register block size ({block.SizeInBytes} bytes). Increase the config block's size, or reduce the panel addresses."); + UserControl newControl; switch (value.Type) {