【发布时间】:2015-11-16 11:09:33
【问题描述】:
我更新了这个问题并知道它工作正常..
我尝试检查我的 mavecom 调制解调器中的余额,但我的文本框中没有任何响应。它一直是空的。
这是我的代码:
private SerialPort _port;
private void simpleButton1_Click(object sender, EventArgs e)
{
_port = new SerialPort();
_port.PortName = cbPort.Text;
_port.BaudRate = 115200;
_port.Parity = Parity.None;
_port.DataBits = 8;
_port.StopBits = StopBits.One;
_port.Handshake = Handshake.RequestToSend;
port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
port.Open();
port.Write("AT+CUSD=1,\"" + txtUSSD.Text + "\",15" + "\r");
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
// read the response.
var response = ((SerialPort)sender).ReadLine();
// Need to update the txtProvider on the UI thread .
//showing result in txtOutput based on txtProvider USSD Command
this.Invoke(new Action(() => txtOutput.Text = response));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
这个解决了,可以用来查余额....
【问题讨论】:
-
写入后不要立即关闭端口。
-
在打开串口之前注册
DataReceived也是个好主意。 -
我先试试看你的建议
-
伙计们,..它仍然消失...在 txtOutput 找不到结果
-
不要在标题中添加“[已解决]”字样,这不是它的工作原理。请选择正确的答案。
标签: c# at-command ussd