【发布时间】:2011-03-03 19:59:57
【问题描述】:
如何将ctrl+z转成字符串?
我将此作为 AT 命令发送到连接到此计算机的设备。
基本上,我只是将一些字符放入字符串中,并将 ctrl+z 放入该字符串中。
【问题讨论】:
如何将ctrl+z转成字符串?
我将此作为 AT 命令发送到连接到此计算机的设备。
基本上,我只是将一些字符放入字符串中,并将 ctrl+z 放入该字符串中。
【问题讨论】:
您可以使用 \u 转义符嵌入任何 Unicode 字符:
"this ends with ctrl-z \u001A"
【讨论】:
尝试以下对你有用
serialPort1.Write("Test message from coded program" + (char)26);
也试试可能对你有用
serialPort1.Write("Test message from coded program");
SendKeys.Send("^(z)");
也检查一下:http://www.dreamincode.net/forums/topic/48708-sending-ctrl-z-through-serial/
【讨论】:
byte[] buffer = new byte[1];
buffer[0] = 26; // ^Z
modemPort.Write(buffer, offset:0, count:1);
【讨论】:
从其他响应中可以清楚地看出 Ctrl+Z 的 ASCII 码是 26;通常 Ctrl+[letter] 组合的 ASCII 码等于 1+[letter]-'A' 即 Ctrl+A 的 ASCII 码为 1(\x01 或 \u0001 ), Ctrl+B有ASCII码2等
【讨论】:
向设备发送字符时,需要从内部字符串表示进行转换。这被称为Encoding - 编码器将字符串转换为字节数组。
查阅Unicode Character Name Index,我们在C0 Controls and Basic Latin(ASCII 标点符号)部分找到了SUBSTITUTE - 0x001A 字符。
要将 CTRL-Z 添加到内部 C# 字符串,
添加unicode character escape sequence (\u001a) 代码。
String ctrlz = "\u001a";
String atcmd = "AT C5\u001a";
在输出到设备之前用于翻译的任何编码
(例如使用StringWriter 输出),会将其转换为ASCII Ctrl-Z。
【讨论】: