Skip to content

Commit

Permalink
[-] Fixed error with reading error code text
Browse files Browse the repository at this point in the history
  • Loading branch information
Kravtsov Vitaly committed Dec 29, 2022
1 parent 53da55e commit db44707
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
7 changes: 7 additions & 0 deletions History.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
Company : SHTRIH-M www.shtrih-m.ru (495) 787-6090
Url : https://github.com/shtrih-m/javapos_shtrih

********************************************************************************

29.12.2022
deviceServiceVersion = 1013684

[-] Fixed error with reading error code text

********************************************************************************

16.12.2022
Expand Down
69 changes: 36 additions & 33 deletions Source/Core/src/com/shtrih/fiscalprinter/SMFiscalPrinterImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ enum Boolean {
private volatile boolean interrupted = false;
private Integer fdVersion = null;
private boolean capLastErrorText = true;
private boolean capErrorTextByCode = true;
private FDOParameters fdoParameters = null;
public boolean isTableTextCleared = false;
private final Map<Integer, Integer> taxRates = new HashMap<Integer, Integer>();
Expand Down Expand Up @@ -228,7 +229,8 @@ public Object getSyncObject() throws Exception {
}

public void deviceExecute(PrinterCommand command) throws Exception {
synchronized (port.getSyncObject()) {
synchronized (port.getSyncObject())
{
Time.delay(params.commandDelayInMs);
beforeCommand(command);
//correctDateTime(command);
Expand All @@ -242,17 +244,13 @@ public void deviceExecute(PrinterCommand command) throws Exception {
port.open(getParams().portOpenTimeout);
}
device.send(command);
}
catch (ClosedConnectionException e)
{
if (!command.getIsRepeatable()){
} catch (ClosedConnectionException e) {
if (!command.getIsRepeatable()) {
throw new DeviceException(PrinterConst.SMFPTR_E_NOCONNECTION, e.getMessage());
}
command.setRepeatNeeded(true);
return;
}
catch (Exception e)
{
} catch (Exception e) {
throw new DeviceException(PrinterConst.SMFPTR_E_NOCONNECTION, e.getMessage());
}

Expand All @@ -262,16 +260,21 @@ public void deviceExecute(PrinterCommand command) throws Exception {
Thread.sleep(3000);
}
commandSucceeded(command);
} else {
if (capLastErrorText) {
ReadLastErrorText command2 = readExtendedCode();
if (command2.isSucceeded()) {
logger.error(command2.getErrorText());
} else
{
if (command.getCode() != 0x6B)
{
if (capLastErrorText) {
ReadLastErrorText command2 = readLastErrorText();
if (command2.isSucceeded()) {
logger.error(command2.getErrorText());
}
} else {
capLastErrorText = false;
String text = getErrorText(command.getResultCode());
logger.error(text + ", " + command.getParametersText(commands));
}
} else {
String text = getErrorText(command.getResultCode());
} else{
String text = getDriverErrorText(command.getResultCode());
logger.error(text + ", " + command.getParametersText(commands));
}
}
Expand Down Expand Up @@ -347,10 +350,8 @@ public void setCurrentDateTime() {
PrinterTime currentTime = new PrinterTime();
FSReadStatus fsStatus = fsReadStatus();

if (!status.getDate().isEqual(currentDate))
{
if (fsStatus.getDate().beforeOrEqual(currentDate))
{
if (!status.getDate().isEqual(currentDate)) {
if (fsStatus.getDate().beforeOrEqual(currentDate)) {
check(writeDate(currentDate));
check(confirmDate(currentDate));
}
Expand All @@ -371,12 +372,12 @@ public void setCurrentDateTime() {

public LongPrinterStatus connect() throws Exception {
logger.debug("connect");
synchronized (port.getSyncObject())
{
synchronized (port.getSyncObject()) {
ReadPrinterModelParameters command = new ReadPrinterModelParameters();
if (executeCommand(command) == 0) {
modelParameters = command.getParameters();
capLastErrorText = modelParameters.isCapCommand6B();
capErrorTextByCode = modelParameters.isCapCommand6B();
capCutter = modelParameters.isCapCutter();
} else {
modelParameters = null;
Expand Down Expand Up @@ -1707,12 +1708,10 @@ public void duplicateReceipt() throws Exception {
execute(command);
}

public void reportRemoteRSSI()
{
public void reportRemoteRSSI() {
try {
port.directIO(PrinterPort.DIO_REPORT_RSSI, null, null);
}
catch(Exception e){
} catch (Exception e) {
logger.error(e.getMessage());
}
}
Expand Down Expand Up @@ -2700,7 +2699,7 @@ private void printBarcodeDevice(PrinterBarcode barcode) throws Exception {
if (barcode.getType() != SmFptrConst.SMFPTR_BARCODE_EAN13) {
throw new Exception(
Localizer
.getString(Localizer.PrinterSupportesEAN13Only));
.getString(Localizer.PrinterSupportesEAN13Only));
}

if (barcode.isTextAbove()) {
Expand Down Expand Up @@ -3654,13 +3653,16 @@ public FSReadCommStatus fsReadCommStatus() throws Exception {
}

public String getErrorText(int code) throws Exception {
if (capModelParameters() && modelParameters.isCapCommand6B() && (code >= 0) && (code <= 0xFF) && capLastErrorText) {
ReadErrorDescription command = readErrorDescription(code);
if (capErrorTextByCode) {
ReadErrorTextByCode command = readErrorText(code);
if (command.isSucceeded()) {
return String.valueOf(code) + ", " + command.getText();
}
}
return getDriverErrorText(code);
}

public String getDriverErrorText(int code) throws Exception {
String key = "PrinterError";
if ((code >= 0x00) && (code <= 0xFF)) {
key += Hex.toHex((byte) code);
Expand All @@ -3679,16 +3681,17 @@ public String getErrorText(int code) throws Exception {
return String.valueOf(code) + ", " + result;
}

private ReadErrorDescription readErrorDescription(int code) throws Exception {
ReadErrorDescription command = new ReadErrorDescription(code);
private ReadErrorTextByCode readErrorText(int code) throws Exception {
ReadErrorTextByCode command = new ReadErrorTextByCode(code);
executeCommand(command);
capLastErrorText = command.isSucceeded();
capErrorTextByCode = command.isSucceeded();
return command;
}

private ReadLastErrorText readExtendedCode() throws Exception {
private ReadLastErrorText readLastErrorText() throws Exception {
ReadLastErrorText command = new ReadLastErrorText();
executeCommand(command);
capLastErrorText = command.isSucceeded();
return command;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.shtrih.fiscalprinter.command;

public class ReadErrorDescription extends PrinterCommand {
public class ReadErrorTextByCode extends PrinterCommand {
// in
private final int errorCode;

// out params
private String errorDescription;

public ReadErrorDescription(int errorCode) {
public ReadErrorTextByCode(int errorCode) {
this.errorCode = errorCode;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package com.shtrih.util;

public class ServiceVersion {
public static final String VERSION = "682-1-g0b7b380f";
public static final String VERSION = "683";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ReadErrorDescriptionTests {

@Test
public void should_serialize_request() throws Exception {
ReadErrorDescription cmd = new ReadErrorDescription(94);
ReadErrorTextByCode cmd = new ReadErrorTextByCode(94);

byte[] data = cmd.encodeData();

Expand All @@ -25,7 +25,7 @@ public void should_serialize_request() throws Exception {

@Test
public void should_deserialize_response() throws Exception {
ReadErrorDescription cmd = new ReadErrorDescription(94);
ReadErrorTextByCode cmd = new ReadErrorTextByCode(94);

byte[] responseData = byteArray(
0x6B, 0x00, 0xCA, 0xCA, 0xD2, 0x3A, 0x20, 0xCD, 0xE5, 0xE2,
Expand Down

0 comments on commit db44707

Please sign in to comment.