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
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.IO.Ports;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace TP1_SMS
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void label5_Click(object sender, EventArgs e)
- {
- }
- private void button3_Click(object sender, EventArgs e)
- {
- SerialPort sp = new SerialPort();
- sp.PortName = "COMXX";
- sp.Open();
- sp.WriteLine("AT" + Environment.NewLine);
- Thread.Sleep(100);
- sp.WriteLine("AT+CMGF= 1 " + Environment.NewLine);
- Thread.Sleep(100);
- sp.WriteLine("AT+CSCS=\"GSM\"" + Environment.NewLine);
- Thread.Sleep(100);
- sp.WriteLine("AT+CMGS=\"" + textBox5.Text + "\" " + Environment.NewLine);
- Thread.Sleep(100);
- sp.WriteLine(textBox6.Text + Environment.NewLine);
- Thread.Sleep(100);
- sp.Write(new byte[] { 26 }, 0, 1);
- Thread.Sleep(100);
- var response = sp.ReadExisting();
- if (response.Contains("ERROR"))
- {
- MessageBox.Show("Failed!", "FAILED", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- else
- {
- MessageBox.Show("Sent", "SUCCESS", MessageBoxButtons.OK, MessageBoxIcon.Information);
- }
- sp.Close();
- }
- }
- }