Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将gsm调制解调器自动连接到可用的COM端口(无组合框)_C#_Combobox_Port_Gsm_Modem - Fatal编程技术网

C# 如何将gsm调制解调器自动连接到可用的COM端口(无组合框)

C# 如何将gsm调制解调器自动连接到可用的COM端口(无组合框),c#,combobox,port,gsm,modem,C#,Combobox,Port,Gsm,Modem,这个问题可以重复,但不能重复。经过长时间的网上搜索,没有结果,于是只好寻求帮助 所有解决方案都适用于在组合框中加载可用端口,用户一次选中一个。但自动化功能随之消失。 因此,我正在寻求帮助,了解调制解调器如何从可用端口自动连接,而无需用户交互(用户友好) 对于组合框,它工作正常,如下所示 using GsmComm.GsmCommunication; using GsmComm.PduConverter; using GsmComm.Server; using MySql.Data.MySqlCl

这个问题可以重复,但不能重复。经过长时间的网上搜索,没有结果,于是只好寻求帮助

所有解决方案都适用于在组合框中加载可用端口,用户一次选中一个。但自动化功能随之消失。 因此,我正在寻求帮助,了解调制解调器如何从可用端口自动连接,而无需用户交互(用户友好)

对于组合框,它工作正常,如下所示

using GsmComm.GsmCommunication;
using GsmComm.PduConverter;
using GsmComm.Server;
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace COMM_All
{
    public partial class Comm_F : Form
    {
        public Comm_F()
        {
            InitializeComponent(); 
        }

        private void COM_PORTS()
        {
            string[] ports = SerialPort.GetPortNames();
            txtGPort1.Items.AddRange(ports);
            txtGPort2.Items.AddRange(ports);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            COM_PORTS(); 
        }

        private void Modem1_Click(object sender, EventArgs e)
        {
            if (txtGPort1.Text == "") { MessageBox.Show("Invalid Port Name"); return; }
            comm = new GsmCommMain(txtGPort1.Text, 9600, 8);
            Cursor.Current = Cursors.Default;

            bool retry;
            do
            {
                retry = false;
                try
                {
                    Cursor.Current = Cursors.WaitCursor; comm.Open(); Cursor.Current = Cursors.Default;
                    //MessageBox.Show("Modem Connected Sucessfully");
                     txtGStatus1.Text = "Connected Sucessfully";
                     comm.EnableMessageNotifications();
                     MessageBox.Show("Message notifications activated.");

                }
                catch (Exception)
                {
                    Cursor.Current = Cursors.Default;
                    if (MessageBox.Show(this, "GSM Modem is not available", "Check",
                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Warning) == DialogResult.Retry)
                        retry = true; 
                    else { return; }
                }
            } while (retry);
  
      }
}
}

注:计算机有多个usb设备

什么是GsmCommMain对象?它来自于你的代码或者你正在使用的某种库?它来自于我的代码<代码>使用GsmComm.GsmCommunication;使用GsmComm.PduConverter;使用GsmComm.Server;使用MySql.Data.MySqlClient;使用制度;使用System.Collections.Generic;使用系统组件模型;使用系统配置;使用系统数据;使用系统图;使用System.IO.Ports;使用System.Linq;使用系统文本;使用System.Threading.Tasks;使用System.Windows.Forms;名称空间COMM_All{public partial class COMM_F:Form{public COMM_F(){InitializeComponent();}}}}