application d'envoi SMS en C#
bonjour tous le monde je développe une application en c# d'envoi sms par telephone connecte au port usb de pc en utilisant les commandes at voila mon code de la form SMS
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace SMS
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
loadPorts();
}
private void loadPorts()
{
string[] ports = SerialPort.GetPortNames();
foreach (string port in ports)
{
cboPorts.Items.Add(port);
}
}
private void btnSend_Click(object sender, EventArgs e)
{
SmsClass sm = new SmsClass(cboPorts.Text);
sm.Opens();
sm.sendSms(txtPhone.Text, txtMessage.Text);
sm.Closes();
MessageBox.Show("Message Sent!");
}
private void cboPorts_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtPhone_TextChanged(object sender, EventArgs e)
{
}
private void txtMessage_TextChanged(object sender, EventArgs e)
{
}
}
} |
et voila le code de program.cs
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
} |
j'utilise la class smsclass pour communiquer avec le port et envoyer les commandes at
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.IO.Ports;
using System.Windows.Forms;
namespace SMS
{
class SmsClass
{
SerialPort serialPort;
public SmsClass(string comPort)
{
this.serialPort = new SerialPort();
this.serialPort.PortName = comPort;
this.serialPort.BaudRate = 9600;
this.serialPort.Parity = Parity.None;
this.serialPort.DataBits = 8;
this.serialPort.StopBits = StopBits.One;
this.serialPort.Handshake = Handshake.RequestToSend;
this.serialPort.DtrEnable = true;
this.serialPort.RtsEnable = true;
this.serialPort.NewLine = System.Environment.NewLine;
}
public bool sendSms(string cellNo, string sms)
{
string messages = null;
messages = sms;
if (this.serialPort.IsOpen == true)
{
try
{
this.serialPort.WriteLine("AT" + (char)(13));
Thread.Sleep(4);
this.serialPort.WriteLine("AT+CMGF=1" + (char)(13));
Thread.Sleep(5);
this.serialPort.WriteLine("AT+CMGS=\"" + cellNo + "\"");
Thread.Sleep(10);
this.serialPort.WriteLine(">" + messages + (char)(26));
}
catch (Exception ex)
{
MessageBox.Show(ex.Source);
}
return true;
}
else
return false;
}
public void Opens()
{
if (this.serialPort.IsOpen == false)
{
this.serialPort.Open();
}
}
public void Closes()
{
if (this.serialPort.IsOpen == true)
{
this.serialPort.Close();
}
}
}
} |
mon probleme c'est quand j'execute le programe il ma'affiche une ereur dans le code de program.cs :
Citation:
Error 1 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) D:\Program.cs 18 33 WindowsFormsApplication5
merci de m'aider svp