static void Main(string[] args) { string text = "3g modemdan prep" + DateTime.Now.ToString(); string ComPort = "COM14"; string number = "+998998278960"; //if (args.Length > 0) //{ // ComPort = args[0]; // number = args[1]; // text = args[2]; //}else //{ // Console.WriteLine("sms_cli /dev/ttyUSB0 +998998278960 text"); // return; //} var modem = new GsmModem.GsmModem(ComPort); try { modem.ReceiveTimeount = 1000; modem.Connect(); modem.SendSms(number, text); } finally { modem.Close(); } Console.WriteLine("OK"); Console.ReadLine(); }
public void Run() { using (var db = new MyDbContext()) { var list = db.Clients.Where(x => x.status == 0).ToList(); if (list.Count == 0) { return; } string ComPort = config.GetSection("AppSettings:ComPort").Value; var modem = new GsmModem.GsmModem(ComPort); try { modem.ReceiveTimeount = 1000; var isOpen = modem.Connect(); if (isOpen == false) { return; } var sig = modem.SignalStrength; logger.LogInformation($"Signal ==> {sig}"); if (sig == -1) { logger.LogError($"No signal"); return; } if (devInfo == null) { devInfo = new DevInfo() { SignalStrength = modem.SignalStrength, Comands = modem.SupportedCommands.ToList() }; } foreach (var it in list) { var res = modem.SendSms(it.phone_num, it.text); if (!res) { logger.LogInformation($"Sended => {it.phone_num}"); it.status = 1; it.sended = DateTime.Now; } db.SaveChanges(); } } catch (Exception ee) { logger.LogError(ee.Message); logger.LogError(ee.InnerException?.Message); logger.LogError(ee.StackTrace); } finally { modem?.Close(); } } }