namespace Sick.SafetyScanners.DataStructures;
///
/// Communication settings used to configure the SICK Safety Scanner
/// This structure is used with ChangeCommSettingsCommand to configure scanner parameters
///
public sealed class CommSettings
{
///
/// Gets or sets the channel number (0-3)
///
public byte Channel { get; init; }
///
/// Gets or sets the publishing frequency (publish every n-th scan)
/// Example: 1 = publish every scan, 2 = publish every 2nd scan (half frequency)
///
public ushort PublishingFrequency { get; init; } = 1;
///
/// Gets or sets the interface type
/// 0: EFI-pro, 1: EtherNet/IP, 3: Profinet, 4: Non-safe Ethernet
///
public InterfaceType EInterfaceType { get; init; }
///
/// Gets or sets the start angle in radians
/// If start and end angles are equal, all angles are regarded
///
public double StartAngle { get; init; }
///
/// Gets or sets the end angle in radians
/// If start and end angles are equal, all angles are regarded
///
public double EndAngle { get; init; }
///
/// Gets or sets the enabled features as a bitset (ushort)
/// Use SensorDataFeatures constants or SensorDataFeatures.ToFeatureFlags() to set
///
public ushort Features { get; init; } = SensorDataFeatures.All;
///
/// Gets or sets whether general system state feature is enabled
///
public bool GeneralSystemStateEnabled { get; init; } = true;
///
/// Gets or sets whether derived settings feature is enabled
///
public bool DerivedSettingsEnabled { get; init; } = true;
///
/// Gets or sets whether measurement data feature is enabled
///
public bool MeasurementDataEnabled { get; init; } = true;
///
/// Gets or sets whether intrusion data feature is enabled
///
public bool IntrusionDataEnabled { get; init; } = true;
///
/// Gets or sets whether application data feature is enabled
///
public bool ApplicationDataEnabled { get; init; } = true;
///
/// Gets or sets whether the channel is enabled
///
public bool Enabled { get; init; } = true;
///
/// Gets or sets the host UDP port (0 = auto-assign)
///
public ushort HostUdpPort { get; init; }
///
/// Gets or sets the host IP address as a string (e.g., "192.168.1.100")
///
public string HostIp { get; init; } = "192.168.1.100";
///
/// Creates a CommSettings with all features enabled
///
public static CommSettings CreateDefault()
{
return new CommSettings
{
Channel = 0,
PublishingFrequency = 1,
EInterfaceType = InterfaceType.NonSafeEthernet,
StartAngle = 0.0,
EndAngle = 0.0, // Equal to start angle means all angles
Features = SensorDataFeatures.All,
GeneralSystemStateEnabled = true,
DerivedSettingsEnabled = true,
MeasurementDataEnabled = true,
IntrusionDataEnabled = true,
ApplicationDataEnabled = true,
Enabled = true,
HostUdpPort = 0,
HostIp = "192.168.1.100"
};
}
///
/// Creates a CommSettings with custom feature flags
///
public static CommSettings Create(
byte channel,
string hostIp,
ushort hostUdpPort,
bool generalSystemState = true,
bool derivedSettings = true,
bool measurementData = true,
bool intrusionData = true,
bool applicationData = true,
ushort publishingFrequency = 1,
double startAngle = 0.0,
double endAngle = 0.0,
InterfaceType interfaceType = InterfaceType.NonSafeEthernet,
bool enabled = true)
{
return new CommSettings
{
Channel = channel,
PublishingFrequency = publishingFrequency,
EInterfaceType = interfaceType,
StartAngle = startAngle,
EndAngle = endAngle,
Features = SensorDataFeatures.ToFeatureFlags(
generalSystemState,
derivedSettings,
measurementData,
intrusionData,
applicationData),
GeneralSystemStateEnabled = generalSystemState,
DerivedSettingsEnabled = derivedSettings,
MeasurementDataEnabled = measurementData,
IntrusionDataEnabled = intrusionData,
ApplicationDataEnabled = applicationData,
Enabled = enabled,
HostUdpPort = hostUdpPort,
HostIp = hostIp
};
}
}