SerialPort

Hi
im tring to send AT command to my gsm modem using serialport. but its not working properly. Reading event not working!. please help me to doing this.
--

#region Namespace Inclusions

using System;

using System.IO.Ports;

using System.Windows.Forms;

#endregion

namespace SerialPortExample

{

classSerialPortProgram

{

// Create the serial port with basic settings

privateSerialPort port =newSerialPort("COM1", 9600,Parity.None, 8,StopBits.One);

[STAThread]

staticvoid Main(string[] args)

{

SerialPortProgram sp =newSerialPortProgram();

sp.SendSampleData();

Application.Run();

}

privatevoid SendSampleData()

{

Console.WriteLine("Sending Data:" +port.IsOpen);

port.WriteLine("AT");

}

private SerialPortProgram()

{

Console.WriteLine("Incoming Data:");

// Attach a method to be called when there is data waiting in the port's buffer

port.DataReceived +=newSerialDataReceivedEventHandler(port_DataReceived);

port.ErrorReceived +=newSerialErrorReceivedEventHandler(sp_ErrorEvent);

//port.ReceivedBytesThreshold = 1;

Console.WriteLine("ReadBufferSize:" + port.ReadBufferSize);

//port.ReadBufferSize = 2047;

port.ReceivedBytesThreshold = 100;

port.ReadTimeout = 3000;// 3 second timeout

port.NewLine ="\r";

// Begin communications

port.Open();

//port.DtrEnable = true;

}

privatevoid sp_ErrorEvent(object sender,SerialErrorReceivedEventArgs e)

{

Console.WriteLine(">>e");

}

privatevoid port_DataReceived(object sender,SerialDataReceivedEventArgs e)

{

Console.WriteLine(">>");

// Show all the incoming data in the port's buffer

//Console.WriteLine(port.ReadExisting());

int c;

while (port.BytesToRead > 0)

{

c = port.ReadByte();

Console.WriteLine(">"+c);

}

}

}

}
-
console output :
Incoming Data:
ReadBufferSize:4096
Sending Data:True
-
Thanks

[5967 byte] By [DishanFernando] at [2008-3-1]
# 1

I don’t have much experience with using modems however is it possible that the modem is simply not writing back any data after you send the AT command? The best way to determine if there is a problem with the DataReceived event is the printing out the BytesToRead after sending the AT command. If BytesToRead is 0 then there is probably some problem with communication between the computer and the modem(thought I have no idea what this would be since I don’t know much about the communication protocol for modems).

Thanks,

Ryan Byington [MS]

RyanByington at 2007-9-8 > top of Msdn Tech,Visual Studio Express Editions,Visual C# 2005 Express Edition...