public void fillqueue(SmsObj sms, int Priority) { portName = sms.portName; BaudRate = sms.BaudRate; databits = sms.databits; parity = sms.parity; stopBits = sms.stopBits; ReadTimeout = sms.ReadTimeout; if (Priority == 1) { NormalPriority.Enqueue(sms); } else { HighPriority.Enqueue(sms); } //IsThreadOn = !IsThreadOn; if (!IsThreadOn) { IsThreadOn = true; Sendsms = new Thread(SendSmsThread); Sendsms.Start(); } }
//获取短信配置信息 public static SmsObj GetSMSinfo() { XmlDocument xmlDocument = GetXmlDocument(); if (xmlDocument == null) { return(null); } SmsObj sobj = new SmsObj(); try { XmlElement rootElement = xmlDocument.DocumentElement; XmlNode SMSNode = rootElement.SelectSingleNode("SMSAlarmConfig"); sobj.BaudRate = Convert.ToInt32(SMSNode.FirstChild.FirstChild.Value); sobj.databits = Convert.ToByte(SMSNode.ChildNodes[1].FirstChild.Value); sobj.stopBits = Convert.ToByte(SMSNode.ChildNodes[2].FirstChild.Value); sobj.parity = Convert.ToByte(SMSNode.ChildNodes[3].FirstChild.Value); sobj.portName = SMSNode.ChildNodes[4].FirstChild.Value; } catch (Exception) { return(null); } return(sobj); }
/// <summary> /// 发送短信 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> //private void Send(object sender, System.EventArgs e) public void Send(SmsObj smsobj) { //Debug.WriteLine("发送前时间——" + DateTime.Now.ToString()); foreach (string phoneNumber in smsobj.phoneNumbers) { //Debug.WriteLine("发送信息前时间——" + DateTime.Now.ToString()); string decodedSMS = sms.smsDecodedsms(CenterNumber, phoneNumber, smsobj.smsContent); byte[] buf = null; buf = Encoding.ASCII.GetBytes(String.Format("AT+CMGS={0}\r", sms.nLength)); while (ss_port.Read(128).Length > 0) { } ss_port.Write(buf); Thread.Sleep(5000); string response = null; response = Encoding.ASCII.GetString(ss_port.Read(128)); string SendState = ""; if (response.Length > 0 && response.EndsWith("> ")) { ss_port.Write(Encoding.ASCII.GetBytes(String.Format("{0}\x01a", decodedSMS))); SendState = "发送成功!"; } else { SendState = "发送失败"; } //Debug.WriteLine(SendState); Thread.Sleep(5000); //Debug.WriteLine("发送信息后时间——" + DateTime.Now.ToString()); } //Debug.WriteLine("发送后时间——" + DateTime.Now.ToString()); }
//修改短信配置 public static Boolean ModifySMSinfo(SmsObj smsObj_para) { XmlDocument xmlDocument = GetXmlDocument(); if (xmlDocument == null) { return(false); } try { XmlElement rootElement = xmlDocument.DocumentElement; XmlNode SMSNode = rootElement.SelectSingleNode("SMSAlarmConfig"); SMSNode.FirstChild.FirstChild.Value = (smsObj_para.BaudRate).ToString(); SMSNode.ChildNodes[1].FirstChild.Value = ((int)(smsObj_para.databits)).ToString(); SMSNode.ChildNodes[2].FirstChild.Value = ((int)(smsObj_para.stopBits)).ToString(); SMSNode.ChildNodes[3].FirstChild.Value = ((int)(smsObj_para.parity)).ToString();; SMSNode.ChildNodes[4].FirstChild.Value = smsObj_para.portName; xmlDocument.Save(GetFilePath()); } catch (Exception) { return(false); } return(true); }
//初始化相关数据结构 public static void Inition() { sobj = OperateAlarmConfigClass.GetSMSinfo(); mobj = OperateAlarmConfigClass.GetMailInfo(); cobj = OperateAlarmConfigClass.GetPhoneInfo(); LAM = OperateAlarmConfigClass.GetAlarmModes(); CallObj callObj = new CallObj(); callObj.BaudRate = 1200; callObj.DataBits = (byte)8; callObj.StopBits = (byte)1; callObj.Parity = (byte)0; callObj.PortNum = "COM1"; OperateAlarmConfigClass.ModifyPhoneInfo(callObj); SmsObj smsObj = new SmsObj(); smsObj.BaudRate = 1200; smsObj.databits = (byte)8; smsObj.stopBits = (byte)1; smsObj.parity = (byte)4; smsObj.portName = "COM6"; OperateAlarmConfigClass.ModifySMSinfo(smsObj); MailObj mailObj = new MailObj(); mailObj.From = "*****@*****.**"; mailObj.FromName = "East"; mailObj.PassWord = "******"; mailObj.Host = "192.168.1.81"; mailObj.Subject = "这是自动报警邮件"; mailObj.TimeOut = 8; OperateAlarmConfigClass.ModifyMailInfo(mailObj); }