Commit 9ef87077d1e9115f7ab43660c816725c574fb3c4

Authored by 王天杨
1 parent ae1a2647

美国版 App 对接外接佳博 GP-D750 蓝牙打印机,走 SDK2 且不改动其他机型。

EOF

Co-authored-by: Cursor <cursoragent@cursor.com>
打印机安卓基座/native-fast-printer/android-src/src/com/foodlabel/nativeprinter/NativeFastPrinterModule.java
... ... @@ -42,7 +42,7 @@ import io.dcloud.feature.uniapp.common.UniModule;
42 42  
43 43 public class NativeFastPrinterModule extends UniModule {
44 44 private static final String BACKEND = "native-fast-printer";
45   - private static final String PLUGIN_VERSION = "1.2.66-d750-ribbon-dual";
  45 + private static final String PLUGIN_VERSION = "1.2.67-external-d750";
46 46 private static final String BUILD_TIME = String.valueOf(System.currentTimeMillis());
47 47 private static final Object LOCK = new Object();
48 48 private static final ExecutorService PRINT_EXECUTOR = Executors.newSingleThreadExecutor();
... ... @@ -1975,6 +1975,16 @@ public class NativeFastPrinterModule extends UniModule {
1975 1975 nameLowerEarly.contains("virtual bt")
1976 1976 || nameLowerEarly.contains("virtualbt")
1977 1977 || nameLowerEarly.contains("i9200");
  1978 + // External GP-D750 head is 108mm. Do not apply this cap to Virtual BT or the D750 AIO host.
  1979 + boolean hostAioEarly = isAndroidModelD750() || isAndroidModelD740();
  1980 + boolean externalDesktopD750 = !hostAioEarly
  1981 + && !virtualBt
  1982 + && (nameLowerEarly.contains("d750") || nameLowerEarly.contains("gp-d750"))
  1983 + && !nameLowerEarly.contains("d320")
  1984 + && !nameLowerEarly.contains("rda320");
  1985 + if (externalDesktopD750 && wMm > 108) {
  1986 + wMm = 108;
  1987 + }
1978 1988  
1979 1989 // Pre-binarize at threshold 180 (same as App imageRaster) so gray dotted borders
1980 1990 // and bold antialias stems survive SDK addBitmap(dither=false) hard threshold.
... ...
美国版/Food Labeling Management App UniApp/src/utils/print/drivers/gpD750.ts 0 → 100644
  1 +import { buildTscLabelData, buildTscTestPrintData } from '../protocols/tscProtocol'
  2 +import type { PrinterCandidate, PrinterDriver } from '../types/printer'
  3 +import { isGpD740AioDevice, isGpD750AioDevice } from '../../deviceInfo'
  4 +
  5 +/**
  6 + * 外接佳博 GP-D750(蓝牙名常见 D750_FFD0)。
  7 + * 手机自己是 D740/D750 一体机时不抢驱动,内部打印仍走 Virtual BT / d320fax。
  8 + */
  9 +const KEYWORDS = [
  10 + 'gp-d750',
  11 + 'd750',
  12 +]
  13 +
  14 +function score (device: PrinterCandidate): number {
  15 + if (isGpD750AioDevice() || isGpD740AioDevice()) return 0
  16 + const text = `${device.name || ''} ${device.deviceId || ''}`.toLowerCase()
  17 + let total = 0
  18 + KEYWORDS.forEach((keyword) => {
  19 + if (text.includes(keyword)) total += 120
  20 + })
  21 + return total
  22 +}
  23 +
  24 +export const gpD750Driver: PrinterDriver = {
  25 + key: 'gp-d750',
  26 + brand: 'Gprinter',
  27 + model: 'GP-D750',
  28 + displayName: 'Gprinter GP-D750 (Gainscha SDK2)',
  29 + protocol: 'tsc',
  30 + // 外接桌面机:连续纸 GAP 0、缝隙纸 GAP n。黑标沿用同一套 SDK2 纸型指令。
  31 + supportedMediaTypes: ['continuous', 'gap', 'black-mark'],
  32 + // 佳博把蓝牙名做成「型号_MAC末四位」,例如 D750_FFD0。双模:经典 SPP 优先,失败再回 BLE。
  33 + preferredConnection: 'classic',
  34 + preferredBleMtu: 20,
  35 + // 108mm 机头 @ 300DPI,宽按 8 点对齐:floor(108 * 300 / 25.4 / 8) * 8 = 1272。
  36 + imageMaxWidthDots: 1272,
  37 + imageDpi: 300,
  38 + keywords: KEYWORDS,
  39 + matches (device) {
  40 + return score(device)
  41 + },
  42 + resolveConnectionType (device) {
  43 + return device.type === 'classic' ? 'classic' : 'ble'
  44 + },
  45 + buildTestPrintData () {
  46 + return buildTscTestPrintData()
  47 + },
  48 + buildLabelData (payload) {
  49 + return buildTscLabelData(payload)
  50 + },
  51 +}
... ...
美国版/Food Labeling Management App UniApp/src/utils/print/manager/driverRegistry.ts
... ... @@ -3,12 +3,14 @@ import { d320faxDriver } from &#39;../drivers/d320fax&#39;
3 3 import { genericEscDriver } from '../drivers/genericEsc'
4 4 import { genericTscDriver } from '../drivers/genericTsc'
5 5 import { gpD320fxDriver } from '../drivers/gpD320fx'
  6 +import { gpD750Driver } from '../drivers/gpD750'
6 7 import { gpR3Driver } from '../drivers/gpR3'
7 8 import type { PrinterCandidate, PrinterDriver, ResolvedPrinterCandidate } from '../types/printer'
8 9  
9 10 const printerDrivers: PrinterDriver[] = [
10 11 gpR3Driver,
11 12 gpD320fxDriver,
  13 + gpD750Driver,
12 14 d320faxDriver,
13 15 bixolonLabelDriver,
14 16 genericEscDriver,
... ...
美国版/Food Labeling Management App UniApp/src/utils/print/manager/printerManager.ts
... ... @@ -259,10 +259,10 @@ function withPrinterSpecificImageOptions (
259 259 rasterDriver: PrinterDriver,
260 260 options: PrintImageOptions,
261 261 ): PrintImageOptions {
262   - if (rasterDriver.protocol === 'tsc' && driver.key === 'gp-d320fx') {
263   - // GP-D320FX follows the TSPL BITMAP convention used by the Gprinter SDK:
264   - // a cleared bit is a black/heated dot and a set bit remains white. Sending
265   - // black as 1 makes the printer feed a correctly-sized but fully blank label.
  262 + if (rasterDriver.protocol === 'tsc' && (driver.key === 'gp-d320fx' || driver.key === 'gp-d750')) {
  263 + // Gprinter TSPL BITMAP: a cleared bit is a black/heated dot and a set bit
  264 + // remains white. Sending black as 1 feeds a correctly-sized blank label.
  265 + // gp-d750 uses this only on the BLE/JS fallback; classic jobs go through SDK2.
266 266 return {
267 267 ...options,
268 268 tscBitmapBlackPixelValue: 0,
... ... @@ -796,7 +796,7 @@ function connectClassicBluetooth (device: PrinterCandidate, driver: PrinterDrive
796 796 }
797 797 }
798 798  
799   - if (isNativeFastPrinterAvailable() && (driver.key === 'bixolon-label' || driver.key === 'd320fax' || driver.key === 'gp-d320fx')) {
  799 + if (isNativeFastPrinterAvailable() && (driver.key === 'bixolon-label' || driver.key === 'd320fax' || driver.key === 'gp-d320fx' || driver.key === 'gp-d750')) {
800 800 if (driver.key === 'bixolon-label') {
801 801 setBluetoothConnection({
802 802 deviceId: device.deviceId,
... ... @@ -850,7 +850,7 @@ function connectClassicBluetooth (device: PrinterCandidate, driver: PrinterDrive
850 850 }
851 851 return
852 852 }
853   - if (driver.key === 'd320fax' || driver.key === 'gp-d320fx' || shouldUseGenericClassicOnly) {
  853 + if (driver.key === 'd320fax' || driver.key === 'gp-d320fx' || driver.key === 'gp-d750' || shouldUseGenericClassicOnly) {
854 854 connectClassicSocketFallback()
855 855 return
856 856 }
... ... @@ -949,9 +949,10 @@ export async function connectBluetoothPrinter (device: PrinterCandidate): Promis
949 949 })
950 950 return driver
951 951 }
952   - if (driver.key === 'gp-d320fx') {
  952 + if (driver.key === 'gp-d320fx' || driver.key === 'gp-d750') {
953 953 // Prefer Gainscha SDK2 (native-plugin) when the custom base is present.
954 954 // Fall back to BLE / classic socket only if the native open fails.
  955 + // gp-d750 广播名是「型号_MAC末四位」(如 D750_FFD0)。先开经典 SPP + SDK2,失败再回 BLE。
955 956 if (isNativeFastPrinterAvailable()) {
956 957 try {
957 958 await connectClassicBluetooth(device, driver)
... ... @@ -1277,7 +1278,7 @@ export async function testPrintCurrentPrinter (
1277 1278  
1278 1279 // 佳博 D320FAX / GP-D320FX(含 Virtual BT):测试打印走与正式打印相同的 SDK2 光栅路径。
1279 1280 // 旧 gprinterTsplProbe 会在 writeMs=0(同毫秒写完)时误报 EMPTY_WRITE,尽管纸已出。
1280   - if ((driver.key === 'd320fax' || driver.key === 'gp-d320fx') && connection?.transportMode === 'native-plugin') {
  1281 + if ((driver.key === 'd320fax' || driver.key === 'gp-d320fx' || driver.key === 'gp-d750') && connection?.transportMode === 'native-plugin') {
1281 1282 if (!isNativeGainschaSdk2RasterPrintSupported()) {
1282 1283 throw new Error('NATIVE_GAINSCHA_SDK2_RASTER_NOT_SUPPORTED. Please rebuild the custom base with native-fast-printer.')
1283 1284 }
... ... @@ -1331,6 +1332,7 @@ export async function testPrintCurrentPrinter (
1331 1332 heightMm: 30,
1332 1333 mediaType,
1333 1334 mediaGapMm,
  1335 + ...(driver.key === 'gp-d750' ? { dpi: driver.imageDpi || 300 } : {}),
1334 1336 })
1335 1337 if (onProgress) onProgress(100)
1336 1338 return driver
... ... @@ -1531,6 +1533,11 @@ export async function printImageForCurrentPrinter (
1531 1533 && connForSdk2?.deviceType === 'classic'
1532 1534 && connForSdk2?.transportMode === 'native-plugin'
1533 1535 )
  1536 + || (
  1537 + driver.key === 'gp-d750'
  1538 + && connForSdk2?.deviceType === 'classic'
  1539 + && connForSdk2?.transportMode === 'native-plugin'
  1540 + )
1534 1541 )
1535 1542 if (useGainschaSdk2BitmapFile) {
1536 1543 const conn = connForSdk2
... ... @@ -2141,7 +2148,7 @@ export async function printImageDataForCurrentPrinter (
2141 2148 // 改走下方 JS buildTscImageLabel + sendToPrinter→printCommandBytes(与 BLE 同源 BITMAP 打包)。
2142 2149 // d320fax(非 Virtual BT)仍可用 SDK2 raster。
2143 2150 if (
2144   - driver.key === 'd320fax'
  2151 + (driver.key === 'd320fax' || driver.key === 'gp-d750')
2145 2152 && getPrinterType() === 'bluetooth'
2146 2153 && !isVirtualBtBluetoothConnection()
2147 2154 && getBluetoothConnection()?.deviceType === 'classic'
... ... @@ -2196,6 +2203,7 @@ export async function printImageDataForCurrentPrinter (
2196 2203 mediaGapMm: getCurrentPrinterMediaGapMm(),
2197 2204 forceGapFormFeed,
2198 2205 disableCutter: shouldDisableCutterForCurrentMedia(),
  2206 + ...(driver.key === 'gp-d750' ? { dpi: rasterDriver.imageDpi || 300 } : {}),
2199 2207 })
2200 2208 if (forceGapFormFeed) clearSdk2GapNeedFormFeed()
2201 2209 printRunDiag('gainscha_sdk2_raster_done', { widthDots, heightDots, printQty, pixelBytes: pixels.length })
... ...
美国版/Food Labeling Management App UniApp/src/utils/print/nativeFastPrinter.ts
... ... @@ -541,6 +541,8 @@ export function printNativeGainschaSdk2RasterBase64 (options: {
541 541 forceGapFormFeed?: boolean
542 542 /** Gap / black-mark → true:不开切刀 */
543 543 disableCutter?: boolean
  544 + /** 外接 GP-D750 传 300。不传时原生按设备名 / 主机型号决定。 */
  545 + dpi?: number
544 546 }) {
545 547 return wrapCallback('printGainschaSdk2RasterBase64', 180000, (resolve, reject) => {
546 548 try {
... ... @@ -563,6 +565,7 @@ export function printNativeGainschaSdk2RasterBase64 (options: {
563 565 mediaGapMm: options.mediaGapMm ?? 0,
564 566 forceGapFormFeed: !!options.forceGapFormFeed,
565 567 disableCutter: !!options.disableCutter,
  568 + ...(options.dpi ? { dpi: Math.max(150, Math.min(600, Math.round(options.dpi))) } : {}),
566 569 }, (raw: any) => {
567 570 const res = parsePluginResult(raw)
568 571 updateNativeState({ ...res, lastAction: 'printGainschaSdk2RasterBase64' })
... ...
美国版/Food Labeling Management App UniApp/src/utils/print/printerConnection.ts
... ... @@ -507,6 +507,7 @@ export function getBluetoothConnection (): {
507 507 const transportMode = storedDriverKey === 'bixolon-label'
508 508 || storedDriverKey === 'd320fax'
509 509 || storedDriverKey === 'gp-d320fx'
  510 + || storedDriverKey === 'gp-d750'
510 511 ? storedTransportMode
511 512 : 'generic'
512 513 if (!deviceId) return null
... ... @@ -1511,7 +1512,7 @@ function isCurrentGprinterClassicConnection (): boolean {
1511 1512 const conn = getBluetoothConnection()
1512 1513 if (!conn || conn.deviceType !== 'classic') return false
1513 1514 const key = String(conn.driverKey || getCurrentPrinterDriverKey() || '').trim().toLowerCase()
1514   - if (key === 'gp-d320fx' || key === 'gp-r3' || key === 'gp-9442d') return true
  1515 + if (key === 'gp-d320fx' || key === 'gp-d750' || key === 'gp-r3' || key === 'gp-9442d') return true
1515 1516 const name = String(conn.deviceName || '').toLowerCase()
1516 1517 return name.includes('gprinter') || name.includes('gp-d320')
1517 1518 }
... ...