捣鼓了天了2 .net 2.0 的SerialPort 控件测试Modem AT 拨号指令,终于拨通了....
代码如下,一个窗口有来输入AT 指令,先要安置好Modem我用的是KN-JT560(金浪的外置猫)配置好驱动
另外来电显示要电信那边开通,Modem也分为支持来电显示与不支持来电显示2中.
开始输入ATDxxxxx (xxx为电话号码)怎么也不行,找了很多资料,KN-JT560的生产厂家电话也打过,要了分资料,发现上面写的拨好指令也是ATDxxxxx ,多要崩溃了....
后来(恩恩)设置了下 serialPort 的DtrEnable 属性为true (这个表示DTR,此针脚由计算机控制,用以通知Modem可以进行传输.高位表示计算机已经准备就绪)就可以拨通了...!
另外来电显示要电信那边开通,Modem也分为支持来电显示与不支持来电显示2中.
开始输入ATDxxxxx (xxx为电话号码)怎么也不行,找了很多资料,KN-JT560的生产厂家电话也打过,要了分资料,发现上面写的拨好指令也是ATDxxxxx ,多要崩溃了....
后来(恩恩)设置了下 serialPort 的DtrEnable 属性为true (这个表示DTR,此针脚由计算机控制,用以通知Modem可以进行传输.高位表示计算机已经准备就绪)就可以拨通了...!
delegate void del_ShowMsg(string msg);
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
Invoke(new del_ShowMsg(ShowMsg), serialPort1.ReadLine());
}
private void ShowMsg(string msg)
{
textBox1.Text = msg + Environment.NewLine+ textBox1.Text ;
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Close();
label1.Text = serialPort1.IsOpen.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.NewLine =Environment.NewLine;
serialPort1.Open();
serialPort1.WriteLine(textBox2.Text.Trim());
//serialPort1.WriteLine("at+vcid=1");
label1.Text = serialPort1.IsOpen.ToString();
button2.Enabled = false;
}
private void serialPort1_PinChanged(object sender, System.IO.Ports.SerialPinChangedEventArgs e)
{
//Invoke(new del_ShowMsg(ShowMsg), e.EventType.ToString());
}
private void serialPort1_ErrorReceived(object sender, System.IO.Ports.SerialErrorReceivedEventArgs e)
{
//Invoke(new del_ShowMsg(ShowMsg), e.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
serialPort1.WriteLine(textBox2.Text.Trim());
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
Invoke(new del_ShowMsg(ShowMsg), serialPort1.ReadLine());
}
private void ShowMsg(string msg)
{
textBox1.Text = msg + Environment.NewLine+ textBox1.Text ;
}
private void button1_Click(object sender, EventArgs e)
{
serialPort1.Close();
label1.Text = serialPort1.IsOpen.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.NewLine =Environment.NewLine;
serialPort1.Open();
serialPort1.WriteLine(textBox2.Text.Trim());
//serialPort1.WriteLine("at+vcid=1");
label1.Text = serialPort1.IsOpen.ToString();
button2.Enabled = false;
}
private void serialPort1_PinChanged(object sender, System.IO.Ports.SerialPinChangedEventArgs e)
{
//Invoke(new del_ShowMsg(ShowMsg), e.EventType.ToString());
}
private void serialPort1_ErrorReceived(object sender, System.IO.Ports.SerialErrorReceivedEventArgs e)
{
//Invoke(new del_ShowMsg(ShowMsg), e.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
serialPort1.WriteLine(textBox2.Text.Trim());
}
}