如何在Cpu(系统)中找到垂直调制解调器端口 [英] How can we find Perticular Modem Port in Cpu(System)

查看:105
本文介绍了如何在Cpu(系统)中找到垂直调制解调器端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

在这里,iam通过调制解调器开发一个Sms应用程序.在连接到调制解调器的同时,iam通过循环服务至少20个Com端口.实际上,调制解调器已连接到Com5.在for循环中,iam试图搜索连接了哪个Com端口.因此for循环正在检查com1 ,com2,com3,com4失败,因此异常即将到来,因此每次iam在消息框中显示异常消息.所以这对最终用户不利.所以我的想法是在连接到调制解调器时.我们应该保持Com端口信息.意味着如果调制解调器连接到Com5.我应该连接到Com5,或者如果调制解调器连接到Com3,我应该这样连接到Com3.这样我就可以避免出现Exceptuon消息.

关于这个想法,请与我分享.



问候,


AnilKumar.D

Dear Friends,

Here iam Developing one Sms Application Through Modem.While Connecting to Modem iam serching minimum 20 Com ports through loop.Actually the Modem is Connected to Com5.In for loop iam trying to search which Com port is Connected.So the for loop is checking com1,com2,com3,com4 which is failed so the Exception is Coming,So every time iam Showing Exception Messages in Message Box.So it is Not Good For End User.So My idea is while Connected to Modem.We should hold the Com port Information.Means if the Modem is Connected to Com5.I should connected to Com5 or If Modem is Connected to Com3 i should connected to Com3 like this.So i can avoid the Exceptuon Messages.

Regarding this if any Idea please Share with me.



Regards,


AnilKumar.D

推荐答案

解决方案:评论或删除当前显示的MessageBox.

您当前正在做的事情是100%正确的,无法找到与调制解调器连接的端口.因为直到与调制解调器对话(发送命令),您才能识别调制解调器,至少像(AT)
如果命令是对连接到调制解调器的命令的命令的响应.


谢谢
--RA
Solution : Comment or remove the MessageBox which you are currently showing.

What you are doing presently is 100% correct, there is no way to find out to which comport is connected to the modem. Because you can''t identify the modem until you talk(send command) to the modem, like at least(AT)
if the comport is response to the command that is the comport connected to the modem.


Thanks
--RA


这是我的代码
this is my code
private bool EnterNewSettings()
{
    int newPort=0;
    int newBaudRate=0;
    int newTimeout=0;
    int count = 0;
    string[] strport;
    string[] strbaudrate;
    string[] strtimeout;
    try
    {
        strport = Convert.ToString(ConfigurationSettings.AppSettings["COMPortID"]).Split(',');
        strbaudrate = Convert.ToString(ConfigurationSettings.AppSettings["COMBaudRATE"]).Split(',');
        strtimeout = Convert.ToString(ConfigurationSettings.AppSettings["COMTimeOUT"]).Split(',');

    }
    catch (Exception es) { return false; }

    bool comStatus;
    bool comMTN = true;
    int comPortNonMTN = 0;
    if (count != 1)
    {
        for (int i = 0; i < strport.Length; i++)
        {
            comStatus = true;

            for (int j = 0; j < strbaudrate.Length; j++)
            {
                for (int k = 0; k < strtimeout.Length; k++)
                {
                    try
                    {
                        newPort = int.Parse(strport[i]);
                    }
                    catch (Exception)
                    {
                        AddToLog("Invalid port number");
                        return false;
                    }

                    try
                    {
                        newBaudRate = int.Parse(strbaudrate[j]);
                    }
                    catch (Exception)
                    {
                        AddToLog("Invalid baud rate");
                        return false;
                    }

                    try
                    {
                        newTimeout = int.Parse(strtimeout[k]);
                    }
                    catch (Exception)
                    {
                        AddToLog("Invalid timeout value");
                        return false;
                    }

                    SetData(newPort, newBaudRate, newTimeout);
                    GsmCommMain comm = new GsmCommMain(port, baudRate, timeout);
                    try
                    {
                        if (comStatus)
                        {
                            comm.Open();
                            comStatus = false;
                            Thread.Sleep(20000);
                            if (!comm.IsConnected())
                            {
                                //AddToLog("Not Connected : Port - " + port);
                                comm.Close();
                                //return false;
                            }
                            else
                            {
                                if (comMTN)
                                {
                                    comm.Close();
                                    comMTN = false;
                                    comPortNonMTN = i;

                                    i = strport.Length + 1;
                                    count = 1;

                                    return true;

                                }
                                else
                                {
                                    AddToLog("Connected: Port - " + port);
                                    comm.Close();
                                    return true;
                                }
                            }
                        }
                    }

                    catch (Exception ex)
                    {
                        //AddToLog("Connection error: " + ex.Message);
                        //return false;
                    }
                }
            }
            if (i + 1 == strport.Length)
            {
                i = comPortNonMTN - 1;
            }
        }
    }
    return false;
}


这篇关于如何在Cpu(系统)中找到垂直调制解调器端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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