示例#1
0
        static void GetAvailableComPorts()
        {
            Console.WriteLine("Open Serial/COM ports for use:");
            if (SerialPort.GetPortNames().Length > 0)
            {
                foreach (string serialPort in SerialPort.GetPortNames())
                {
                    GsmCommunication com = new GsmCommunication(serialPort);

                    try
                    {
                        com.OpenPort();

                        if (com.CheckPort())
                        {
                            string phoneNumber = com.GetNumber();
                            string imei        = com.GetImei();
                            Console.WriteLine("Port {0} is available for use.", serialPort);
                            Console.WriteLine("Port {0} SIM card number is: {1}", serialPort, phoneNumber);
                            Console.WriteLine("Port {0} IMEI number: {1}", serialPort, imei);
                        }
                    }
                    catch (Exception e) {
                        Console.WriteLine("[Error] exception occured: {0}", e.Message);
                    }
                    finally {
                        com.ClosePort();
                    }
                }
            }
            else
            {
                Console.WriteLine("No available COM ports for use now.");
            }
        }
示例#2
0
 public void CheckStatus()
 {
     if (module.CheckPort())
     {
         Console.WriteLine("[{0}] Module is working correctly, health check passed.", IMEI);
         CheckNumber();
         CheckSms();
     }
 }
示例#3
0
        static void Main(string[] args)
        {
            while (true)
            {
                if (SerialPort.GetPortNames().Length > 0)
                {
                    foreach (string serialPort in SerialPort.GetPortNames())
                    {
                        GsmCommunication com = new GsmCommunication(serialPort);

                        try
                        {
                            com.OpenPort();

                            if (com.CheckPort())
                            {
                                string phoneNumber = com.GetNumber();
                                string imei        = com.GetImei();
                                Console.WriteLine("[Main] Port {0} is available for use.", serialPort);
                                Console.WriteLine("[Main] Port {0} SIM card number is: {1}", serialPort, phoneNumber);
                                Console.WriteLine("[Main] Port {0} IMEI number: {1}", serialPort, imei);

                                Module GSM = new Module(serialPort);
                                GSM.IMEI        = imei;
                                GSM.PhoneNumber = phoneNumber;

                                //Find existing module by IMEI - if not found we add new
                                if (!modules.Exists(ByIMEI(imei)))
                                {
                                    modules.Add(GSM);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("[Main][Error] exception occured: {0}", e.Message);
                        }
                        finally
                        {
                            com.ClosePort();
                        }
                    }
                }
                else
                {
                    Console.WriteLine("[Main] No available COM ports for use now.");
                }

                foreach (var module in modules)
                {
                    if (!module.Running)
                    {
                        module.Start();
                        module.Running = true;
                    }
                }

                Console.WriteLine("[Main][Info] Modules total connected: {0}", modules.Count);

                Thread.Sleep(MAIN_DELAY);
            }
        }