star-micronics / react-native-star-io10

react-native-star-io10 is a library for supporting application development for Star Micronics devices.
Other
91 stars 55 forks source link

Cash drawer is opening constantly #95

Closed yongmin86k closed 2 months ago

yongmin86k commented 1 year ago

Description

Our customer reported the issue with the cash drawer that opens constantly.

The log for this issue shows that the printer command is sending Action.Open too many times.

We are not sure how this happened for only this specific store while there are 3000 users.

Printer commands are logged as followings:

{
    "title": "StarXpandCommand",
    "version": "1.0.0",
    "contents": [
        {
            "category": "Document",
            "contents": [
                {
                    "category": "Drawer",
                    "contents": [
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}}
                    ]
                },
                {
                    "category": "Drawer",
                    "contents": [
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        ...
                    ]
                },
                {
                    "category": "Drawer",
                    "contents": [
                        {"method": "Action.Open", "parameter": {"channel": "No.1", "on_time": 200}},
                        ...
                    ]
                }
            ]
        }
    ]
}

Your device where the bug occurs

Your printer

Your development environment

n/a

To Reproduce

Can't replicate

Expected behavior

Should create a command once for the cash drawer

Screenshots

image

Additional context

n/a

bandit-ibayashi commented 1 year ago

@yongmin86k Is it possible to share the code of the part that generates print data with StarXpandCommand.StarXpandCommandBuilder() etc.?

This json format data can be obtained by the following, but we would like to know what the part that generates it is. var commands = await builder.getCommands();

yongmin86k commented 1 year ago

The json format for the command is stated in previous comment. - https://github.com/star-micronics/react-native-star-io10/issues/95#issue-1626054286

And this is the code for opening the cash drawer. Most users don't see the issue but it only happened to 1 user and I suspect the culprit is their network speed.

// settings are configured as a user select on the discovered printer
const settings = new StarConnectionSettings()
const printer = new StarPrinter(settings)

const builder = new StarXpandCommand.StarXpandCommandBuilder()
const document = new StarXpandCommand.DocumentBuilder()
const cashDrawer = new StarXpandCommand.DrawerBuilder()
const openParameter = new StarXpandCommand.Drawer.OpenParameter()

cashDrawer.actionOpen(openParameter)
document.addDrawer(cashDrawer)
builder.addDocument(document)

try {
  const commands = await builder.getCommands()

  await printer.open()
  await printer.print(commands)
} catch {
// we capture the any errors with Sentry
} finally {
  await printer.close()
  await printer.dispose()
}
bandit-ibayashi commented 1 year ago

@yongmin86k Thank you for sharing your code to open the drawer and the information on how often this issue occurs.

I used your code to generate a command in json format but I was not able to reproduce this issue. It generated a code that opens only once. The frequency of occurrence also suggests that it is not caused by the SDK or our library, but by other factors.

{
    "title": "StarXpandCommand",
    "version": "1.0.0",
    "contents": [
        {
            "category": "Document",
            "contents": [
                {
                    "category": "Drawer",
                    "contents": [
                        {
                            "method": "Action.Open",
                            "parameter": {
                                "channel": "No.1",
                                "on_time": 200
                            }
                        }
                    ]
                }
            ]
        }
    ]
}

For reference, here is the implementation. We have applied your code to our print sample.

private _onPressPrintButton = async() => {
    const settings = new StarConnectionSettings();
    settings.interfaceType = this.state.interfaceType;
    settings.identifier = this.state.identifier;

    const printer = new StarPrinter(settings);

    const builder = new StarXpandCommand.StarXpandCommandBuilder()
    const document = new StarXpandCommand.DocumentBuilder()
    const cashDrawer = new StarXpandCommand.DrawerBuilder() 
    const openParameter = new StarXpandCommand.Drawer.OpenParameter()

    cashDrawer.actionOpen(openParameter)
    document.addDrawer(cashDrawer)
    builder.addDocument(document)

    try {
        var commands = await builder.getCommands();
        console.log(`commands¥n${commands}`);

        await printer.open();
        await printer.print(commands);

        console.log(`Success`);
    }
    catch(error) {
        console.log(`Error: ${String(error)}`);
    }
    finally {
        await printer.close();
        await printer.dispose();
    }
}