You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native对接LW-600P蓝牙热敏打印机无打印输出问题求助

LW-600P蓝牙打印机无输出问题排查与解决方案

问题背景

已成功扫描并连接LW-600P蓝牙热敏标签打印机,但调用react-native-bluetooth-escpos-printer库的打印接口后无任何输出,使用React Native 73版本,同时测试了Escpos和Tsc两种打印逻辑。


排查方向与解决方案

1. Tsc打印参数与设备标签规格不匹配

你的options中设置的width:12、height:30不符合LW-600P的60mm宽标签规格(对应203DPI约477像素点),过小的尺寸会导致打印机无法识别有效打印内容。

  • 解决方案:修改参数匹配实际标签规格,示例:
    let options = {
        width: 60, // 匹配60mm标准宽标签
        height: 40, // 对应实际标签高度(如40mm)
        gap: 2, // 标签间距,根据实际耗材调整
        direction: BluetoothTscPrinter.DIRECTION.FORWARD,
        reference: [0, 0],
        tear: BluetoothTscPrinter.TEAR.ON,
        sound: 0,
        text: [{
            text: '测试打印内容',
            x: 20,
            y: 10,
            fonttype: BluetoothTscPrinter.FONTTYPE.SIMPLIFIED_CHINESE,
            rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,
            xscal: BluetoothTscPrinter.FONTMUL.MUL_2,
            yscal: BluetoothTscPrinter.FONTMUL.MUL_2
        }],
    }
    

2. 未验证蓝牙连接状态与打印机初始化

即使显示连接成功,也可能存在通道未绑定或连接异常的情况;同时Escpos/Tsc打印需要对应初始化逻辑,否则指令无法被打印机识别。

  • 解决方案:
    • 打印前强制验证连接状态:
      const isConnected = await BluetoothEscposPrinter.isConnected();
      if (!isConnected) {
          alert('打印机未正常连接');
          return;
      }
      
    • 打印前添加初始化指令:
      • Escpos打印:await BluetoothEscposPrinter.printerInit();
      • Tsc打印:await BluetoothTscPrinter.setup();

3. RN版本与库依赖兼容性冲突

React Native 73使用AndroidX,但你的库build.gradle中同时存在AndroidX和support-v4依赖,且RN版本未明确指定,可能导致适配错误。

  • 解决方案:修改库的build.gradle配置:
    android {
        compileSdkVersion 34
        buildToolsVersion "34.0.0" // 与compileSdkVersion匹配
        // ...其他配置不变
    }
    
    dependencies {
        implementation "androidx.core:core-ktx:+"
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        implementation 'com.facebook.react:react-native:73.0.0' // 明确指定RN版本
        // 移除support-v4依赖
        implementation "com.google.zxing:core:3.4.1" // 更新到兼容版本
    }
    

4. 缺少打印触发指令

部分标签打印机需要明确的结束/切割指令来触发纸张吐出,仅换行可能无法触发打印动作。

  • 解决方案:
    • Escpos打印末尾添加切割指令:await BluetoothEscposPrinter.printerCut();
    • Tsc打印确认调用printLabel后执行缓冲区输出:await BluetoothTscPrinter.printBuffer();

5. 编码与字体设置不兼容

你使用的GBK编码可能未被LW-600P支持,或字体类型设置错误导致内容无法渲染,打印机跳过无效指令。

  • 解决方案:切换为UTF-8编码并调整字体参数:
    await BluetoothEscposPrinter.printText('测试打印\r\n', {
        encoding: 'UTF-8',
        codepage: 16, // 对应UTF-8的codepage值
        widthtimes: 1,
        heigthtimes: 1,
        fonttype: 0,
    });
    

内容的提问来源于stack exchange,提问作者Andy Yogaswara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 07:27:11