Witam,
próbuje napisać sobie program do wysyłania smsów przez modem sms:
Oki, zrobiłem sobie taki program:
public static SerialPort SMSPort = null;
static void Main(string[] args)
{
try
{
SMSPort = new SerialPort();
SMSPort.PortName = "COM14";
SMSPort.BaudRate = 115200;
//SMSPort.Parity = Parity.None;
SMSPort.DataBits = 8;
//SMSPort.ReadTimeout = 10000;
//SMSPort.WriteTimeout = 10000;
SMSPort.StopBits = StopBits.One;
//SMSPort.Handshake = Handshake.RequestToSend;
SMSPort.DtrEnable = true;
SMSPort.RtsEnable = true;
SMSPort.NewLine = ((char)13).ToString() + ((char)10).ToString();
SMSPort.Open();
Console.WriteLine("SMS Server is started");
Thread t1 = new Thread(odpowiedzi);
t1.Start();
Thread t2 = new Thread(wysylka);
t2.Start();
}
catch (TimeoutException ex)
{
Console.WriteLine("Błąd : " + ex.Message);
}
catch (Exception ex)
{
Console.WriteLine("Błąd : " + ex.Message);
}
}
public static void odpowiedzi()
{
while (true)
{
Console.WriteLine(SMSPort.ReadLine());
}
}
public static void wysylka()
{
///////////////////////////////////////////////////////////////////
/////////////////// POBRANIE SMSÓW Z BAZY POSTGRESQL ///////////
///////////////////////////////////////////////////////////////////
//while (true)
//{
//
///////////////////////////////////////////////////////////////////
//////////////////// KONWERSJA NA PDU //////////////
///////////////////////////////////////////////////////////////////
SmsSubmitPdu pdu;
string costam = "";
string destination_numbers = "+48123456789";
string txt_message = "tresc wiadomosci";
pdu = new SmsSubmitPdu(txt_message, destination_numbers, ""); // "" indicate SMSC No
//Console.WriteLine(pdu); // WIADOMOŚĆ W PDU DO WYSŁANIA
///////////////////////////////////////////////////////////////////
SMSPort.NewLine = ((char)13).ToString() + ((char)10).ToString();
SMSPort.Write("AT+CMGF=1\r");
byte[] RXBuffer = new byte[SMSPort.ReadBufferSize + 1];
SMSPort.Write("AT+CMGS=\"+48123456789\",129" + SMSPort.NewLine);
while (SMSPort.BytesToRead != 0)
{
costam += SMSPort.ReadExisting() + "\n";
//if (costam.Contains(">") == true)
//{
SMSPort.Write("_tu_bedzie_pdu_" + "" + (char)26);
//}
}
//Console.WriteLine(SMSPort.ReadLine());
//costam += SMSPort.ReadLine() + "\n";
// }
}
nie chce mi to za bardzo działać - ani nie odczytuje, ani nie wysyła:/ wiecie może co jest nie tak??
Northwest