Hi,
I have to send some commands and read the modem's answers to those commands. The time the modem needs to answer the command varies depending on the command issued by the PC.
I have been working on a function like this:
answer = modemCommandAnswer("AT","OK");
private bool modemCommandAnswer(string modemCommand, string expectedAnswer)
{
string modemAnswer;
serialPortModem.WriteLine(modemCommand);
modemAnswer = serialPortModem.ReadLine();
if (modemAnswer.Equals(expectedAnswer))
{
return true;
}
return false;
}
Is there a better method than ReadLine() for this job ?. The problem with ReadLine is that it reads until it finds a new-line char and some modems have the echo activated, so the reading returns the same issued command.
In some other programming languages there are methods that allows the system to wait until the expected answer is received or until a timeout timer expires.
What is the rigth way to do this in C# 2005 ?
Regards,
Carlos
I have to send some commands and read the modem's answers to those commands. The time the modem needs to answer the command varies depending on the command issued by the PC.
I have been working on a function like this:
answer = modemCommandAnswer("AT","OK");
private bool modemCommandAnswer(string modemCommand, string expectedAnswer)
{
string modemAnswer;
serialPortModem.WriteLine(modemCommand);
modemAnswer = serialPortModem.ReadLine();
if (modemAnswer.Equals(expectedAnswer))
{
return true;
}
return false;
}
Is there a better method than ReadLine() for this job ?. The problem with ReadLine is that it reads until it finds a new-line char and some modems have the echo activated, so the reading returns the same issued command.
In some other programming languages there are methods that allows the system to wait until the expected answer is received or until a timeout timer expires.
What is the rigth way to do this in C# 2005 ?
Regards,
Carlos