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

IOS: Request to have the check in write function if the data is Buffer data #324

Open
duc-tran-epam opened this issue Jun 11, 2024 · 1 comment

Comments

@duc-tran-epam
Copy link
Contributor

Mobile Device Environment

  • Device: any
  • OS: IOS

Is your feature request related to a problem? Please describe.
Currently, the app sends Buffer data. However, the write function tries to convert it to a string, causing a failure check. As a result, the data isn't sent to the Printer device.

Describe the solution you'd like
I suggest removing the check if let sending = String(data: data, encoding: self.encoding)
or implementing another check if the data is Buffer data.

I tried to remove the condition and it's working correctly.

func write(_ data: Data) -> Bool {
    if let sending = String(data: data, encoding: self.encoding) {
        NSLog("(BluetoothDevice:writeToDevice) Writing %@ to device %@", sending, accessory.serialNumber)
        NSLog("(BluetoothDevice:writeToDevice) 2222")
        outBuffer.append(data)
        writeDataToStream((session?.outputStream)!)
    } else {
        NSLog("(BluetoothDevice:writeToDevice) Writing false")
        return false
    }

    return true
}

Additional context
Here is the buffer data we passed to write function

      const n = 42; // Feed amount
      const PRINT_AND_FEED_PAPER_COMMAND = '\x1B\x6A';

      const command = Buffer.from(PRINT_AND_FEED_PAPER_COMMAND, 'binary');
      const values = Buffer.from([n]);
      const combinedCommand = Buffer.concat([command, values]);
      await classicDevice.write(combinedCommand);
@kenjdavidson
Copy link
Owner

Feel free to open a PR, not sure what check you removed, since the "working" code you posted has the line/content that you mention you want to remove above. I'm not entirely sure why it was done that way, but it does look a little weird that I'm converting to the sending string but then never using that string.

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

2 participants