使用华为加密狗发送短信 [英] Send SMS USing huawei dongle

查看:127
本文介绍了使用华为加密狗发送短信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友



我正在尝试发送短信使用华为加密狗,现在我只能发送短信当用户从组合中选择正确的com端口号在表单加载事件中加载的框,



现在我的问题如何使组合框加载huawei加密狗连接的唯一端口号?



这个我已完成的代码



 使用系统; 
使用 System.Collections.Generic;
使用 System.Threading;
使用 System.IO.Ports;
使用 System.Windows.Forms;
使用 System.Management;
使用 System.Management.Instrumentation;

命名空间 gi
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}
SerialPort s;
private void button1_Click( object sender,EventArgs e)
{

string comport = cboPorts.Text;
GetPort(comport);
}
public void GetPort( string comport)
{
// if(this.s == null)
{
this .s = new SerialPort( );
this .s.PortName = comport;
this .s.Open();
this .s.BaudRate = 9600 ;
this .s.Parity = Parity.None;
this .s.DataBits = 8 ;
this .s.StopBits = StopBits.One;
// this.s.Handshake = Handshake.RequestToSend;
this .s.DtrEnable = true ;
.s.RtsEnable = true ;
// this.s.RtsEnable = true;
this .s.NewLine = System.Environment.NewLine;
this .s.WriteLine( AT +( char )( 13 ));
// string tt = s.ReadLine();
// if(s.ReadLine()!=AT / r / r)
{
Thread.Sleep( 2000 );
this .s.WriteLine( AT + CMGF = 1 +( char )( 13 ));
Thread.Sleep( 3000 );
this .s.WriteLine( AT + CMGS = \ + 9916518522 + \);
Thread.Sleep( 5000 );
this .s.WriteLine( > ; + le +( char )( 26 ));
this .s.Close();
MessageBox.Show( 已发送);
}
// else
// {
// MessageBox.Show(Dervice Nt);
// }
}
}
私有 void Form1_Load( object sender,EventArgs e)
{
string [] ports = SerialPort。 GetPortNames();


foreach string port in ports)
{
cboPorts.Items.Add(port);
}


}
}
}

解决方案

< blockquote>而不是选择手动使用for循环并通过发送每个com端口进行检查&如果com端口不包含加密狗,则在try catch中捕获它并且不显示消息。


Dear Friends

I am trying to send SMS Using huawei dongle, now i am able to send SMS only When User Select the correct com port number from the combo box which are loaded at the form load event,

Now My Question How Can I make the Combo box Load the only port number which huawei dongle is connected?

This My Code Which I have Done

using System;
using System.Collections.Generic;
using System.Threading;
using System.IO.Ports;
using System.Windows.Forms;
using System.Management;
using System.Management.Instrumentation;

namespace gi
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        SerialPort s;
        private void button1_Click(object sender, EventArgs e)
        {

            string comport = cboPorts.Text;
            GetPort(comport);
        }
        public void GetPort(string comport)
        {
           // if (this.s == null)
            {
                this.s = new SerialPort();
                this.s.PortName = comport;
                this.s.Open();
                this.s.BaudRate = 9600;
                this.s.Parity = Parity.None;
                this.s.DataBits = 8;
                this.s.StopBits = StopBits.One;
                //this.s.Handshake = Handshake.RequestToSend;
                this.s.DtrEnable = true;
                this.s.RtsEnable = true;
                //this.s.RtsEnable = true;
                this.s.NewLine = System.Environment.NewLine;
                this.s.WriteLine("AT" + (char)(13));
                //string tt = s.ReadLine();
               // if(s.ReadLine()!="AT/r/r")
                {
                    Thread.Sleep(2000);
                    this.s.WriteLine("AT+CMGF=1" + (char)(13));
                    Thread.Sleep(3000);
                    this.s.WriteLine("AT+CMGS=\"" + 9916518522 + "\"");
                    Thread.Sleep(5000);
                    this.s.WriteLine(">" + "le" + (char)(26));
                    this.s.Close();
                    MessageBox.Show("Sent");
                }
                //else
                //{
                //    MessageBox.Show("Dervice Nt");
                //}
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            string[] ports = SerialPort.GetPortNames();


            foreach (string port in ports)
            {
                cboPorts.Items.Add(port);
            }


        }
    }
}

解决方案

instead of selecting manually use for loop & check by sending on every com port & if the com port does not consists the dongle catch it in try catch and do not show a message.


这篇关于使用华为加密狗发送短信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆