infoxicator / react-native-star-prnt

React-Native bridge to communicate with Star Micronics Bluetooth/LAN Printers
MIT License
67 stars 65 forks source link

Question about error code "Fail to Open Port" #17

Closed jeremycy closed 5 years ago

jeremycy commented 5 years ago

Hi there,

Not sure what I did wrong but when I try print or connect I get failed to open port error. The printer is definitely on network and tested working with another device (not written via react native)

As far as I can tell StarPRNT.checkStatus works as I can get printer info, just not print or connect below.

Thanks in advance.

StarPRNT.print('StarGraphic', commands, printer.portName).then(()=>{
  console.log('printed');
}, err=>{
  this.setState({
    printerError: err.code
  })
});

StarPRNT.connect(printer.portName, 'StarGraphic', false).then(()=>{
  this.setState({
    connectedPrinter: printer
  });
}, err=>{
  this.setState({
    printerError: err.code
  })
})
jeremycy commented 5 years ago

User error here. Closing this issue.

jeremycy commented 5 years ago

Actually reopening to see if anyone had these two issues:

  1. Looks like I can connect fine via ios emulator, but when connecting to physical devices I still kept getting Failed to open port. For ios I launch via react-native run-ios --udid="my device udid".

  2. Whenever in emulator mode, after a hot-reload I can't seem to re-connect the printer again (Failed to open port). Disconnect won't help either. I would have to rerun react-native run-ios command to start over. Is anyone else seeing this issue?

infoxicator commented 5 years ago

Hi @jeremycy. You need to make sure your app closes the connection on pause and on close events otherwise the connection will remain open and it will block new connections. My advice is not to use the connect() function, instead, you should send the commands to the printer passing the portName every time. This will guarantee that the connection is only open while printing and then immediately close it when finished, this helps preserve the battery life of your device by not having open connections that are not used very often.

thanks

jeremycy commented 5 years ago

@infoxicator , great advice. It solved both of my problems. Apparently it's already blocked when I run on my device with connect method rather than passing port ondemand.

Thank you very much.

rootcstar commented 2 years ago

@infoxicator In my app, i let the user choose the printer model name and i give the emulation value according to that. So i have a TSP100 printer, when i try to connect that TSP100 with the emulation value of TSP650, the connection does not close. It gives me a timeout error. And also it doesn't close the connection immediately when i got that error message. So i have to wait or restart the app to try my TSP100 with a correct emulation value from the list. Is there any solution for that? Btw i am not using the connect or disconnect method. It works perfectly when i choose the right one. But when i click accidentally wrong printer. It messes up.