【发布时间】:2016-07-18 23:28:20
【问题描述】:
我尝试了以下方法: (这个“whatever”是在向端口发送 AT+STGR=3,1 后要求输入的 4 位密码)
1. this.port.WriteLine("whatever\0x1A");
2. this.port.WriteLine("whatever"+ char.ConvertFromUtf32(26));
3. this.port.WriteLine("whatever\u0001");
4. this.port.WriteLine("whatever"+(char)26);
5. this.port.WriteLine("whatever");
SendKeys.Send("^(z)");
6. this.port.WriteLine("whatever");
this.port.Write(new byte[] { 0x1A }, 0, 1);
7. this.port.WriteLine("whatever");
this.port.Write(new byte[] { 0x26}, 0, 1);
它们都不起作用,但是当使用 putty 并输入代码后跟 ctrl+z 键时,一切正常,所以谁能告诉我 putty 是如何将这个 ctrl+z 发送到串行端口的?或者如果可能的话在c#中解决这个问题? 每次我尝试上面给出的 c# 代码时,调制解调器的回复是:
+CME ERROR: 100
串口初始化:
port.PortName = "COM3";
port.BaudRate = 115200;
port.DataBits = 8;
port.StopBits = StopBits.One;
port.Parity = Parity.None;
port.ReadTimeout = 300;
port.WriteTimeout = 300;
port.Encoding = Encoding.GetEncoding("iso-8859-1");
port.DataReceived += new SerialDataReceivedEventHandler(this.port_DataReceived);
port.Open();
port.DtrEnable = true;
port.RtsEnable = true;
【问题讨论】:
-
在这里阅读回复/回答stackoverflow.com/questions/4862684/…
-
@MethodMan 我已经尝试过 (char)26,它应该发送相当于发送 ctrl+z 的 ascii。但正如我提到的,它没有成功。或者你认为这不是发送它的方式?如果有,请写出正确的发送方式吗?
-
使用写入字节 0x26。
-
@jdweng 能否请您写下代码作为答案?
-
试试这个:this.port.Write(new byte[] { 0x1A }, 0, 1);
标签: c# serial-port gsm