Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
koneru9999 committed May 25, 2024
1 parent 836bfd9 commit 9fee039
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 76 deletions.
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,12 @@ TSPLConnectionClient tsplConnectionClient = new USBConnectionClient(
(short) xxxx, 16)); // product id of TSPL2 based printer

// Or Ethernet Client
// TSPLConnectionClient tsplConnectionClient = new EthernetConnectionClient("x.x.x.x", 9100);

TSPLConnectionClient tsplConnectionClient = new EthernetConnectionClient("x.x.x.x", 9100);
```

Initialize the printer with defaults
```java
// Initialize the printer with defaults
tsplConnectionClient.init();
```

Once initialized, Establish the connection
```java
// Once initialized, Establish the connection
tsplConnectionClient.connect();
```

Expand All @@ -71,7 +66,6 @@ TSPLLabel tsplLabel = TSPLLabel.builder()
.build();

tsplConnectionClient.send(tsplLabel);

```

The above will send the following TSPL2 code to printer
Expand Down Expand Up @@ -110,10 +104,8 @@ Implement [ClientListener](src/main/java/org/fintrace/core/drivers/tspl/listener
Other documentation
=================

Documentation about TSPL could be find here
http://www.tscprinters.com/cms/upload/download_en/TSPL_TSPL2_Programming.pdf
or
http://mediaform.de/fileadmin/support/handbuecher/Armilla/Handbuecher/TSC_TSPL_TSPL2_Programming.pdf
Documentation about TSPL2 could be found here
https://shop.mediaform.de/media/wysiwyg/downloads/armilla/TSC_TSPL_TSPL2_Programming.pdf

Contributions
=================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum TSPLDeviceConfigurationCommands implements TSPLCommand {

/**
* Set number of printing labels per cut. 0<= pieces <=65535.
* Shall append the this command with the number of pieces.
* Shall append the command with the number of pieces.
*/
PARTIAL_CUTTER_PIECES(DeviceConfigCommand.PARTIAL_CUTTER, PartialCutterValues.Pieces),

Expand All @@ -64,7 +64,7 @@ public enum TSPLDeviceConfigurationCommands implements TSPLCommand {

/**
* Set number of printing labels per cut. 0<= pieces <=65535.
* Shall append the this command with the number of pieces.
* Shall append the command with the number of pieces.
*/
CUTTER_PIECES(DeviceConfigCommand.CUTTER, PartialCutterValues.Pieces),

Expand Down Expand Up @@ -108,15 +108,15 @@ public enum TSPLDeviceConfigurationCommands implements TSPLCommand {
*/
ENCODER_OFF(DeviceConfigCommand.ENCODER, EncoderCommandValues.OFF);

private DeviceConfigCommand command;
private CommandValues commandValue;
private final DeviceConfigCommand command;
private final CommandValues<String> commandValue;

/**
* @param command
* @param commandValue
*/
TSPLDeviceConfigurationCommands(DeviceConfigCommand command,
CommandValues commandValue) {
CommandValues<String> commandValue) {
this.command = command;
this.commandValue = commandValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,75 +107,72 @@ public class AztecBarcode implements TSPLCommand {
*/
@Override
public String getCommand() {
validateRequiredFields();

return new StringBuilder(AZTEC.name())
.append(EMPTY_SPACE)
.append(xCoordinate).append(COMMA)
.append(yCoordinate).append(COMMA)
.append(rotation.getRotation()).append(COMMA)
.append(getModuleSizeCommandPart())
.append(getErrorControlCommandPart())
.append(getEscapeFlagCommandPart())
.append(getMenuCommandPart())
.append(getMultiCommandPart())
.append(getRevCommandPart())
.append(getBytesCommandPart())
.append(content)
.append(LF)
.toString();
}

private void validateRequiredFields() {
if (xCoordinate == null || yCoordinate == null) {
throw new LabelParserException("AZTEC: x and y positions are required");
}

if (rotation == null) {
throw new LabelParserException("AZTEC: rotation is required");
}

if (moduleSize != null && (moduleSize < 1 || moduleSize > 20)) {
throw new LabelParserException("AZTEC: invalid module size value");
}

if (errorControl != null && (errorControl == 100
|| (errorControl > 104 && errorControl <= 200)
|| (errorControl > 232 && errorControl < 300)
|| (errorControl > 300))) {
if (errorControl != null && checkInvalidErrorControl()) {
throw new LabelParserException("AZTEC: invalid error control parameter");
}
}

StringBuilder commandBuilder = new StringBuilder(AZTEC.name());
commandBuilder.append(EMPTY_SPACE)
.append(xCoordinate).append(COMMA)
.append(yCoordinate).append(COMMA)
.append(rotation.getRotation()).append(COMMA);

if (moduleSize == null) {
commandBuilder.append("6").append(COMMA);
} else {
commandBuilder.append(moduleSize).append(COMMA);
}

if (errorControl == null) {
commandBuilder.append("0").append(COMMA);
} else {
commandBuilder.append(errorControl).append(COMMA);
}

commandBuilder.append(escapeFlag).append(COMMA);
private boolean checkInvalidErrorControl() {
return errorControl == 100
|| (errorControl > 104 && errorControl <= 200)
|| (errorControl > 232 && errorControl < 300)
|| (errorControl > 300);
}

if (menu == null) {
commandBuilder.append("0").append(COMMA);
} else {
commandBuilder.append(menu ? "1" : "0").append(COMMA);
}
private String getModuleSizeCommandPart() {
return (moduleSize == null ? "6" : moduleSize) + COMMA;
}

if (multi == null) {
commandBuilder.append("6").append(COMMA);
} else {
commandBuilder.append(multi).append(COMMA);
}
private String getErrorControlCommandPart() {
return (errorControl == null ? "0" : errorControl) + COMMA;
}

if (rev == null) {
commandBuilder.append("0").append(COMMA);
} else {
commandBuilder.append(rev ? "1" : "0").append(COMMA);
}
private String getEscapeFlagCommandPart() {
return escapeFlag + COMMA;
}

if (bytes != null) {
commandBuilder.append(bytes).append(COMMA)
.append("\"");
}
private String getMenuCommandPart() {
return (menu == null ? "0" : (menu ? "1" : "0")) + COMMA;
}

commandBuilder.append(content);
private String getMultiCommandPart() {
return (multi == null ? "6" : multi) + COMMA;
}

if (bytes != null) {
commandBuilder.append("\"");
}
private String getRevCommandPart() {
return (rev == null ? "0" : (rev ? "1" : "0")) + COMMA;
}

commandBuilder.append(LF);
return commandBuilder.toString();
private String getBytesCommandPart() {
return bytes == null ? "" : bytes + COMMA + '"';
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ public String getCommand() {
throw new LabelParserException("BAR: height is required");
}

return LabelFormatCommand.BAR.name() + EMPTY_SPACE
+ xCoordinate + COMMA
+ yCoordinate + COMMA
+ width + COMMA
+ height
+ LF;
return new StringBuilder(LabelFormatCommand.BAR.name()).append(EMPTY_SPACE)
.append(xCoordinate).append(COMMA)
.append(yCoordinate).append(COMMA)
.append(width).append(COMMA)
.append(height).append(LF)
.toString();
}
}

0 comments on commit 9fee039

Please sign in to comment.