Javascript webUSB api正在工作,但接收到的数据不是';不能正确解码

Javascript webUSB api正在工作,但接收到的数据不是';不能正确解码,javascript,webusb,Javascript,Webusb,更新代码 我用这个代码来声明使用了serial-2-USB设备。它出现了,我可以查询有关它的信息,即“连接到USB2.0-Serial VID:6790 PID:29987”(来自秦恒的CH34x)。为了清楚起见,我使用了winUSB驱动程序(随zadig-2.5.exe下载,Windows 10),并卸载了原始驱动程序 我将接收到的数据作为dataview,但当我解码时,它会变得乱七八糟。我发现数组长度与我所知道的ESP8266通过串行端口发送的内容基本一致 解码数据示例:�(#���D“D�

更新代码

我用这个代码来声明使用了serial-2-USB设备。它出现了,我可以查询有关它的信息,即“连接到USB2.0-Serial VID:6790 PID:29987”(来自秦恒的CH34x)。为了清楚起见,我使用了winUSB驱动程序(随zadig-2.5.exe下载,Windows 10),并卸载了原始驱动程序

我将接收到的数据作为dataview,但当我解码时,它会变得乱七八糟。我发现数组长度与我所知道的ESP8266通过串行端口发送的内容基本一致

解码数据示例:
�(#���D“D�T�B�!七百万便士�R�N����#�m93aw9½�d-K��B��BF+3ѡ��kag1�R�#��#!!R����G�!D��A.��谛骨性关节炎��399�}��1D�#��'99�����9�����'99���'99����@@譛

我以UINT8数组的形式获取数据,但即使我尝试制作自己的解析器,最终的结果也是一样的胡言乱语。我是否需要关心USB数据,如起始位、确认位等?所有的示例代码都只是做一个文本解码器,就这样

serial.js+index.html


//https://zadig.akeo.ie/  ---对于windows,获取支持的驱动程序“winusb”
//https://www.cypress.com/file/134171/download  ---阅读USB标准
//https://cscott.net/usb_dev/data/devclass/usbcdc11.pdf ---更多
//http://www.linux-usb.org/usb.ids ---ID列表
//https://developer.mozilla.org/en-US/docs/Web/API/USBDevice ---更多信息
//主机---数据管道--->供应商/设备TX(主机)传输数据
//主机供应商/设备端点0(这是我们用来控制数据向上(从设备到主机)和向下(从主机到设备)的端点
//主人{
this.device.transferIn(this.endpointIn,64)。然后(result=>{
此.onReceive(result.data);
readLoop();
},错误=>{
此.onReceiveError(错误);
});
};
返回此.device\ux.open()
.然后(()=>{
//首先,我们填充了一些GUI内容,我们使用“设备”进行配置……其他地方的配置使用串行和端口
device.hostName=port.device\uux.productName;
device.vendorName=Object.keys(表[port.device\uu.vendorId])[0];
device.chip=表[port.device..vendorId][device.vendorName][port.device..productId];
device.serialNumber=端口.设备\序列号;
device.manufacturerName=端口.device\uu.manufacturerName;
//1:我们设置了一个配置(USB标准中的配置描述符)
if(此设备配置===null){
返回此。设备。选择配置(1);
}
})
.然后(()=>{
//2:我们为我们将使用的数据设置端点,我们只使用“批量”传输,因此我们解析它们的地址
让configInterfaces=this.device\uu.configuration.interfaces;
configInterfaces.forEach(元素=>{
element.alternates.forEach(elementalt=>{
if(elementalt.interfaceClass===0xff){
this.interfaceEnumber=element.interfaceEnumber;
elementalt.endpoints.forEach(elementendpoint=>{
//本部分以编程方式获取批量输入和输出端点
if(elementendpoint.direction==“out”&&elementendpoint.type==“bulk”){
this.endpointOut=elementendpoint.endpointNumber;
this.endpointOutPacketSize=elementendpoint.packetSize;
}
if(elementendpoint.direction===“in”&&elementendpoint.type==“bulk”){
this.endpointIn=elementendpoint.endpointNumber;
this.endpointpacketsize=elementendpoint.packetSize;
}
})
}
})
})
})
//3:我们声明此接口并选择替代接口
.then(()=>此.device_uIi.claimInterface(此.interface枚举器))
.然后(()=>this.device_u0.selectAlternateInterface(this.interfaceEnumber_0))
//4:我们根据检测到的硬件配置输入和输出传输
.然后(()=>串行[设备芯片](此))
//5:我们开始循环
.然后(()=>{
//console.log(this);
readLoop();
})
};
//断开连接后,该怎么办
serial.Port.prototype.disconnect=异步函数(){
等待串行[设备.芯片](此)。断开连接;
};
//发送数据,怎么办
serial.Port.prototype.send=函数(数据){
返回this.device_u2;transferOut(this.endpointOut_2;,data);
};
serial.controlledTransfer=异步函数(对象、方向、类型、收件人、请求、值=0、数据=new DataView(new ArrayBuffer(0))、索引=object.InterfaceEnumber\ux){
direction=direction.charAt(0.toUpperCase()+direction.slice(1);
type=type.toLowerCase();
recipient=recipient.toLowerCase();
if(data.bytellength==0&&direction==“In”){
//我们设置一个“in”需要返回多少位
//因此,在调用中设置data=0…N,否则它将默认为0
数据=0;