简体   繁体   English

模板文字,奇怪的 output

[英]Template literal, weird output

I'm working with some lab equipment using ASTM over TCP/IP.我正在使用基于 TCP/IP 的 ASTM 使用一些实验室设备。 Getting some weird behavior.得到一些奇怪的行为。 Using just Node and the net package.仅使用 Node 和网络 package。

socket.on('data', data => {
        let str = data.toString('ascii');
        console.log(`the string ---- ${str}`);
    if (str === ENQ) {
        socket.write(ACK);
    } else {
        console.log(str);
    }

outputs (given correct input):
E1 string ----  1H|\^&|||1^Analyzer 1^6.0|||||||P||20201216150358
E1|\^&|||1^Analyzer 1^6.0|||||||P||20201216150358

I need the stuff on the top line after the dashes, but "The" becomes E1, then E1 moves down to the next line and replaces 1H.我需要破折号后顶行的东西,但是“The”变成了 E1,然后 E1 向下移动到下一行并替换了 1H。 What's going on here?这里发生了什么? I'm hoping it just has something to do with console.log so I can still get to the results I'm looking for.我希望它与 console.log 有关,所以我仍然可以得到我正在寻找的结果。

So it looks like some of the control characters are making the output weird.所以看起来一些控制字符让 output 变得很奇怪。 Towards the end of the line, there is a CR and ETX at the end of the line followed by a checksum of the line.在行尾,行尾有一个 CR 和 ETX,后面是行的校验和。 So it seems that the carriage return is sending the cursor back to the front of the line and putting the ETX and checksum in place of "The"因此,回车似乎将 cursor 发送回行的前面,并将 ETX 和校验和代替“The”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM