难以通过 Web 蓝牙连接热敏打印机 [英] Difficult To Connect Thermal Printer via Web Bluetooth

查看:127
本文介绍了难以通过 Web 蓝牙连接热敏打印机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我正在开发能够连接热敏打印机的网络.我正在使用 angular 框架,并且使用库 ng-thermal-printer 成功地将热敏打印机与 USB 连接.但我希望我的网络也能够通过网络蓝牙连接热敏打印机,即 BLE(低功耗蓝牙).据我所知,BLE 有 GATT 方面的规范,里面有服务和特性.

Right now I am developing web which has ability to connect thermal printer. I am using angular framework, and I successfully connect the thermal printer with USB using library ng-thermal-printer. But I want to my web also being able to connect thermal printer via web bluetooth which is BLE (Bluetooth Low Energy). As far as I know, BLE has specification in term of GATT and has services and characteristics in it.

到目前为止我所做的进展,我可以在服务和特性中连接并向热敏打印机设备发送一个值,让我们说带有 UUID AS 的服务和带有 UUID AC 的特性,在应用程序的帮助下使用我的安卓手机名为 nRF Connect.Targeting Service AS并以特征AC发送十六进制值使我成功地在热敏纸上打印了一些东西.

The progress I did so far, I can connect and send a value to the thermal printer device in a Service and a Characteristic, let's say Service with UUID AS and Characteristics with UUID AC, using my android phone with the help of application named nRF Connect. Targeting Service AS and send hexadecimal value at charateristic AC make me successfully print something on the thermal paper.

但是有一个问题.在了解正确的服务和特点后.我在我的项目中实现了它.但是,我的 chrome 浏览器控制台显示错误:

But there is a problem. After knowing the right service and characteristic. I implemented it in my project. But, my chrome browser console showed error:

  1. Origin 不允许访问任何服务......它告诉我在 requestiDevice() 时添加 optionalServices
  2. 在属性 optionalServices 中添加 Service AS 后,控制台显示错误 DOMException: Connection failed for unknown reason.chrome PC 和 chrome android 中均显示错误.

注意:

  • 我在 chrome 上启用了实验性网络平台功能
  • 我已在 chrome 上为 Web 蓝牙启用了使用新的权限后端
  • 我已为从本地主机加载的资源启用允许无效证书.铬
  • 我已启用在 chrome 上启用新的 USB 后端
  • 我使用过 https.

补充问题.应用程序 nRF Connect 使用的蓝牙连接与 BLE 不同吗?如果是,为什么显示服务和特征?

Additional question. is bluetooth connection that application nRF Connect used different from BLE? if so, why it displays services and characteristics?

推荐答案

我已经解决了这个问题.

I have fixed this problem.

我使用了 2 台设备,我的电脑和我的安卓手机.实际上,我电脑的蓝牙不支持 BLE.这就是为什么我一直在努力调试的原因,因为我的桌面版 chrome 在尝试连接我的热敏打印机后一直没有响应.

There are 2 devices that I use, my pc and my android phone. Actually, my PC's Bluetooth does not support BLE. This is why I keep struggling to debug as my chrome for desktop keeps being not responding after trying to connect my thermal printer.

基本上,出现错误号 2 是因为我发送了一个编码字符串值,而不是 UInt8Array 值.

Basically, error number 2 appears because I sent an encoded string value, not a UInt8Array value.

最终,我使用了 2 个 Web API.web 蓝牙 API 用于将我的 PWA 从移动设备连接到我的热敏打印机,而 web 串行 API 用于将我的 PWA 从桌面连接到我的热敏打印机.ng-thermal-printer 库非常适合我的项目.我只需要扩展驱动程序.

Eventually, I use 2 web APIs. web Bluetooth API for connecting my PWA to my thermal printer from mobile and web Serial API for connecting my PWA to my thermal printer from the desktop. The library, ng-thermal-printer, is good for my project. I just need to extend the driver.

这篇关于难以通过 Web 蓝牙连接热敏打印机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆