Javascript Chrome应用程序,如何向Datecs DP05BT财政打印机发送命令?
我正在尝试制作一个chrome应用程序,可以向Datecs DP05BT财政打印机发送命令 我设法与财政打印机建立了连接,但我不知道如何使用Javascript Chrome应用程序,如何向Datecs DP05BT财政打印机发送命令?,javascript,google-chrome-app,fiscal,Javascript,Google Chrome App,Fiscal,我正在尝试制作一个chrome应用程序,可以向Datecs DP05BT财政打印机发送命令 我设法与财政打印机建立了连接,但我不知道如何使用chrome.bluetooth.send向设备发送命令(例如) 编辑1:我设法用chrome.bluetooth.send发送了一个字符串,使用chrome开发者提供的字符串到数组缓冲区转换器发送,但财政打印机什么也不做。我设法找到了一个android应用程序,可以向财政打印机发送命令 我的问题是如何在我的应用程序中实现JavaScript?或者一个SDK
chrome.bluetooth.send
向设备发送命令(例如
)
编辑1:我设法用chrome.bluetooth.send发送了一个字符串,使用chrome开发者提供的字符串到数组缓冲区转换器发送,但财政打印机什么也不做。我设法找到了一个android应用程序,可以向财政打印机发送命令
我的问题是如何在我的应用程序中实现JavaScript?或者一个SDK,它可以管理字符串到数据.readable.by.fiscal.printer
连接
编辑2:我设法找到了一个SDK与财政打印机通信,问题是,它是android的。我可以将其包含到我的应用程序中吗
编辑3:财务打印机为Datecs DP05BT
function ConnectToService(device, uuid, container) {
chrome.bluetoothSocket.create({}, function (info) {
if (chrome.runtime.lastError) {
log("Error creating socket: " + chrome.runtime.lastError.message);
return;
}
log("Socket OK!");
container.socketId = info.socketId;
chrome.bluetoothSocket.onReceive.addListener(function (info) {
log("Data received on socket " + info.socketId + ", length=" + info.data.byteLength);
});
chrome.bluetoothSocket.onReceiveError.addListener(function (info) {
log("Error receiving data on socket " + info.socketId + ", error code=" + info.error + ", message=" + info.errorMessage);
chrome.bluetoothSocket.close(info.socketId, function () {
log("socket closed");
container.socketId = -1;
});
});
chrome.bluetoothSocket.connect(info.socketId, device.address, uuid, function () {
if (chrome.runtime.lastError) {
log("Error connecting to socket: " + chrome.runtime.lastError.message);
return;
}
log("Connect OK!");
chrome.bluetoothSocket.send(info.socketId, str2ab('<44>'), function(bytes_sent){
if (chrome.runtime.lastError) {
console.log("Send failed: " + chrome.runtime.lastError.message);
} else {
console.log("Sent " + bytes_sent + " bytes")
}
});
});
});
};
function str2ab(str)
{
var buf = new ArrayBuffer(str.length*2); // 2 bytes for each char
var bufView = new Uint16Array(buf);
for (var i=0, strLen=str.length; i < strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
功能连接到服务(设备、uuid、容器){
chrome.bluetoothSocket.create({},函数(信息){
if(chrome.runtime.lastError){
日志(“创建套接字时出错:”+chrome.runtime.lastError.message);
返回;
}
日志(“套接字正常!”);
container.socketId=info.socketId;
chrome.bluetoothSocket.onReceive.addListener(函数(信息)){
日志(“在套接字“+info.socketId+”上接收的数据,长度=“+info.Data.bytellength”);
});
chrome.bluetoothSocket.onReceiveError.addListener(函数(信息)){
日志(“在套接字“+info.socketId+”上接收数据时出错,错误代码=“+info.Error+”,消息=“+info.errorMessage”);
chrome.bluetoothSocket.close(info.socketId,函数(){
日志(“插座关闭”);
container.socketId=-1;
});
});
chrome.bluetoothSocket.connect(info.socketId、device.address、uuid、function(){
if(chrome.runtime.lastError){
日志(“连接到套接字时出错:”+chrome.runtime.lastError.message);
返回;
}
日志(“连接正常!”);
chrome.bluetoothSocket.send(info.socketId,str2ab(“”),函数(bytes\u sent){
if(chrome.runtime.lastError){
log(“发送失败:+chrome.runtime.lastError.message”);
}否则{
console.log(“已发送”+字节\已发送+“字节”)
}
});
});
});
};
功能str2ab(str)
{
var buf=new ArrayBuffer(str.length*2);//每个字符2个字节
var bufView=新UINT16阵列(buf);
对于(变量i=0,strLen=str.length;i
提供当前与打印机建立连接的部分代码,以及您正在使用的SDK,并包括打印机型号。@Dayan I已使用财政打印机型号和连接代码片段进行更新!提供一些您当前拥有的与打印机建立连接的代码,以及您正在使用的SDK,并包括打印机的型号。@Dayan I已更新为财政打印机型号和连接的代码段!