Kenfack Cathy

Kenfack Cathy

  • NA
  • 19
  • 550

application d'envoie sms en C# determiner le num d port COM

Apr 17 2020 7:12 AM
BONJOUR , JE DEVELOPE UNE Application d'envoie sms par modem gsm en c# et j'aimerai savoir comment determiner le numero du port COM utiliser par mon moderm une fois qu'il est connecte a mon ordinateur, enfaite il me faut entre ce numero dans le code merci.
 
Voici mon code complet j'ai mis au niveau de com xx par ce que je n'ai pas de numero
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.IO.Ports;  
  7. using System.Linq;  
  8. using System.Text;  
  9. using System.Threading;  
  10. using System.Threading.Tasks;  
  11. using System.Windows.Forms;  
  12. namespace TP1_SMS  
  13. {  
  14. public partial class Form1 : Form  
  15. {  
  16. public Form1()  
  17. {  
  18. InitializeComponent();  
  19. }  
  20. private void label5_Click(object sender, EventArgs e)  
  21. {  
  22. }  
  23. private void button3_Click(object sender, EventArgs e)  
  24. {  
  25. SerialPort sp = new SerialPort();  
  26. sp.PortName = "COMXX";  
  27. sp.Open();  
  28. sp.WriteLine("AT" + Environment.NewLine);  
  29. Thread.Sleep(100);  
  30. sp.WriteLine("AT+CMGF= 1 " + Environment.NewLine);  
  31. Thread.Sleep(100);  
  32. sp.WriteLine("AT+CSCS=\"GSM\"" + Environment.NewLine);  
  33. Thread.Sleep(100);  
  34. sp.WriteLine("AT+CMGS=\"" + textBox5.Text + "\" " + Environment.NewLine);//CONTACT  
  35. Thread.Sleep(100);  
  36. sp.WriteLine(textBox6.Text + Environment.NewLine);//MESSAGE  
  37. Thread.Sleep(100);  
  38. sp.Write(new byte[] { 26 }, 0, 1);  
  39. Thread.Sleep(100);  
  40. var response = sp.ReadExisting();  
  41. if (response.Contains("ERROR"))  
  42. {  
  43. MessageBox.Show("Failed!""FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error);  
  44. }  
  45. else  
  46. {  
  47. MessageBox.Show("Sent""SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);  
  48. }  
  49. sp.Close();  
  50. }  
  51. }  
  52. }  

Answers (1)