serialPort not works?

  • Thread starter Thread starter PiotrKolodziej
  • Start date Start date
P

PiotrKolodziej

Hi
Iam trying to send AT commands to the device.

if (serialPort1.IsOpen) serialPort1.Close();


serialPort1.Open();

byte[] buffer = ASCIIEncoding.ASCII.GetBytes("AT");



serialPort1.Write(buffer, 0, buffer.Length);
Thread.Sleep(1000);
serialPort1.ReadLine();


While in hyperterminal everything is ok ( device reposnds with OK ), here
program stops at the readline();
When i close the program and open HT the AT command is still in the buffer.
I Tought that maybe iam not sending Enter key code, but tried saveral times
without effect.
If you have an idea what shoud i correct, i'd be grateful for advice
PK

ps:( serialport settings are the same as in HT )
 
This is the code with the enter key:


private void Form1_Load(object sender, EventArgs e)
{
if (serialPort1.IsOpen) serialPort1.Close();

serialPort1.Open();

SendCommand("AT");
Thread.Sleep(1000);
serialPort1.ReadLine();

SendCommand("AT+CMGF=1");
Thread.Sleep(1000);
serialPort1.ReadLine();

SendCommand("AT+CNMI=1,2,0,0,0");
Thread.Sleep(1000);
serialPort1.ReadLine();

}

private void SendCommand(string value)
{
StringBuilder sb = new StringBuilder(value);
int size = sb.Length;
byte[] data = new byte[size + 1];
for (int i = 0; i < sb.Length; i++)
{
data = (byte)sb;
}
data[size] = (byte)Convert.ToChar(13);

//send the data
if (serialPort1.IsOpen)
serialPort1.Write(data, 0, size + 1);
}
 
PiotrKolodziej wrote:

<snippedy>

Hi,

You may need to send a CRLF sequence (just a wild stab in the dark), which
means you need to send a 13 followed by a 10.
 
You may need to send a CRLF sequence (just a wild stab in the dark), which
means you need to send a 13 followed by a 10.

I think that the problem is with the SerialPort itself.
When i close application and run HT i see AT and OK response, so the AT with
the enter key was stored in the buffer.
Problem is why it's not beeing sent by the program but stored in the buffer
instead?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top