开发者

How to send ctrl+z

How do I convert ctrl+z to a string?

I am sending this as an AT COMMAND to an attached device to this computer.

Basically, I just to put some chars in a string and ctrl+z in that string as well.开发者_如何学运维


You can embed any Unicode character with the \u escape:

"this ends with ctrl-z \u001A"


Try following will work for you

serialPort1.Write("Test message from coded program" + (char)26);

also try may work for you

serialPort1.Write("Test message from coded program");
   SendKeys.Send("^(z)");

also check : 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);


It's clear from other responses that Ctrl+Z has ASCII code 26; in general Ctrl+[letter] combinations have ASCII code equal to 1+[letter]-'A' i.e. Ctrl+A has ASCII code 1 (\x01 or \u0001), Ctrl+B has ASCII code 2, etc.


When sending characters to a device, translation from the internal string representation is needed. This is known as Encoding - an encoder translates the string into a byte array.

Consulting the Unicode Character Name Index, we find the SUBSTITUTE - 0x001A character in the C0 Controls and Basic Latin (ASCII Punctuation) section. To add a CTRL-Z to an internal C# string, add a unicode character escape sequence (\u001a) code.

String ctrlz = "\u001a";
String atcmd = "AT C5\u001a";

Any encoding used for translation before output to the device (for example output using StringWriter), will translate this to ASCII Ctrl-Z.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜