Skip to content

Commit

Permalink
Set serial encoding to null if empty in sample.html (qzind#954)
Browse files Browse the repository at this point in the history
Set serial encoding to null if empty in sample.html

Co-authored-by: Berenz <[email protected]>
  • Loading branch information
klabarge and Berenz authored May 20, 2022
1 parent 521e186 commit 0297d5b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
12 changes: 6 additions & 6 deletions sample.html
Original file line number Diff line number Diff line change
Expand Up @@ -2457,8 +2457,8 @@ <h4 class="panel-title">Options</h4>
function resetRawOptions() {
//config
$("#rawSpoolSize").val(1);
$("#rawEncoding").val(null);
$("#rawSpoolEnd").val(null);
$("#rawEncoding").val("");
$("#rawSpoolEnd").val("");
$("#rawForceRaw").prop('checked', false);
$("#rawCopies").val(1);

Expand All @@ -2481,8 +2481,8 @@ <h4 class="panel-title">Options</h4>
$("#pxlJobName").val("");
$("#pxlLegacy").prop('checked', false);
$("#pxlOrientation").val("");
$("#pxlPaperThickness").val(null);
$("#pxlPrinterTray").val(null);
$("#pxlPaperThickness").val("");
$("#pxlPrinterTray").val("");
$("#pxlRasterize").prop('checked', false);
$("#pxlRotation").val(0);
$("#pxlSpoolSize").val("");
Expand Down Expand Up @@ -2543,7 +2543,7 @@ <h4 class="panel-title">Options</h4>
$("#serialEnd").val('');
$("#serialWidth").val('');
$("#serialHeader").prop('checked', false);
$("#serialRespEncoding").val('');
$("#serialRespEncoding").val('UTF-8');
$("#serialLenIndex").val('0');
$("#serialLenLength").val('1');
$("#serialLenEndianBig").prop('checked', true);
Expand Down Expand Up @@ -3101,7 +3101,7 @@ <h4 class="panel-title">Options</h4>
stopBits: $("#serialStop").val(),
parity: $("#serialParity").val(),
flowControl: $("#serialFlow").val(),
encoding: $("#serialEncoding").val(),
encoding: $("#serialEncoding").val() || null,
rx: {
start: $("#serialStart").val(),
end: $("#serialEnd").val() || null,
Expand Down
4 changes: 2 additions & 2 deletions src/qz/communication/SerialOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public SerialOptions(JSONObject serialOpts, boolean isOpening) {
catch(JSONException e) { LoggerUtilities.optionWarn(log, "string", "flowControl", serialOpts.opt("flowControl")); }
}

if (!serialOpts.isNull("encoding")) {
if (!serialOpts.isNull("encoding") && !serialOpts.optString("encoding").isEmpty()) {
try { portSettings.encoding = Charset.forName(serialOpts.getString("encoding")); }
catch(JSONException e) { LoggerUtilities.optionWarn(log, "string", "encoding", serialOpts.opt("encoding")); }
}
Expand Down Expand Up @@ -179,7 +179,7 @@ public SerialOptions(JSONObject serialOpts, boolean isOpening) {
}
}

if (!respOpts.isNull("encoding")) {
if (!respOpts.isNull("encoding") && !respOpts.optString("encoding").isEmpty()) {
try { responseFormat.encoding = Charset.forName(respOpts.getString("encoding")); }
catch(JSONException | IllegalArgumentException e) { LoggerUtilities.optionWarn(log, "charset", "encoding", respOpts.opt("encoding")); }
}
Expand Down
8 changes: 7 additions & 1 deletion src/qz/utils/SerialUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public static int parseDataBits(String data) {
log.trace("Parsed serial setting: DATABITS_7");
return SerialPort.DATABITS_7;
case "8":
case "":
log.trace("Parsed serial setting: DATABITS_8");
return SerialPort.DATABITS_8;
default:
Expand Down Expand Up @@ -210,7 +211,12 @@ public static int parseParity(String parity) {
*/
public static int parseBaudRate(String rate) {
int baud = -1;
try { baud = Integer.decode(rate.trim()); } catch(NumberFormatException ignore) {}

if (rate.trim().isEmpty()) {
baud = SerialPort.BAUDRATE_9600;
} else {
try { baud = Integer.decode(rate.trim()); } catch(NumberFormatException ignore) {}
}

if (baud == 0) {
log.trace("Parsed serial setting: 0 (Auto)");
Expand Down

0 comments on commit 0297d5b

Please sign in to comment.