Angular 蓝牙串行写入在Ionic-v4中不工作
我正在开发一个蓝牙串行插件。使用这个插件,我可以检测设备并连接(配对)它们,但在连接设备后,我试图发送一条消息,但它不起作用。我已经连接(配对),但每当我尝试使用write方法时,就会显示Angular 蓝牙串行写入在Ionic-v4中不工作,angular,ionic-framework,bluetooth,ionic4,Angular,Ionic Framework,Bluetooth,Ionic4,我正在开发一个蓝牙串行插件。使用这个插件,我可以检测设备并连接(配对)它们,但在连接设备后,我试图发送一条消息,但它不起作用。我已经连接(配对),但每当我尝试使用write方法时,就会显示无法连接。此处是git回购的链接: searchBluetooth(){ this.bluetoothSerial.discoverUnpaired()。然后(响应=>{ log(JSON.stringify(response)); }).catch((错误)=>{ log(JSON.stringify(err
无法连接
。此处是git回购的链接:
searchBluetooth(){
this.bluetoothSerial.discoverUnpaired()。然后(响应=>{
log(JSON.stringify(response));
}).catch((错误)=>{
log(JSON.stringify(error));
}
}
设备连接(id:字符串){
this.bluetoothSerial.connect(id).subscribe((res)=>{
log(JSON.stringify(res));
}),(错误:任意)=>{
log(JSON.stringify(error));
}
}
设备连接(){
此.bluetoothSerial.subscribe('\n').subscribe(成功=>{
警报(“成功连接”+JSON.stringify(成功));
},错误=>{
警报(“错误”+JSON.stringify(错误));
});
}
sendMessage():可观察{
返回可观察的。创建(观察者=>{
this.bluetoothSerial.isConnected()。然后((isConnected)=>{
this.reader=from(this.bluetoothSerial.write(“你好,世界”)).pipe(mergeMap(()=>{
返回此.bluetoothSerial.subscribeRawData();
})).pipe(合并映射(()=>{
返回此.bluetoothSerial.readUntil('\n');//{
下一步(数据);
});
},未连接=>{
observer.next('BLUETOOTH.NOT_CONNECTED');
observer.complete();
});
});
}
这是示例的一小部分,在上面的链接中,他解释得比这个好得多。
请帮助…您可以从中下载提供商文件夹 示例可以在pages/home.ts上显示(它构建在v3上) 您应该更改一些代码,例如:
主页.ts上
:
等待。打印机。连接蓝牙(devicemac)。订阅(…
它将在您使用Enter后打印 调用Enter有两种方法相同(
\n
或
不能在escpos打印机上使用)
“\x0A”
请分享所有相关代码和步骤,以在问题本身中重现该问题。指向外部网站的链接是一个很好的补充,但链接往往会随着时间的推移而消失,而这个问题对未来的读者来说将是无用的。问题已更新,请立即检查:)
searchBluetooth(){
this.bluetoothSerial.discoverUnpaired().then(response => {
console.log(JSON.stringify(response));
}).catch((error) => {
console.log(JSON.stringify(error));
}
}
deviceConnection(id: string) {
this.bluetoothSerial.connect(id).subscribe((res) => {
console.log(JSON.stringify(res));
}), (error: any) => {
console.log(JSON.stringify(error));
}
}
deviceConnected() {
this.bluetoothSerial.subscribe('\n').subscribe(success => {
alert("Connected Successfullly" + JSON.stringify(success));
}, error => {
alert("error" + JSON.stringify(error));
});
}
sendMessage(): Observable<any> {
return Observable.create(observer => {
this.bluetoothSerial.isConnected().then((isConnected) => {
this.reader = from(this.bluetoothSerial.write("hello, world")).pipe(mergeMap(() => {
return this.bluetoothSerial.subscribeRawData();
})).pipe(mergeMap(() => {
return this.bluetoothSerial.readUntil('\n'); // <= delimitador
}));
this.reader.subscribe(data => {
observer.next(data);
});
}, notConected => {
observer.next('BLUETOOTH.NOT_CONNECTED');
observer.complete();
});
});
}
import { PrinterProvider } from './../../providers/printer/printer';
import { commands } from './../../providers/printer/printer-commands';