diff --git a/Daqifi.Desktop.Test/Device/AbstractStreamingDeviceTests.cs b/Daqifi.Desktop.Test/Device/AbstractStreamingDeviceTests.cs
index 1377fb9f..117e6989 100644
--- a/Daqifi.Desktop.Test/Device/AbstractStreamingDeviceTests.cs
+++ b/Daqifi.Desktop.Test/Device/AbstractStreamingDeviceTests.cs
@@ -1,5 +1,9 @@
using Daqifi.Desktop.Device;
using Daqifi.Desktop.DataModel.Network;
+using Daqifi.Desktop.IO.Messages.Consumers;
+using Daqifi.Desktop.IO.Messages.Producers;
+using Daqifi.Core.Communication.Messages;
+using Moq;
namespace Daqifi.Desktop.Test.Device;
@@ -128,6 +132,80 @@ public void DeviceType_Property_ShouldNotifyPropertyChanged()
Assert.IsTrue(propertyChanged, "DeviceType property should notify PropertyChanged");
}
+ [TestMethod]
+ public void DetectFromPartNumber_ShouldReturnNyquist1_ForNq1()
+ {
+ // Arrange & Act
+ var deviceType = DeviceTypeDetector.DetectFromPartNumber("Nq1");
+
+ // Assert
+ Assert.AreEqual(DeviceType.Nyquist1, deviceType, "Should detect Nyquist1 from Nq1 part number");
+ }
+
+ [TestMethod]
+ public void DetectFromPartNumber_ShouldReturnNyquist3_ForNq3()
+ {
+ // Arrange & Act
+ var deviceType = DeviceTypeDetector.DetectFromPartNumber("Nq3");
+
+ // Assert
+ Assert.AreEqual(DeviceType.Nyquist3, deviceType, "Should detect Nyquist3 from Nq3 part number");
+ }
+
+ [TestMethod]
+ public void DetectFromPartNumber_ShouldBeCaseInsensitive()
+ {
+ // Arrange & Act
+ var nq1Upper = DeviceTypeDetector.DetectFromPartNumber("NQ1");
+ var nq1Lower = DeviceTypeDetector.DetectFromPartNumber("nq1");
+ var nq1Mixed = DeviceTypeDetector.DetectFromPartNumber("Nq1");
+
+ // Assert
+ Assert.AreEqual(DeviceType.Nyquist1, nq1Upper, "Should detect Nyquist1 from uppercase NQ1");
+ Assert.AreEqual(DeviceType.Nyquist1, nq1Lower, "Should detect Nyquist1 from lowercase nq1");
+ Assert.AreEqual(DeviceType.Nyquist1, nq1Mixed, "Should detect Nyquist1 from mixed case Nq1");
+ }
+
+ [TestMethod]
+ public void DetectFromPartNumber_ShouldReturnUnknown_ForUnrecognizedPartNumber()
+ {
+ // Arrange & Act
+ var deviceType = DeviceTypeDetector.DetectFromPartNumber("UnknownDevice");
+
+ // Assert
+ Assert.AreEqual(DeviceType.Unknown, deviceType, "Should default to Unknown for unrecognized part number");
+ }
+
+ [TestMethod]
+ public void DetectFromPartNumber_ShouldReturnUnknown_ForEmptyString()
+ {
+ // Arrange & Act
+ var deviceType = DeviceTypeDetector.DetectFromPartNumber("");
+
+ // Assert
+ Assert.AreEqual(DeviceType.Unknown, deviceType, "Should return Unknown for empty string");
+ }
+
+ [TestMethod]
+ public void DetectFromPartNumber_ShouldReturnUnknown_ForNull()
+ {
+ // Arrange & Act
+ var deviceType = DeviceTypeDetector.DetectFromPartNumber(null);
+
+ // Assert
+ Assert.AreEqual(DeviceType.Unknown, deviceType, "Should return Unknown for null");
+ }
+
+ [TestMethod]
+ public void DetectFromPartNumber_ShouldReturnUnknown_ForWhitespace()
+ {
+ // Arrange & Act
+ var deviceType = DeviceTypeDetector.DetectFromPartNumber(" ");
+
+ // Assert
+ Assert.AreEqual(DeviceType.Unknown, deviceType, "Should return Unknown for whitespace");
+ }
+
///
/// Test implementation of AbstractStreamingDevice for testing purposes
///
diff --git a/Daqifi.Desktop/Device/AbstractStreamingDevice.cs b/Daqifi.Desktop/Device/AbstractStreamingDevice.cs
index fdaf4e3c..fe026a9b 100644
--- a/Daqifi.Desktop/Device/AbstractStreamingDevice.cs
+++ b/Daqifi.Desktop/Device/AbstractStreamingDevice.cs
@@ -876,6 +876,8 @@ protected void HydrateDeviceMetadata(DaqifiOutMessage message)
if (!string.IsNullOrWhiteSpace(message.DevicePn))
{
DevicePartNumber = message.DevicePn;
+ DeviceType = DeviceTypeDetector.DetectFromPartNumber(message.DevicePn);
+ AppLogger.Information($"Detected device type: {DeviceType} from part number: {message.DevicePn}");
}
if (message.DeviceSn != 0)
{
diff --git a/Daqifi.Desktop/Device/DeviceTypeDetector.cs b/Daqifi.Desktop/Device/DeviceTypeDetector.cs
new file mode 100644
index 00000000..808da460
--- /dev/null
+++ b/Daqifi.Desktop/Device/DeviceTypeDetector.cs
@@ -0,0 +1,27 @@
+namespace Daqifi.Desktop.Device;
+
+///
+/// Provides device type detection logic based on device part numbers.
+///
+public static class DeviceTypeDetector
+{
+ ///
+ /// Detects the device type from a part number string.
+ ///
+ /// The device part number (e.g., "Nq1", "Nq3")
+ /// The detected DeviceType, or DeviceType.Unknown if not recognized
+ public static DeviceType DetectFromPartNumber(string partNumber)
+ {
+ if (string.IsNullOrWhiteSpace(partNumber))
+ {
+ return DeviceType.Unknown;
+ }
+
+ return partNumber.ToLowerInvariant() switch
+ {
+ "nq1" => DeviceType.Nyquist1,
+ "nq3" => DeviceType.Nyquist3,
+ _ => DeviceType.Unknown
+ };
+ }
+}