From 9ef87077d1e9115f7ab43660c816725c574fb3c4 Mon Sep 17 00:00:00 2001 From: 17380053893 <1992879953@qq.com> Date: Tue, 29 Sep 2026 18:31:28 +0800 Subject: [PATCH] 美国版 App 对接外接佳博 GP-D750 蓝牙打印机,走 SDK2 且不改动其他机型。 --- 打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java | 12 +++++++++++- 美国版/Food Labeling Management App UniApp/src/utils/print/drivers/gpD750.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 美国版/Food Labeling Management App UniApp/src/utils/print/manager/driverRegistry.ts | 2 ++ 美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts | 26 +++++++++++++++++--------- 美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts | 3 +++ 美国版/Food Labeling Management App UniApp/src/utils/print/printerConnection.ts | 3 ++- 6 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 美国版/Food Labeling Management App UniApp/src/utils/print/drivers/gpD750.ts diff --git a/打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java b/打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java index 893d28a..cc554f1 100644 --- a/打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java +++ b/打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java @@ -42,7 +42,7 @@ import io.dcloud.feature.uniapp.common.UniModule; public class NativeFastPrinterModule extends UniModule { private static final String BACKEND = "native-fast-printer"; - private static final String PLUGIN_VERSION = "1.2.66-d750-ribbon-dual"; + private static final String PLUGIN_VERSION = "1.2.67-external-d750"; private static final String BUILD_TIME = String.valueOf(System.currentTimeMillis()); private static final Object LOCK = new Object(); private static final ExecutorService PRINT_EXECUTOR = Executors.newSingleThreadExecutor(); @@ -1975,6 +1975,16 @@ public class NativeFastPrinterModule extends UniModule { nameLowerEarly.contains("virtual bt") || nameLowerEarly.contains("virtualbt") || nameLowerEarly.contains("i9200"); + // External GP-D750 head is 108mm. Do not apply this cap to Virtual BT or the D750 AIO host. + boolean hostAioEarly = isAndroidModelD750() || isAndroidModelD740(); + boolean externalDesktopD750 = !hostAioEarly + && !virtualBt + && (nameLowerEarly.contains("d750") || nameLowerEarly.contains("gp-d750")) + && !nameLowerEarly.contains("d320") + && !nameLowerEarly.contains("rda320"); + if (externalDesktopD750 && wMm > 108) { + wMm = 108; + } // Pre-binarize at threshold 180 (same as App imageRaster) so gray dotted borders // and bold antialias stems survive SDK addBitmap(dither=false) hard threshold. diff --git a/美国版/Food Labeling Management App UniApp/src/utils/print/drivers/gpD750.ts b/美国版/Food Labeling Management App UniApp/src/utils/print/drivers/gpD750.ts new file mode 100644 index 0000000..1ff3b00 --- /dev/null +++ b/美国版/Food Labeling Management App UniApp/src/utils/print/drivers/gpD750.ts @@ -0,0 +1,51 @@ +import { buildTscLabelData, buildTscTestPrintData } from '../protocols/tscProtocol' +import type { PrinterCandidate, PrinterDriver } from '../types/printer' +import { isGpD740AioDevice, isGpD750AioDevice } from '../../deviceInfo' + +/** + * 外接佳博 GP-D750(蓝牙名常见 D750_FFD0)。 + * 手机自己是 D740/D750 一体机时不抢驱动,内部打印仍走 Virtual BT / d320fax。 + */ +const KEYWORDS = [ + 'gp-d750', + 'd750', +] + +function score (device: PrinterCandidate): number { + if (isGpD750AioDevice() || isGpD740AioDevice()) return 0 + const text = `${device.name || ''} ${device.deviceId || ''}`.toLowerCase() + let total = 0 + KEYWORDS.forEach((keyword) => { + if (text.includes(keyword)) total += 120 + }) + return total +} + +export const gpD750Driver: PrinterDriver = { + key: 'gp-d750', + brand: 'Gprinter', + model: 'GP-D750', + displayName: 'Gprinter GP-D750 (Gainscha SDK2)', + protocol: 'tsc', + // 外接桌面机:连续纸 GAP 0、缝隙纸 GAP n。黑标沿用同一套 SDK2 纸型指令。 + supportedMediaTypes: ['continuous', 'gap', 'black-mark'], + // 佳博把蓝牙名做成「型号_MAC末四位」,例如 D750_FFD0。双模:经典 SPP 优先,失败再回 BLE。 + preferredConnection: 'classic', + preferredBleMtu: 20, + // 108mm 机头 @ 300DPI,宽按 8 点对齐:floor(108 * 300 / 25.4 / 8) * 8 = 1272。 + imageMaxWidthDots: 1272, + imageDpi: 300, + keywords: KEYWORDS, + matches (device) { + return score(device) + }, + resolveConnectionType (device) { + return device.type === 'classic' ? 'classic' : 'ble' + }, + buildTestPrintData () { + return buildTscTestPrintData() + }, + buildLabelData (payload) { + return buildTscLabelData(payload) + }, +} diff --git a/美国版/Food Labeling Management App UniApp/src/utils/print/manager/driverRegistry.ts b/美国版/Food Labeling Management App UniApp/src/utils/print/manager/driverRegistry.ts index 3dee04c..5333d4b 100644 --- a/美国版/Food Labeling Management App UniApp/src/utils/print/manager/driverRegistry.ts +++ b/美国版/Food Labeling Management App UniApp/src/utils/print/manager/driverRegistry.ts @@ -3,12 +3,14 @@ import { d320faxDriver } from '../drivers/d320fax' import { genericEscDriver } from '../drivers/genericEsc' import { genericTscDriver } from '../drivers/genericTsc' import { gpD320fxDriver } from '../drivers/gpD320fx' +import { gpD750Driver } from '../drivers/gpD750' import { gpR3Driver } from '../drivers/gpR3' import type { PrinterCandidate, PrinterDriver, ResolvedPrinterCandidate } from '../types/printer' const printerDrivers: PrinterDriver[] = [ gpR3Driver, gpD320fxDriver, + gpD750Driver, d320faxDriver, bixolonLabelDriver, genericEscDriver, diff --git a/美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts b/美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts index 8fc806e..17572a0 100644 --- a/美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts +++ b/美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts @@ -259,10 +259,10 @@ function withPrinterSpecificImageOptions ( rasterDriver: PrinterDriver, options: PrintImageOptions, ): PrintImageOptions { - if (rasterDriver.protocol === 'tsc' && driver.key === 'gp-d320fx') { - // GP-D320FX follows the TSPL BITMAP convention used by the Gprinter SDK: - // a cleared bit is a black/heated dot and a set bit remains white. Sending - // black as 1 makes the printer feed a correctly-sized but fully blank label. + if (rasterDriver.protocol === 'tsc' && (driver.key === 'gp-d320fx' || driver.key === 'gp-d750')) { + // Gprinter TSPL BITMAP: a cleared bit is a black/heated dot and a set bit + // remains white. Sending black as 1 feeds a correctly-sized blank label. + // gp-d750 uses this only on the BLE/JS fallback; classic jobs go through SDK2. return { ...options, tscBitmapBlackPixelValue: 0, @@ -796,7 +796,7 @@ function connectClassicBluetooth (device: PrinterCandidate, driver: PrinterDrive } } - if (isNativeFastPrinterAvailable() && (driver.key === 'bixolon-label' || driver.key === 'd320fax' || driver.key === 'gp-d320fx')) { + if (isNativeFastPrinterAvailable() && (driver.key === 'bixolon-label' || driver.key === 'd320fax' || driver.key === 'gp-d320fx' || driver.key === 'gp-d750')) { if (driver.key === 'bixolon-label') { setBluetoothConnection({ deviceId: device.deviceId, @@ -850,7 +850,7 @@ function connectClassicBluetooth (device: PrinterCandidate, driver: PrinterDrive } return } - if (driver.key === 'd320fax' || driver.key === 'gp-d320fx' || shouldUseGenericClassicOnly) { + if (driver.key === 'd320fax' || driver.key === 'gp-d320fx' || driver.key === 'gp-d750' || shouldUseGenericClassicOnly) { connectClassicSocketFallback() return } @@ -949,9 +949,10 @@ export async function connectBluetoothPrinter (device: PrinterCandidate): Promis }) return driver } - if (driver.key === 'gp-d320fx') { + if (driver.key === 'gp-d320fx' || driver.key === 'gp-d750') { // Prefer Gainscha SDK2 (native-plugin) when the custom base is present. // Fall back to BLE / classic socket only if the native open fails. + // gp-d750 广播名是「型号_MAC末四位」(如 D750_FFD0)。先开经典 SPP + SDK2,失败再回 BLE。 if (isNativeFastPrinterAvailable()) { try { await connectClassicBluetooth(device, driver) @@ -1277,7 +1278,7 @@ export async function testPrintCurrentPrinter ( // 佳博 D320FAX / GP-D320FX(含 Virtual BT):测试打印走与正式打印相同的 SDK2 光栅路径。 // 旧 gprinterTsplProbe 会在 writeMs=0(同毫秒写完)时误报 EMPTY_WRITE,尽管纸已出。 - if ((driver.key === 'd320fax' || driver.key === 'gp-d320fx') && connection?.transportMode === 'native-plugin') { + if ((driver.key === 'd320fax' || driver.key === 'gp-d320fx' || driver.key === 'gp-d750') && connection?.transportMode === 'native-plugin') { if (!isNativeGainschaSdk2RasterPrintSupported()) { throw new Error('NATIVE_GAINSCHA_SDK2_RASTER_NOT_SUPPORTED. Please rebuild the custom base with native-fast-printer.') } @@ -1331,6 +1332,7 @@ export async function testPrintCurrentPrinter ( heightMm: 30, mediaType, mediaGapMm, + ...(driver.key === 'gp-d750' ? { dpi: driver.imageDpi || 300 } : {}), }) if (onProgress) onProgress(100) return driver @@ -1531,6 +1533,11 @@ export async function printImageForCurrentPrinter ( && connForSdk2?.deviceType === 'classic' && connForSdk2?.transportMode === 'native-plugin' ) + || ( + driver.key === 'gp-d750' + && connForSdk2?.deviceType === 'classic' + && connForSdk2?.transportMode === 'native-plugin' + ) ) if (useGainschaSdk2BitmapFile) { const conn = connForSdk2 @@ -2141,7 +2148,7 @@ export async function printImageDataForCurrentPrinter ( // 改走下方 JS buildTscImageLabel + sendToPrinter→printCommandBytes(与 BLE 同源 BITMAP 打包)。 // d320fax(非 Virtual BT)仍可用 SDK2 raster。 if ( - driver.key === 'd320fax' + (driver.key === 'd320fax' || driver.key === 'gp-d750') && getPrinterType() === 'bluetooth' && !isVirtualBtBluetoothConnection() && getBluetoothConnection()?.deviceType === 'classic' @@ -2196,6 +2203,7 @@ export async function printImageDataForCurrentPrinter ( mediaGapMm: getCurrentPrinterMediaGapMm(), forceGapFormFeed, disableCutter: shouldDisableCutterForCurrentMedia(), + ...(driver.key === 'gp-d750' ? { dpi: rasterDriver.imageDpi || 300 } : {}), }) if (forceGapFormFeed) clearSdk2GapNeedFormFeed() printRunDiag('gainscha_sdk2_raster_done', { widthDots, heightDots, printQty, pixelBytes: pixels.length }) diff --git a/美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts b/美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts index 302e0b3..c50c362 100644 --- a/美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts +++ b/美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts @@ -541,6 +541,8 @@ export function printNativeGainschaSdk2RasterBase64 (options: { forceGapFormFeed?: boolean /** Gap / black-mark → true:不开切刀 */ disableCutter?: boolean + /** 外接 GP-D750 传 300。不传时原生按设备名 / 主机型号决定。 */ + dpi?: number }) { return wrapCallback('printGainschaSdk2RasterBase64', 180000, (resolve, reject) => { try { @@ -563,6 +565,7 @@ export function printNativeGainschaSdk2RasterBase64 (options: { mediaGapMm: options.mediaGapMm ?? 0, forceGapFormFeed: !!options.forceGapFormFeed, disableCutter: !!options.disableCutter, + ...(options.dpi ? { dpi: Math.max(150, Math.min(600, Math.round(options.dpi))) } : {}), }, (raw: any) => { const res = parsePluginResult(raw) updateNativeState({ ...res, lastAction: 'printGainschaSdk2RasterBase64' }) diff --git a/美国版/Food Labeling Management App UniApp/src/utils/print/printerConnection.ts b/美国版/Food Labeling Management App UniApp/src/utils/print/printerConnection.ts index 775b5f1..f19823b 100644 --- a/美国版/Food Labeling Management App UniApp/src/utils/print/printerConnection.ts +++ b/美国版/Food Labeling Management App UniApp/src/utils/print/printerConnection.ts @@ -507,6 +507,7 @@ export function getBluetoothConnection (): { const transportMode = storedDriverKey === 'bixolon-label' || storedDriverKey === 'd320fax' || storedDriverKey === 'gp-d320fx' + || storedDriverKey === 'gp-d750' ? storedTransportMode : 'generic' if (!deviceId) return null @@ -1511,7 +1512,7 @@ function isCurrentGprinterClassicConnection (): boolean { const conn = getBluetoothConnection() if (!conn || conn.deviceType !== 'classic') return false const key = String(conn.driverKey || getCurrentPrinterDriverKey() || '').trim().toLowerCase() - if (key === 'gp-d320fx' || key === 'gp-r3' || key === 'gp-9442d') return true + if (key === 'gp-d320fx' || key === 'gp-d750' || key === 'gp-r3' || key === 'gp-9442d') return true const name = String(conn.deviceName || '').toLowerCase() return name.includes('gprinter') || name.includes('gp-d320') } -- libgit2 0.21.4