我打算通过Google Chrome内置的Web Serial API来解决Modbus设备的问题。我想用十六进制码对我的设备进行寻址。下面的屏幕截图证明,我的设备可以使用这样的工具成功寻址。
因此,该接口使用以下十六进制值进行寻址: 01 03 00 01 00 02 95 CB
我现在的问题是。Tutorial仅显示了如何将接口寻址为Uint8Array或Text。如何使用十六进制代码对接口进行寻址?
谢谢你的帮助
发布于 2021-11-26 08:49:55
正如https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array中指出的,Uint8Array
类型的数组表示一个由8位无符号整数组成的数组。
在JavaScript中,0x
用于指示所有后续字符应解释为十六进制(以16为基数的数字系统)。
因此,您所需要的就是:
const writer = port.writable.getWriter();
const data = new Uint8Array([0x01, 0x03, 0x00, 0x01, 0x00, 0x02, 0x95, 0xCB]);
await writer.write(data);
https://stackoverflow.com/questions/70112813
复制相似问题