Reputation: 1105
I am learning AT Command in c#.
public static void Main(string[] args)
{
String command = "AT";
SerialPort serialPort = new SerialPort
{
PortName = "COM4",
BaudRate = 9600,
DataBits = 8,
Parity = Parity.None,
ReadTimeout = 300,
WriteTimeout = 300,
StopBits = StopBits.One,
Handshake = Handshake.None
};
serialPort.Open();
serialPort.WriteLine(command + "\r");
String outPut = serialPort.ReadExisting();
Console.WriteLine(outPut);
}
I am sure about the PortName. What I am doing wrong in the program??
Thanks in advance :)
Upvotes: 0
Views: 1664
Reputation: 180867
Hard to tell if it's your only problem but SerialPort.ReadExisting()
only reads the data that is immediately available (ie in the stream and buffer).
Your program writes data to the modem, and calls ReadExisting()
right away. ReadExisting
will return immediately with no data available, since the modem has had no time to respond.
Upvotes: 1