private void ExecuteDriverCommand(bool printable, ExecuteCommandDelegate executeCommandDelegate) { ErrorCode = new ServerErrorCode(this, GeneralError.Success); if (!Active) { ErrorCode = new ServerErrorCode(this, GeneralError.Inactive); return; } try { if (_spProtocol == null) { _spProtocol = new SPProtocol(Port, PASSWORD); } executeCommandDelegate(_spProtocol); if (printable) { _paperStatus = PaperOutStatus.Present; } } catch (TimeoutException) { ErrorCode = new ServerErrorCode(this, GeneralError.Timeout, _spProtocol.GetCommandDump()); } catch (DeviceErrorException E) { // отлавливаем ошибки принтера if (E.ErrorCode == 8 || E.ErrorCode == 9) { _paperStatus = PaperOutStatus.OutPassive; } else if (E.ErrorCode == 1 && _paperStatus != PaperOutStatus.Present) { } ErrorCode = new ServerErrorCode(this, E.ErrorCode, GetSpecificDescription(E.ErrorCode), _spProtocol.GetCommandDump()); } catch (Exception E) { ErrorCode = new ServerErrorCode(this, E); } }
protected override void OnAfterActivate() { Port.ReadTimeout = READ_TIMEOUT; Port.WriteTimeout = WRITE_TIMEOUT; _spProtocol = new SPProtocol(Port, PASSWORD); try { // короткий запрос состояния _spProtocol.ShortStatusInquiry(); // проверяем статус _spProtocol.ExecuteCommand("A0"); byte currStatus = (byte)_spProtocol.GetFieldAsInt(2); // если команда инициализации еще не выполнялась if ((currStatus & 0x01) == 0x01) { // инициализация ККМ var currTime = DateTime.Now; _spProtocol.ExecuteCommand("00", currTime.ToString("ddMMyy"), currTime.ToString("HHmmss")); } // если смена закрыта if ((currStatus & 0x04) == 0x00) { // установка клише for (int i = 0; i < DocumentHeader.Length && i < 4; i++) { _spProtocol.ExecuteCommand("A2", "20", i.ToString(), DocumentHeader[i]); } // установка подвала for (int i = 0; i < DocumentFooter.Length && i < 2; i++) { _spProtocol.ExecuteCommand("A2", "21", i.ToString(), DocumentFooter[i]); } } } catch (Exception) { throw; } }