Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Modem: Send commands read answers

Status
Not open for further replies.

carlossan

Programmer
Dec 10, 2005
18
CA
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top