Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

receive events about printer status #19

Closed
NqCompiler opened this issue Sep 13, 2021 · 3 comments
Closed

receive events about printer status #19

NqCompiler opened this issue Sep 13, 2021 · 3 comments

Comments

@NqCompiler
Copy link

NqCompiler commented Sep 13, 2021

Hey,

Is it possible to get printer status from connected devices?

For example if paper is empty or the connection is lost

Keep up the great work!

@NqCompiler NqCompiler changed the title receive Events from Printer Status receive events about printer status Sep 13, 2021
@tr3v3r
Copy link
Owner

tr3v3r commented Sep 13, 2021

@NqCompiler hi! Sure. Please take a look at startMonitorPrinter. I suppose it returns all data you’ve mentioned.

moreover after every print - promise with corresponding data will be returned as well.

Here the code snippet how to use it ( from example folder)

React.useEffect(() => {
    EscPosPrinter.addPrinterStatusListener((status) => {
      console.log('current printer status:', status);
    });
  }, []);

..

Button
        title="Start monitor printer status"
        disabled={!printer}
        color={!printer ? 'gray' : 'blue'}
        onPress={async () => {
          if (printer) {
            if (!init) {
              await EscPosPrinter.init({
                target: printer.target,
                seriesName: getPrinterSeriesByName(printer.name),
              });
              setInit(true);
            }

            const status = await EscPosPrinter.startMonitorPrinter();

            console.log('Printer status:', status);
          }
        }}
      />
      ```

@NqCompiler
Copy link
Author

I had so many tabs open and was looking at the examples from your fork from react-native-thermal-receipt-printer and somehow ended up creating the issue at the right place.

Thanks for the fast response and help :)

@Rehankhalil462
Copy link

@tr3v3r @NqCompiler when device is connected using instantiate method, printing is working fine but this startsMonitorPrinter() is showing
DISCONNECT OFFLINE UNKNOWN for

 EscPosPrinter.addPrinterStatusListener((status) => {

      console.log(status.connection, status.online, status.paper); // will be executed every 5 sec
    });

What is the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants