I'm setting up a star TSP 100III with RN 0.61 through Bluetooth.
Every time I start to print the connection is really slow and most of the times I end up with this error:
Is there anyone with such experience in the past? How did you solve or can you suggest any workaround here?
I'll leave my code below so you can see what I'm doing. I'm trying to follow what there is on the documentation but I might missed something there.
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, ActivityIndicator, Button } from 'react-native';
import {StarPRNT} from 'react-native-star-prnt';
const EMULATION = 'StarGraphic';
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
printer: {},
isLoading: false,
isConnected: false
};
}
portDiscovery = async () => {
this.setState({isLoading: true})
try {
const printers = await StarPRNT.portDiscovery('All');
printers.forEach(p =>{
if (p.macAddress === "00:11:62:17:11:CB"){
this.connect(p)
return
}
})
} catch (e) {
console.error(e);
}
}
connect = async(printer)=> {
let isConnect = false;
try {
isConnect = await StarPRNT.connect(printer.portName, EMULATION, true);
console.log('connect success',isConnect); // Printer Connected!
this.setState({
isLoading: false,
printer
})
} catch (e) {
console.log('connection error',e);
}
}
handlePrint = async () => {
try {
let status = await StarPRNT.checkStatus(this.state.printer.portName,EMULATION);
console.log("status",status);
if(!status.offline){
console.log("starting...");
let commands = [];
commands.push({append:
"Star Clothing Boutique\n" +
"123 Star Road\n" +
"City, State 12345\n" +
"\n"});
commands.push({appendCutPaper:StarPRNT.CutPaperAction.PartialCutWithFeed});
var rslt = await StarPRNT.print(EMULATION, commands, this.state.printer.portName);
console.log(rslt); // Success!
}
} catch (e) {
console.log(1,e);
}
};
render() {
console.log(this.state.isLoading)
return (
<View style={styles.container}>
<Text style={styles.welcome}>Connected: {this.state.printer.modelName}</Text>
{this.state.isLoading ? (<ActivityIndicator animating={true}/>) : <Button onPress={this.portDiscovery} title="Press here" />}
{!this.state.isLoading && <Button onPress={this.handlePrint} title="Print" />}
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
});