question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bluetooth printer just prints once, stops printing, and then prints duplicates

See original GitHub issue

Prerequisites

  • [X ] I am running the latest version
  • [X ] I checked the documentation and found no answer
  • [X ] I checked to make sure that this issue has not already been filed

Expected Behavior

Print each time the button is pressed

Current Behavior

The first time app sends print command, it prints. The second time (without any change), doesn’t do anything. The next time, it prints duplicates (from the second and third time).

Steps to Reproduce

  1. Just call the method multiple times.

Context

  • Library version: 1.1.0
  • Platform: Android.

As you can see, after scanning and connecting to the device, the print command is sent. After printing, I cancel the connection and then destroy the manager object in order to restart the object and be able to print again.

But this doesn’t happen until the third time, when it prints duplicates. It does not show errors.

Maybe I got something wrong and I can’t see it. Some help will be appreciated.

export default class BluetoothSerial extends Component {
    constructor() {
        super()
        this.state = {info: "", values: {}}
    }

    info(message) {
        this.setState({info: message})
    }

   error(message) {
        this.setState({info: "ERROR: " + message})
    }

async scanAndConnect() {
        this.manager = new BleManager()
        this.manager.startDeviceScan(["000018f0-0000-1000-8000-00805f9b34fb"],
            null, async (error, device) => {
            this.info("Scanning...");
            console.log(device.name); //printer name

            if (error) {
                this.error(error.message);
                return
            }

            if (device.name === 'RG-MDP58B') {
                this.info("Connected to printer");
                this.manager.stopDeviceScan();

                await this.manager.connectToDevice(device.id)
                    .then(async (device) => {
                        await this.manager.discoverAllServicesAndCharacteristicsForDevice(device.id)
                        console.log('device id ', device.id)

                        await this.manager.writeCharacteristicWithoutResponseForDevice(
                             device.id,
                            "000018f0-0000-1000-8000-00805f9b34fb",
                            '00002af1-0000-1000-8000-00805f9b34fb', 
                            'cHJpbnRlciBjb25uZWN0ZWQ=')
                            .then((characteristic) => {
                                console.log('print value', characteristic.value)
                                this.info(characteristic.value);
                                this.manager.cancelDeviceConnection(device.id).then( () => {
                                    this.manager.destroy()
                                });
                            }).catch(err => console.log(err))
                    })
                    .catch((error) => {
                        this.error(error.message)
                    })
            }
        });
    }

    render() {
        return (
            <View>
                <Button title="Print" onPress={() => this.scanAndConnect()} />
                <Text>{this.state.info}</Text>
            </View>
        )
    }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9

github_iconTop GitHub Comments

1reaction
pdlm95commented, Dec 7, 2020

@mayniii This is how I made it. I provide the text that I want to print in an array, where each line I wish to print its an array item.

import { Buffer } from 'buffer';

const SERVICE_UUID = '000018f0-0000-1000-8000-00805f9b34fb';    //primary service (printers)
const CHAR_UUID = '00002af1-0000-1000-8000-00805f9b34fb';       //characteristic (write)

async print(text: array){
    await this.scanAndConnect().then(async (res: any) => {
            for (let item of text) {
                let encryptedCredentials = new Buffer(item).toString("base64");

                promises.push(res.Device.writeCharacteristicWithResponseForService(
                    SERVICE_UUID, CHAR_UUID, encryptedCredentials));
            }
            await Promise.all(promises).then(() => {
                this.manager.destroy()
            })
        }).catch(err => {return});
}
0reactions
AyishmAzeemcommented, Jan 18, 2022

@pdlm95 can you guide me about receipt printing?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bluetooth printer just prints once, stops printing, and then ...
Bluetooth printer just prints once, stops printing, and then ... The next time, it prints duplicates (from the second and third time).
Read more >
13 Common Printer Problems and How to Fix Them
Turn on your printer using the power button, then turn on your computer again. Restart the print spooler service. Print your document.
Read more >
Fix printer connection and printing problems in Windows
Fix printer connection and printing problems in Windows · Step 1. Unplug and restart your printer · Step 2. Check cables or wireless...
Read more >
Epson Printer Not Printing [SOLVED] - Driver Easy
Their Epson printer isn't responding to their command when they're trying to print something with it. This is a frustrating issue.
Read more >
Printer stops halfway through job and then an error message
Try printing the document - just that one "problem" page (if you know the page number). Convert to PDF > Open in Adobe...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found