|
|
|
@@ -831,7 +831,17 @@ class PlasticBagPrinterService( |
|
|
|
): Pair<Boolean, String> { |
|
|
|
return when (printerType.lowercase()) { |
|
|
|
"dataflex" -> checkTcpPrinter(printerIp, printerPort ?: 3008, "DataFlex") |
|
|
|
"laser" -> checkTcpPrinter(printerIp, printerPort ?: 45678, "Laser") |
|
|
|
// - /bagPrint: sends browser localStorage laser IP (may differ from DB — second machine). |
|
|
|
// - /laserPrint: omit printerIp → use DB LASER_PRINT.* (same as sendLaserBag2Job). |
|
|
|
// - Explicit empty string → not configured (do not fall back to DB). |
|
|
|
"laser" -> { |
|
|
|
val trimmed = printerIp?.trim().orEmpty() |
|
|
|
when { |
|
|
|
trimmed.isNotEmpty() -> checkTcpPrinter(trimmed, printerPort ?: 45678, "Laser") |
|
|
|
printerIp == null -> checkTcpPrinter(resolveLaserBag2Host(), resolveLaserBag2Port(), "Laser") |
|
|
|
else -> false to "Laser IP is not configured" |
|
|
|
} |
|
|
|
} |
|
|
|
"label" -> { |
|
|
|
val comPort = labelCom?.trim().orEmpty() |
|
|
|
if (comPort.isBlank()) { |
|
|
|
@@ -853,14 +863,14 @@ class PlasticBagPrinterService( |
|
|
|
return try { |
|
|
|
Socket().use { socket -> |
|
|
|
socket.connect(InetSocketAddress(ip, port), 3000) |
|
|
|
true to "$printerName connected" |
|
|
|
true to "$printerName 已連線($ip:$port)" |
|
|
|
} |
|
|
|
} catch (e: SocketTimeoutException) { |
|
|
|
false to "$printerName connection timed out" |
|
|
|
false to "$printerName 連線逾時($ip:$port)" |
|
|
|
} catch (e: ConnectException) { |
|
|
|
false to "$printerName connection refused" |
|
|
|
false to "$printerName 無法連線($ip:$port)" |
|
|
|
} catch (e: Exception) { |
|
|
|
false to "$printerName connection failed: ${e.message}" |
|
|
|
false to "$printerName 連線失敗($ip:$port):${e.message}" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|