使用Chrome序列号清除极点显示文本 [英] Clear Pole Display text using chrome serial
问题描述
我创建了一个chrome应用程序,该应用程序通过串行端口连接到Pole Display,我已经成功写入了它,但是每次发送一条消息时,它都将它与上一个连接起来,我找不到方法每次发送新消息时都要清除屏幕!
I have created a chrome application to connect to a Pole Display through serial port, I have succeeded with writing to it, but every time I send a message, it concatenates it with the previous one, I can't find a way to clear the screen each time I send a new message !
这是我的代码:
var connectionId = -1;
openPort("COM3");
function openPort(port){
var onOpen = function(connectionInfo) {
if (!connectionInfo || connectionInfo.connectionId == -1) {
return;
}
connectionId = connectionInfo.connectionId;
}
chrome.serial.connect(port, {bitrate: 9600}, onOpen);
}
function closePort() {
if (connectionId == -1) {
return;
}
var onDisconnect = function(connectionInfo) {
connectionId = -1;
}
chrome.serial.disconnect(connectionId, onDisconnect);
}
function sendData(str){
chrome.serial.flush(connectionId, function(){});
chrome.serial.send(connectionId, str2ab(str), function(){});
}
function str2ab(str) {
var buf = new ArrayBuffer(str.length);
var bufView = new Uint8Array(buf);
for (var i = 0; i < str.length; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
sendData("dsadsads");
推荐答案
您应该查看极点显示手册.
You should be looking into your Pole Display manual.
根据我的经验,您需要发送一个特殊命令来清除显示和/或在开始时重新放置插入标记.
From my experience working with one, you need to send a special command to clear the display and / or reposition the caret at the beginning.
您为显示模型命名,然后搜索"BIRCH DSP-800手册",该链接将首先链接到
You named your display model, and a search for "BIRCH DSP-800 manual" gives first link to this document that contains all the command codes in section 4.1.7.
要覆盖字符串,您只需要发送40个字符即可翻转"旧数据. 顺便说一下,这是一种通用的解决方案:仅以等于显示大小的块形式编写文本.根据需要使用空格填充.
To overwrite a string, you just need to send exactly 40 characters that will "roll over" the old data. This is a universal solution by the way: only write text in chunks equal to display size. Pad with spaces as needed.
您还可以通过发送与命令相对应的字符串来执行命令.让我们以清除范围"命令为例.
You can also execute commands by sending a string of characters corresponding to a command. Let's do it with the example of "clear range" command.
清除范围从1到40的位置并将光标移到1的位置"
"Clear range from 1 position to 40 position and move cursor to 1 position"
十六进制字符串为04 01 43 n m 17
,请注意:m和n在[0x31; 0x58]范围内,因此位置1将为n = 0x31,位置40将为(十六进制算术!)m = 0x31 + 39 = 49 + 39 = 88 = 0x58(不足为奇).因此,正确的命令(十六进制编码)是04 01 43 31 58 17
.
Hex string is 04 01 43 n m 17
, take note: m and n are in range [0x31;0x58], so position 1 would be n = 0x31 and position 40 would be (hex arithmetic!) m = 0x31 + 39 = 49 + 39 = 88 = 0x58 (no surprise). Therefore, the correct command (hex-encoded) is 04 01 43 31 58 17
.
对应的字符串为String.fromCharCode(0x04, 0x01, 0x43, 0x31, 0x58, 0x17)
,您将其作为文本发送,就可以了.
The corresponding string would be String.fromCharCode(0x04, 0x01, 0x43, 0x31, 0x58, 0x17)
, you send it as text and you're done.
您可以转换其他类似的命令并完全控制杆的显示.
You can convert other commands like that and control your pole display fully.
这篇关于使用Chrome序列号清除极点显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!