React Native LW-600P Bluetooth Thermal Label Printer

83 views Asked by At

I want to make an application without interaction that only accepts parameters allowing to print labels on the LW-600P device, now I can scan the device and it is connected, but when it prints, nothing happens, I use this https://github .com/januslo/react-native-bluetooth-escpos-printer

ive tried this code :


`import React from 'react';
import { Button, StyleSheet, Text, View } from 'react-native';
import { BluetoothEscposPrinter, BluetoothTscPrinter } from 'react-native-bluetooth-escpos-printer';
import { hsdLogo } from './dummy-logo';

let options = {
    width: 12,
    height: 30,
    gap: 0,
    direction: BluetoothTscPrinter.DIRECTION.FORWARD,
    reference: [0, 0],
    tear: BluetoothTscPrinter.TEAR.ON,
    sound: 0,
    text: [{
        text: 'Ioooo',
        x: 20,
        y: 0,
        fonttype: BluetoothTscPrinter.FONTTYPE.SIMPLIFIED_CHINESE,
        rotation: BluetoothTscPrinter.ROTATION.ROTATION_0,
        xscal: BluetoothTscPrinter.FONTMUL.MUL_1,
        yscal: BluetoothTscPrinter.FONTMUL.MUL_1
    }],
}


const SamplePrint = () => {
    return (
        <View>
            <Text>Sample Print Instruction</Text>
            <View style={styles.btn}>
                <Button
                    onPress={async () => {

                    }}
                    title="Print BarCode"
                />
            </View>
            <View style={styles.btn}>
                <Button
                    onPress={async () => {
                        BluetoothTscPrinter.printLabel(options)
                    }}
                    title="Print QRCode"
                />
            </View>

            <View style={styles.btn}>
                <Button
                    onPress={async () => {
                        await BluetoothEscposPrinter.printerUnderLine(2);
                        await BluetoothEscposPrinter.printText('Prawito Hudoro\r\n', {
                            encoding: 'GBK',
                            codepage: 0,
                            widthtimes: 0,
                            heigthtimes: 0,
                            fonttype: 1,
                        });
                        await BluetoothEscposPrinter.printerUnderLine(0);
                        await BluetoothEscposPrinter.printText('\r\n\r\n\r\n', {});
                    }}
                    title="Print UnderLine"
                />
            </View>

            <View style={styles.btn}>
                <Button
                    title="Print Struk Belanja"
                    onPress={async () => {
                        let columnWidths = [8, 20, 20];
                        try {
                            await BluetoothEscposPrinter.printText('\r\n\r\n\r\n', {});
                            await BluetoothEscposPrinter.printPic(hsdLogo, { width: 250, left: 150 });
                            await BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER);
                            await BluetoothEscposPrinter.printColumn(
                                [48],
                                [BluetoothEscposPrinter.ALIGN.CENTER],
                                ['Jl. Brigjen Saptadji Hadiprawira No.93'],
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [32],
                                [BluetoothEscposPrinter.ALIGN.CENTER],
                                ['https://xfood.id'],
                                {},
                            );
                            await BluetoothEscposPrinter.printText(
                                '================================================',
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [24, 24],
                                [BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.RIGHT],
                                ['Customer', 'Prawito Hudoro'],
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [24, 24],
                                [BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.RIGHT],
                                ['Packaging', 'Iya'],
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [24, 24],
                                [BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.RIGHT],
                                ['Delivery', 'Ambil Sendiri'],
                                {},
                            );
                            await BluetoothEscposPrinter.printText(
                                '================================================',
                                {},
                            );
                            await BluetoothEscposPrinter.printText('Products\r\n', { widthtimes: 1 });
                            await BluetoothEscposPrinter.printText(
                                '================================================',
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                columnWidths,
                                [
                                    BluetoothEscposPrinter.ALIGN.LEFT,
                                    BluetoothEscposPrinter.ALIGN.LEFT,
                                    BluetoothEscposPrinter.ALIGN.RIGHT,
                                ],
                                ['1x', 'Cumi-Cumi', 'Rp.200.000'],
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                columnWidths,
                                [
                                    BluetoothEscposPrinter.ALIGN.LEFT,
                                    BluetoothEscposPrinter.ALIGN.LEFT,
                                    BluetoothEscposPrinter.ALIGN.RIGHT,
                                ],
                                ['1x', 'Tongkol Kering', 'Rp.300.000'],
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                columnWidths,
                                [
                                    BluetoothEscposPrinter.ALIGN.LEFT,
                                    BluetoothEscposPrinter.ALIGN.LEFT,
                                    BluetoothEscposPrinter.ALIGN.RIGHT,
                                ],
                                ['1x', 'Ikan Tuna', 'Rp.400.000'],
                                {},
                            );
                            await BluetoothEscposPrinter.printText(
                                '================================================',
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [24, 24],
                                [BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.RIGHT],
                                ['Subtotal', 'Rp.900.000'],
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [24, 24],
                                [BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.RIGHT],
                                ['Packaging', 'Rp.6.000'],
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [24, 24],
                                [BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.RIGHT],
                                ['Delivery', 'Rp.0'],
                                {},
                            );
                            await BluetoothEscposPrinter.printText(
                                '================================================',
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [24, 24],
                                [BluetoothEscposPrinter.ALIGN.LEFT, BluetoothEscposPrinter.ALIGN.RIGHT],
                                ['Total', 'Rp.906.000'],
                                {},
                            );
                            await BluetoothEscposPrinter.printText('\r\n\r\n', {});
                            await BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER);
                            await BluetoothEscposPrinter.printQRCode(
                                'DP0837849839',
                                280,
                                BluetoothEscposPrinter.ERROR_CORRECTION.L,
                            );
                            await BluetoothEscposPrinter.printerAlign(BluetoothEscposPrinter.ALIGN.CENTER);
                            await BluetoothEscposPrinter.printColumn(
                                [48],
                                [BluetoothEscposPrinter.ALIGN.CENTER],
                                ['DP0837849839'],
                                { widthtimes: 2 },
                            );
                            await BluetoothEscposPrinter.printText(
                                '================================================',
                                {},
                            );
                            await BluetoothEscposPrinter.printColumn(
                                [48],
                                [BluetoothEscposPrinter.ALIGN.CENTER],
                                ['Sabtu, 18 Juni 2022 - 06:00 WIB'],
                                {},
                            );
                            await BluetoothEscposPrinter.printText(
                                '================================================',
                                {},
                            );
                            await BluetoothEscposPrinter.printText('\r\n\r\n\r\n', {});
                            await BluetoothEscposPrinter.printText('\r\n\r\n\r\n', {});
                        } catch (e) {
                            alert(e.message || 'ERROR');
                        }
                    }}
                />
            </View>
        </View>
    );
};

export default SamplePrint;

const styles = StyleSheet.create({
    btn: {
        marginBottom: 8,
    },
});
`

My react native ver is 73, and this is my build.gradle :

buildscript {
    repositories {
        jcenter { url "https://jcenter.bintray.com/" }
        maven {url "https://repo.spring.io/plugins-release/"}
        mavenCentral()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven {
            url 'https://maven.google.com'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.4'
    }
}

apply plugin: 'com.android.library'

android {
    compileSdkVersion 34
    buildToolsVersion "28.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    lintOptions {
        abortOnError false
    }
    sourceSets {
        main {
            aidl.srcDirs = ['src/main/java']
        }
    }
}

repositories {
    jcenter { url "https://jcenter.bintray.com/" }
    maven {url "https://repo.spring.io/plugins-release/"}
    mavenCentral()
    maven {
        // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
        url "$rootDir/../node_modules/react-native/android"
    }
    maven {
        url 'https://maven.google.com'
    }
}

dependencies {
    implementation "androidx.core:core-ktx:+"
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.facebook.react:react-native:+'  // From node_modules
    implementation group: 'com.android.support', name: 'support-v4', version: '27.0.0'
    implementation "com.google.zxing:core:3.3.0"
}
0

There are 0 answers