短信猫是TC35i,串口
C# webservice代码:
[WebMethod]
public string Sendmsg(string phone, string msg, string com)
{
lock (_objLock)
{
var gm = new GsmModem();
if (gm.IsOpen)
{
TryAction(() =>
{
gm.Close();
});
}
try
{
gm.ComPort = com;
gm.BaudRate = 9600;
gm.Open();
if (!gm.IsOpen)
{
gm.Close();
return string.Format("打开设备成功,但是IsOpen是False.", string.Empty);
}
}
catch (Exception ex)
{
TryAction(() =>
{
gm.Close();
});
return string.Format("尝试打开设备失败. {0}", ex.Message);
}
System.Threading.Thread.Sleep(2000);
try
{
gm.SendMsg(phone, msg);
return string.Format("短信发送成功. {0}, {1}", phone, msg);
}
catch (Exception ex)
{
return string.Format("Failed:{0}", ex.Message);
}
finally
{
TryAction(() =>
{
gm.Close();
});
}
}
}
源码下载:http://download.csdn.net/detail/sxwhbj/8918817