namespace Inspectron.Epson; /// /// General printer status (DLE EOT 1) /// Format: 0xx1xx10b /// public record PrinterStatus { /// /// Raw status byte received from printer /// public byte RawByte { get; init; } /// /// Binary representation of status byte /// public string Binary => Convert.ToString(RawByte, 2).PadLeft(8, '0'); /// /// Hex representation of status byte /// public string Hex => $"0x{RawByte:X2}"; /// /// Drawer kick-out connector pin 3 is HIGH (Bit 2) /// public bool DrawerOpen { get; init; } /// /// Printer is online (Bit 3: 0=online, 1=offline) /// public bool IsOnline { get; init; } /// /// Cover is closed (Bit 5: 0=closed, 1=open) /// public bool IsCoverClosed { get; init; } /// /// Paper feed button is being pressed (Bit 6) /// public bool PaperFeedButtonPressed { get; init; } /// /// Parse printer status byte /// public static PrinterStatus Parse(byte statusByte) { return new PrinterStatus { RawByte = statusByte, DrawerOpen = (statusByte & 0x04) != 0, IsOnline = (statusByte & 0x08) == 0, IsCoverClosed = (statusByte & 0x20) == 0, PaperFeedButtonPressed = (statusByte & 0x40) != 0 }; } } /// /// Offline status (DLE EOT 2) - Reasons for offline /// Format: 0xx1xx10b /// public record OfflineStatus { /// /// Raw status byte received from printer /// public byte RawByte { get; init; } /// /// Binary representation of status byte /// public string Binary => Convert.ToString(RawByte, 2).PadLeft(8, '0'); /// /// Hex representation of status byte /// public string Hex => $"0x{RawByte:X2}"; /// /// Cover is open (Bit 2) /// public bool CoverOpen { get; init; } /// /// Paper feed button is being pressed (Bit 3) /// public bool PaperFeedButton { get; init; } /// /// Paper end detected (Bit 5) /// public bool PaperEnd { get; init; } /// /// Error occurred (Bit 6) /// public bool ErrorOccurred { get; init; } /// /// Parse offline status byte /// public static OfflineStatus Parse(byte statusByte) { return new OfflineStatus { RawByte = statusByte, CoverOpen = (statusByte & 0x04) != 0, PaperFeedButton = (statusByte & 0x08) != 0, PaperEnd = (statusByte & 0x20) != 0, ErrorOccurred = (statusByte & 0x40) != 0 }; } } /// /// Error status (DLE EOT 3) /// Format: 0xx1xx10b /// public record ErrorStatus { /// /// Raw status byte received from printer /// public byte RawByte { get; init; } /// /// Binary representation of status byte /// public string Binary => Convert.ToString(RawByte, 2).PadLeft(8, '0'); /// /// Hex representation of status byte /// public string Hex => $"0x{RawByte:X2}"; /// /// Recoverable error occurred (Bit 2) /// public bool RecoverableError { get; init; } /// /// Auto-cutter error occurred (Bit 3) /// public bool AutoCutterError { get; init; } /// /// Unrecoverable error occurred (Bit 5) /// public bool UnrecoverableError { get; init; } /// /// Auto-recovery error occurred (Bit 6) /// public bool AutoRecoveryError { get; init; } /// /// Returns true if any error is present /// public bool HasError => RecoverableError || AutoCutterError || UnrecoverableError || AutoRecoveryError; /// /// Parse error status byte /// public static ErrorStatus Parse(byte statusByte) { return new ErrorStatus { RawByte = statusByte, RecoverableError = (statusByte & 0x04) != 0, AutoCutterError = (statusByte & 0x08) != 0, UnrecoverableError = (statusByte & 0x20) != 0, AutoRecoveryError = (statusByte & 0x40) != 0 }; } } /// /// Paper sensor status (DLE EOT 4) /// Format: 0xx1xx10b /// public record PaperSensorStatus { /// /// Raw status byte received from printer /// public byte RawByte { get; init; } /// /// Binary representation of status byte /// public string Binary => Convert.ToString(RawByte, 2).PadLeft(8, '0'); /// /// Hex representation of status byte /// public string Hex => $"0x{RawByte:X2}"; /// /// Paper roll is near end (Bits 2-3) /// public bool PaperNearEnd { get; init; } /// /// Paper is present (Bits 5-6, inverted logic) /// public bool PaperPresent { get; init; } /// /// Parse paper sensor status byte /// public static PaperSensorStatus Parse(byte statusByte) { return new PaperSensorStatus { RawByte = statusByte, PaperNearEnd = (statusByte & 0x0C) != 0, PaperPresent = (statusByte & 0x60) == 0 }; } } /// /// Overall printer status with aggregated information and health status /// public record OverallStatus { /// /// Printer model/ID /// public string? PrinterModel { get; init; } /// /// General printer status /// public PrinterStatus? PrinterStatus { get; init; } /// /// Offline status /// public OfflineStatus? OfflineStatus { get; init; } /// /// Error status /// public ErrorStatus? ErrorStatus { get; init; } /// /// Paper sensor status /// public PaperSensorStatus? PaperStatus { get; init; } /// /// Overall status text description /// public string StatusText { get; init; } = string.Empty; /// /// True if printer is ready for operation /// public bool IsReady { get; init; } /// /// List of recommendations to resolve issues /// public List Recommendations { get; init; } = new(); /// /// Status emoji/icon /// public string StatusIcon { get; init; } = "❓"; }