Click here to Skip to main content
15,882,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
THIS QUESTION MAY SEAM A DUPLICATE, BUT NOT. after a long period of search on internet and no, result, then had to seek for assistance.

All solutions apply to loading available ports in a combo box and the user checks one at a go. But the automation feature then dies.
thus,
i'm looking for assistance on how the modem can connect automatically from the available ports without user interaction (USER FRIENDLINESS)

FOR THE COMBO BOX, IT IS WORKING FINE;

What I have tried:

C#
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);
  
      }
}
}
Posted
Updated 13-Oct-22 22:36pm
v3
Comments
Richard MacCutchan 15-Nov-20 9:04am    
You could try connecting to each port in turn until one succeeds.
honey the codewitch 15-Nov-20 10:34am    
ooh that could be fun depending on whats on the other COM ports. :P
[no name] 15-Nov-20 10:46am    
Not to mention matching the baud rate, etc.
Richard MacCutchan 15-Nov-20 10:46am    
Fun is what it's all about. :)
Robert S4r 15-Nov-20 10:51am    
HOW? Code....?

1 solution

You would have to open each port, one at a time, and send a command to it to get an expected response. If you don't get that response, close the port and move on to the next one.
 
Share this answer
 
Comments
Robert S4r 15-Nov-20 10:52am    
how? code....?
Dave Kreskowiak 15-Nov-20 18:29pm    
It's simple. You open the port, send a command that doesn't do anything or send a command that tells the phone to ID itself. If you get an expected response, you found the port. If not, close the port and move to the next one.

I do not have code as I don't do anything over a serial port or with any phones connected to a PC.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900