Subject: Modem: send commands, read answers
Posted By: carlosSan Post Date: 12/19/2005 12:59:08 PM
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

Go to topic 37757

Return to index page 414
Return to index page 413
Return to index page 412
Return to index page 411
Return to index page 410
Return to index page 409
Return to index page 408
Return to index page 407
Return to index page 406
Return to index page 405