infoxicator / react-native-star-prnt

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

Only PartialCutWithFeed works with TSP100IIIW #28

Closed bosung90 closed 5 years ago

bosung90 commented 5 years ago

I was able to connect to the printer and send a print command.

However, every print only comes out with tiny little slip with partial cut.

async function portDiscovery() {
  try {
    let printers = await StarPRNT.portDiscovery('All')
    console.log(printers)
    if (printers && printers.length > 0) {
      await connect(printers[0].portName)
      portName = printers[0].portName
      await new Promise(r => setTimeout(r, 5000))
      let commands = []
      commands.push({ append: 'Star Clothing Boutique\n' + '123 Star Road\n' + 'City, State 12345\n' + '\n' })
      commands.push({ appendRawBytes: [0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x2e] })
      commands.push({ appendRaw: 'Star Clothing Boutique\n' + '123 Star Road\n' + 'City, State 12345\n' + '\n' })
      commands.push({ appendUnderline: 'Star Clothing Boutique\n' + '123 Star Road\n' + 'City, State 12345\n' + '\n' })
      commands.push({ appendAbsolutePosition: 40, data: 'Text with absolute position' })
      commands.push({ appendCutPaper: StarPRNT.CutPaperAction.PartialCutWithFeed })
      commands.push({ appendRaw: 'Star Clothing Boutique\n' + '123 Star Road\n' + 'City, State 12345\n' + '\n' })
      commands.push({ appendRaw: 'Star Clothing Boutique\n' + '123 Star Road\n' + 'City, State 12345\n' + '\n' })
      commands.push({ appendRaw: 'Star Clothing Boutique\n' + '123 Star Road\n' + 'City, State 12345\n' + '\n' })

      print(commands, printers[0].portName)
    }
  } catch (e) {
    console.error(e)
  }
}

this is my connect function

async function connect(portName, emulation = StarPRNT.Emulation.StarGraphic, hasBarcodeReader = false) {
  try {
    var connect = await StarPRNT.connect(portName, emulation, hasBarcodeReader)
    console.log(connect) // Printer Connected!
  } catch (e) {
    console.error(e)
  }
}

and print function

async function print(commands, portName, emulation = StarPRNT.Emulation.StarGraphic) {
  try {
    var printResult = await StarPRNT.print(emulation, commands, portName)
    console.log(printResult) // Success!
  } catch (e) {
    console.error(e)
  }
}
cstudios-slovakia commented 5 years ago

So...that is a raster printer. You need to convert your text into bitmap before you can print that out. P.S.: your print command on ios will throw an error, because you should not give the print command the portName if youre connected to it (on the other hand android requires it)

bosung90 commented 5 years ago

@cstudios-slovakia Thank you so much for your answer. I am planning to use it only on Android. I was wondering if this library is capable of converting text into bitmap without having to touch the native code. Thank you so much!!

aysfzaicmu commented 5 years ago

@bosung90 i'm in the same situation. so did you end up using a command in this package to convert to bitmap?

bosung90 commented 5 years ago

@aysfzaicmu no I haven't had a chance to get it to work yet

ararog commented 5 years ago

@bosung90 @aysfzaicmu please give a try on appendBitmapText command, this command worked for me.

lukhol commented 5 years ago

@ararog appendBitmapText works only on iOS, implementation is missing on Android

hunwalk commented 5 years ago

we have a custom fork here https://github.com/cstudios-slovakia/react-native-star-prnt You can use the appendRasterText command. This works both on android and ios, tested with actual printers

stefangeorg commented 5 years ago

anyone else getting "Fail to open Port", for the BT:TSP100. I've tried the print with portName and without parameter. Connect says it worked, check status says connected but print says Fail to open Port

let commands = [];
      commands.push({
        appendBitmapText:
          "Star Clothing Boutique\n" +
          "123 Star Road\n" +
          "City, State 12345\n" +
          "\n"
      });
      commands.push({ appendBitmap: image });
 try {
        //this.connect()

        const result = await StarPRNT.print(this.emulation, commands, this.port);
        alert('printed')
      } catch(e) {
        alert(JSON.stringify(e))
        bugsnag.notify(e)
      }
hunwalk commented 5 years ago

Make sure the printer does not have harware error. Empty paper, paper cutter misaligned. If its hardware error you should see a blinking red light, but you can listen to hardware events by attaching a listener, but for this you have to use StarPRNT.connect first, then you will be able to console log them out. But either way it should work.

stefangeorg commented 5 years ago

@HunWalk thanks for the response. printer is working fine if I use the Star Print app they supply, it prints. From the docs I don't see how one would listen to the events?

stefangeorg commented 5 years ago

@HunWalk I'm getting from status receiptPaperEmpty: true, its definitely full. and works when using their app

stefangeorg commented 5 years ago

I've gotten barcode and QR code to print, but not appendBitmap. Any idea? I've tried sending in a uri, a base64 encoded image, but no success yet.

App copy.txt

hunwalk commented 5 years ago

I commented something useful above:

we have a custom fork here https://github.com/cstudios-slovakia/react-native-star-prnt You can use the appendRasterText command. This works both on android and ios, tested with actual printers

There is no documentation, but here is a piece of code that works

makeBitmap = (base64) => {
        if (Platform.OS === 'ios') {
            return { appendBitmap: base64, diffusion: true, width: 320, bothScale: true, absolutePosition: (590-320)/2 }
        }else{
            return { 
                appendBase64Bitmap: base64.replace(/^data:image\/[a-z]+;base64,/, ""), 
                diffusion: true, 
                width: 400, 
                bothScale: true, 
                absolutePosition: (590 - 320) / 2
            }
        }

    }
stefangeorg commented 5 years ago

@HunWalk

I fixed it with:

commands.push({ appendBitmap: "file:" + image });

So now it works in my limited demo app... still no luck in the real app though.

hunwalk commented 5 years ago

@stefangeorg double check the emulation, but please try to solve it alone, use google or think before spamming comments under a github issue which was not opened for this case.

@infoxicator please close this issue, it's already going in a different direction. If you do not intend to maintain this repo please let me know.

Cheers

infoxicator commented 5 years ago

@HunWalk I can give you access to the repository and now if you want to help maintain it?

hunwalk commented 5 years ago

@infoxicator yepp, i could check the issues on this repo every week in order to patch some things up by sending a PR, but the first thing this repo really needs is some additional informations inside the docs, because people are too lazy to read the manuals of the devices. I'm gonna send a PR for this purpose. I don't really think I need access, unless you want to abandon this repo, or you really don't have time to maintain it.

infoxicator commented 5 years ago

I could do with some help specially publishing new versions to non I left the company I developed this plugin for and don’t have access to printers to test. I can add you as a contributor

hunwalk commented 5 years ago

Okay then, we have an mPop an L200 and a Paypoint for ipad device in here i can use for testing. You can reach me at gergely@cstudios.ninja for further communications