I've coded a little program to read/send SMS messages using a GSM device. My code worked fine on one kind of device. Today I am using a different device and my program can't receive from it (although it can send to it just fine). The device works just fine with the same configs under puTTY.
private void Form1_Load(object sender, EventArgs e)
{
Variables.sp.PortName = "COM1";
Variables.sp.BaudRate = 9600;
Variables.sp.DataBits = 8;
Variables.sp.Parity = Parity.None;
Variables.sp.StopBits = StopBits.One;
Variables.sp.DataReceived += new SerialDataReceivedEventHandler(DataReceivedHandler);
try
{
Variables.sp.Open();
Variables.sp.WriteLine("AT\r");
//Variables.sp.WriteLine("AT+CMGF=1\r");
}
catch
{
MessageBox.Show("Can't open COM1. Quit and try again.");
}
}
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
MessageBox.Show(indata);
}
Any idea why it would work fine on one device and not the other? While I'm typing the same commands under puTTY and they both work the same?