interpretPrinterStatus method

void interpretPrinterStatus(
  1. int statusByte
)

Simple function to interpret the printer status byte for 3nStart RPT008

Implementation

void interpretPrinterStatus(int statusByte) {
  String bits = statusByte.toRadixString(2).padLeft(8, '0');

  log('\n==== PRINTER STATUS 3NSTART RPT008 ====');
  log('Received byte: 0x${statusByte.toRadixString(16).padLeft(2, "0")} ($statusByte)');
  log('Binary representation: $bits');

  bool error = (statusByte & 0x80) != 0; // Bit 7
  bool paperFeed = (statusByte & 0x40) != 0; // Bit 6
  bool coverOpen = (statusByte & 0x20) != 0; // Bit 5
  bool sensorBit = (statusByte & 0x10) != 0; // Bit 4 (model specific)
  bool offline = (statusByte & 0x08) != 0; // Bit 3
  bool drawer1 = (statusByte & 0x04) != 0; // Bit 2
  bool drawer2 = (statusByte & 0x02) != 0; // Bit 1

  log('\nInterpretation:');
  log('- Online/Offline status: ${offline ? "OFFLINE" : "ONLINE"}');
  log('- Cover: ${coverOpen ? "OPEN" : "CLOSED"}');
  log('- Error: ${error ? "YES" : "NO"}');
  log('- Drawer: ${(drawer1 || drawer2) ? "OPEN" : "CLOSED"}');
  log('- Manual feed: ${paperFeed ? "ACTIVE" : "INACTIVE"}');
  log('- Special sensor (bit 4): ${sensorBit ? "ACTIVE" : "INACTIVE"}');

  if (statusByte == 22) {
    log('\nSummary for 0x16 (22):');
    log('The printer is ONLINE, with the cover CLOSED and no errors.');
    log('The drawer appears to be OPEN (bits 1 and 2 activated).');
    log('Bit 4 is active, which could indicate a specific state of the paper sensor or another model-specific function.');
  }

  log('\nBit diagram:');
  log('+---+---+---+---+---+---+---+---+');
  log('| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | Position');
  log('+---+---+---+---+---+---+---+---+');
  log('| ${bits[0]} | ${bits[1]} | ${bits[2]} | ${bits[3]} | ${bits[4]} | ${bits[5]} | ${bits[6]} | ${bits[7]} | Value');
  log('+---+---+---+---+---+---+---+---+');
  log('| E | F | C | S | O | D1| D2| R | Meaning');
  log('+---+---+---+---+---+---+---+---+');
  log(' E=Error, F=Feed, C=Cover, S=Sensor, O=Offline, D=Drawer, R=Reserved');

  log('\n========================================');
}