România
Roportal.ro

comunicare modem-telefon

Început de Calina.stoica, Mie 24 mar 2010 · 0 răspunsuri · 2.199 vizualizări

Calina.stoica1 mesaje#1

Buna !

Am de realizat o aplicatie in C# in care, folosind un modem GSM/GPRS trebuie sa trimit sms-uri si sa fac apeluri catre un telefon.Am facut partea de trimitere de SMS -uri si de apelare...si acum trebuie ca dupa ce se raspunde la telefon sa introduc un mesaj - voce (adica un text convertit in voce).Am realizat aplicatia de conversie a textului in voce si acum trebuie doar sa inserez acel mesaj imediat dupa c este stabilita legatura.Problema mea este ca nu stiu cum sa verific daca s-a raspuns la apel si cum inserez apoi mesajul.Daca cineva ma poate ajuta....

copiez mai jos codul :

using System;

using System.Collections.Generic;

using System.Text;

using System;

using System.IO.Ports;

using System.Threading;

using System.Speech.Synthesis;

using System.Collections.ObjectModel;

public class PortChat

{

// static bool _continue;

static SerialPort _serialPort;

public static void Main()

{

// list voice installed on the system

// ListVoice();

// speak with the second voices. If you have only one voice, change it to Speak(0)

//Console.ReadLine();

//string message;

StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;

//Thread readThread = new Thread(Read);

// Create a new SerialPort object with default settings.

_serialPort = new SerialPort();

// Allow the user to set the appropriate properties.

_serialPort.PortName = SetPortName(_serialPort.PortName);

_serialPort.BaudRate = SetPortBaudRate(_serialPort.BaudRate);

_serialPort.Parity = SetPortParity(_serialPort.Parity);

_serialPort.DataBits = SetPortDataBits(_serialPort.DataBits);

_serialPort.StopBits = SetPortStopBits(_serialPort.StopBits);

_serialPort.Handshake = SetPortHandshake(_serialPort.Handshake);

// Set the read/write timeouts

_serialPort.ReadTimeout = 500;

_serialPort.WriteTimeout = 500;

_serialPort.Open();

// readThread.Start();

string phonenr = "";

string mesaj;

if (!_serialPort.IsOpen)

{

_serialPort.Open();

}

_serialPort.WriteLine("AT\r");

{

Console.WriteLine("Enter the phone number:", phonenr);

phonenr = Console.ReadLine();

_serialPort.WriteLine("ATD" + phonenr + ";" + "\r");

Console.WriteLine("Ring...");

Thread.Sleep(1000);

Speak(1);

//Console.WriteLine("Enter the message:");

//mesaj= Console.ReadLine();

//_serialPort.WriteLine("AT+CMGF=1\r");

//_serialPort.WriteLine("AT+CMGS=\"" + phonenr + "\"\r");

//_serialPort.WriteLine(mesaj + '\x001a');

// Thread.Sleep(500);

// Console.WriteLine("Message sent...");

_serialPort.DiscardInBuffer();

_serialPort.DiscardOutBuffer();

_serialPort.Close();

//readThread.Join();

_serialPort.Close();

// Console.WriteLine("Type QUIT to exit");

// while (_continue)

// {

// message = Console.ReadLine();

// if (stringComparer.Equals("quit", message))

// {

// _continue = false;

//}

// }

Console.ReadLine();

}

}

static void Speak(int voiceIdx)

{

string text = "";

SpeechSynthesizer syn = new SpeechSynthesizer();

ReadOnlyCollection<InstalledVoice> voices = syn.GetInstalledVoices();

if (voiceIdx < 0 || voiceIdx >= voices.Count)

{

Console.WriteLine("voice index out of range from [0-{0}]", voices.Count);

return;

}

syn.SelectVoice(voices[voiceIdx].VoiceInfo.Name);

syn.Speak("the address is : constitution street number 69");

// Console.WriteLine("Enter the text:");

//text = Console.ReadLine();

//syn.Speak(text);

}

static void ListVoice()

{

SpeechSynthesizer syn = new SpeechSynthesizer();

ReadOnlyCollection<InstalledVoice> voices = syn.GetInstalledVoices();

foreach (InstalledVoice voice in voices)

{

Console.WriteLine(voice.VoiceInfo.Description);

}

}

/*public static void Read()

{

while (_continue)

{

try

{

string message = _serialPort.ReadLine();

Console.WriteLine(message);

}

catch (TimeoutException) { }

}

}*/

public static string SetPortName(string defaultPortName)

{

string portName;

Console.WriteLine("Available Ports:");

foreach (string s in SerialPort.GetPortNames())

{

Console.WriteLine(" {0}", s);

}

Console.Write("COM port({0}): ", defaultPortName);

portName = Console.ReadLine();

if (portName == "")

{

portName = defaultPortName;

}

return portName;

}

public static int SetPortBaudRate(int defaultPortBaudRate)

{

string baudRate;

Console.Write("Baud Rate({0}): ", defaultPortBaudRate);

baudRate = Console.ReadLine();

if (baudRate == "")

{

baudRate = defaultPortBaudRate.ToString();

}

return int.Parse(baudRate);

}

public static Parity SetPortParity(Parity defaultPortParity)

{

string parity;

Console.WriteLine("Available Parity options:");

foreach (string s in Enum.GetNames(typeof(Parity)))

{

Console.WriteLine(" {0}", s);

}

Console.Write("Parity({0}):", defaultPortParity.ToString());

parity = Console.ReadLine();

if (parity == "")

{

parity = defaultPortParity.ToString();

}

return (Parity)Enum.Parse(typeof(Parity), parity);

}

public static int SetPortDataBits(int defaultPortDataBits)

{

string dataBits;

Console.Write("Data Bits({0}): ", defaultPortDataBits);

dataBits = Console.ReadLine();

if (dataBits == "")

{

dataBits = defaultPortDataBits.ToString();

}

return int.Parse(dataBits);

}

public static StopBits SetPortStopBits(StopBits defaultPortStopBits)

{

string stopBits;

Console.WriteLine("Available Stop Bits options:");

foreach (string s in Enum.GetNames(typeof(StopBits)))

{

Console.WriteLine(" {0}", s);

}

Console.Write("Stop Bits({0}):", defaultPortStopBits.ToString());

stopBits = Console.ReadLine();

if (stopBits == "")

{

stopBits = defaultPortStopBits.ToString();

}

return (StopBits)Enum.Parse(typeof(StopBits), stopBits);

}

public static Handshake SetPortHandshake(Handshake defaultPortHandshake)

{

string handshake;

Console.WriteLine("Available Handshake options:");

foreach (string s in Enum.GetNames(typeof(Handshake)))

{

Console.WriteLine(" {0}", s);

}

Console.Write("Stop Bits({0}):", defaultPortHandshake.ToString());

handshake = Console.ReadLine();

if (handshake == "")

{

handshake = defaultPortHandshake.ToString();

}

return (Handshake)Enum.Parse(typeof(Handshake), handshake);

}

}

merci ,

[email protected]

← Înapoi la Programare