static void infotimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { bool modemstatus = _comm.IsOpen() && _comm.IsConnected(); string modeminfo = ""; try { if (modemstatus) { modeminfo = $"\r\nPort: {_comm.PortName}\r\nOperator: {_comm.GetCurrentOperator().TheOperator}" + $"\r\nSignal: { (_comm.GetSignalQuality().SignalStrength == 99 ? "Unknown" : (Math.Floor(((double)_comm.GetSignalQuality().SignalStrength / 31) * 100)) + "%")}\r\n"; } } catch (Exception) { modemstatus = false; } _logger.Info($"Application Information:\r\nModem status: {(modemstatus ? "OK" : "ERROR") + modeminfo}"); }
public void connect() { string cmbCOM = "COM" + comms.Text; comm = new GsmCommMain(cmbCOM, 9600, 150); try { if (comm.IsConnected()) { info.Content = comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Model.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Revision.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().SerialNumber.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.GetCurrentOperator(); info.Content = info.Content + Environment.NewLine + comm.GetSignalQuality(); info.Content = info.Content + Environment.NewLine + comm.GetSmscAddress(); info.Content = info.Content + Environment.NewLine + comm.GetSubscriberNumbers(); save.Visibility = Visibility.Visible; Console.WriteLine("comm is already open"); } else { Console.WriteLine("comm is not open"); comm.Open(); info.Content = comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Model.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().Revision.ToUpper().ToString(); info.Content = info.Content + Environment.NewLine + comm.IdentifyDevice().SerialNumber.ToUpper().ToString(); save.Visibility = Visibility.Visible; } } catch (Exception r) { MessageBox.Show(r.Message); } }
public bool CrearConexionCOM() { bool retry = true;; do { comm = new GsmCommMain("COM" + puertoCOM, 9600, 150); try { comm.Open(); if (comm.IsConnected()) { //eventLog.WriteEntry("Conexion de BAM exitosa, señal del dispositivo: " + comm.GetSignalQuality().SignalStrength,EventLogEntryType.Information); string nombreBAM = comm.IdentifyDevice().Manufacturer.ToUpper().ToString(); string modelBAM = comm.IdentifyDevice().Model.ToUpper().ToString(); string numRevisionBAM = comm.IdentifyDevice().Revision.ToUpper().ToString(); string numSerieBAM = comm.IdentifyDevice().SerialNumber.ToUpper().ToString(); new LogAplicacion().Info("Conexion de BAM exitosa, señal del dispositivo: " + comm.GetSignalQuality().SignalStrength + "\n Datos BAM: \n *" + nombreBAM + "\n *" + modelBAM + "\n *" + numRevisionBAM + "\n *" + numSerieBAM ); return(true); } else { comm.Close(); puertoCOM++; } } catch (Exception ex) { if (puertoCOM >= 50)//recorre hasta el puerto 50 { NotificacionCorreo notificacionCorreo = new NotificacionCorreo(); Thread thread = new Thread(x => notificacionCorreo.EnviarThread("Verifique que la banda ancha (bam) este conectada al equipo..!!<br></br>Se recomienda cerrar la aplicacion e intentar de nuevo <br></br>Error: " + ex)); thread.Start(); new LogAplicacion().Error(ex.Message); return(false); } puertoCOM++; retry = true; } }while (retry); return(false); }