At 拨号
SerialPort ss_port = "com10";
ss_port.Handshake = Handshake.RequestToSend;
ss_port.BaudRate = 9600;
ss_port.Parity = Parity.None;
ss_port.DataBits = 8;
ss_port.StopBits = StopBits.One;
format = "11888 7000/1 3000/1 3000/1 3000/{0} 14000/1 3000/{1}";
TelHelp.Dial(ss_port, string.Format(format, accounts, cardpwd));
public static string Dial(SerialPort port, string number)
{
string result = "";
string[] keys = number.Trim().Split(' ');
if (keys[0] == "")
{
throw new Exception("参数不正确");
}
else
{
try
{
port.Open();
Console.WriteLine(keys[0]);
port.Write(string.Format("ATD{0};\r", keys[0]));
#region 循环拨号
for (int i = 1; i < keys.Length; i++)
{
string[] vts = keys[i].Split('/');
if (vts.Length != 2)//
{
break;
}
if (vts[1].Length > 1)//如果要拨的号码大于一个字符串
{
string vtskey = vts[1];
Console.WriteLine("停顿" + vts[0]);
Thread.Sleep(Convert.ToInt32(vts[0]));
string svts = "";
for (int j = 0; j < vtskey.Length; j++)
{
svts = string.Format("AT+VTS={0}\r", vtskey[j]);
Console.WriteLine(svts);
port.Write(svts);
Thread.Sleep(400);
/* if (j == 0)
svts = string.Format("AT+VTS={0};", vtskey[j]);
else if (j < vtskey.Length - 1)
svts += string.Format("+VTS={0};", vtskey[j]);
else
svts += string.Format("+VTS={0};\r", vtskey[j]);*/
}
if (!GetState(port))
{
throw new Exception("拨打中出错");
}
// Console.WriteLine(svts);
// port.Write(svts);
}
else //单个字符直接拨打
{
Console.WriteLine("停顿" + vts[0]);
Thread.Sleep(Convert.ToInt32(vts[0]));
port.Write(string.Format("AT+VTS={0}\r", vts[1]));
Console.WriteLine(vts[1]);
if (!GetState(port))
{
throw new Exception("拨打中出错");
}
}
}
Thread.Sleep(3000);
#endregion 结束拨号
//拨号完成后等待20秒
Console.WriteLine("停顿20000毫秒");
Thread.Sleep(20000);
result = "dialed";
port.Write("ATH\r");
Thread.Sleep(1000);
port.Close();
}
catch
{
result = "dialing";
Console.WriteLine("拨号出错" + port.PortName);
try
{
port.Close();
}
catch
{
Console.WriteLine("关闭端口出错" + port.PortName);
}
}
}
return result;
}