开发者

SerialPort not taking input. It throws it back at me!

开发者 https://www.devze.com 2022-12-29 07:08 出处:网络
When I try to write an AT command to my GSM modem, it does not seem to take the command.I have used PuTTY to check that the command words, it does.I have checked to see if the port is opening, it do开

When I try to write an AT command to my GSM modem, it does not seem to take the command. I have used PuTTY to check that the command words, it does. I have checked to see if the port is opening, it do开发者_如何学运维es.

What could I possibly be doing wrong?

NOTE: The "lol" part is for debugging purposes. ;3

SerialPort sp = new SerialPort("COM3");
sp.BaudRate = 9600;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.Parity = Parity.None;
sp.Open();
if (sp.IsOpen == false)
{
    sp.Open();
}
Thread.Sleep(1000);
sp.WriteLine("AT+CMGF=1");
Thread.Sleep(1000);
string lol = sp.ReadExisting();
sp.Close();
return lol;


Throws it back? an ATE0 will disable it echoing what you send it.

You should probably also issue an ATQ0 to tell the device you want responses, otherwise it won't issue OKs. (a subsequent ATV1 will make them verbose) also issue a AT+CMEE=1 to activate error responses.

There are also existing libraries that are designed to work with GSM Modems that will save you the trouble, if you want to do it yourself a port monitor will save you pulling out your hair by showing you exactly what being sent/received.


Some things to verify...

Is the NewLine property correct for your modem? The default is a line feed.

How about the RtsEnable and DtrEnable values?

Is the Handshake property correct?

0

精彩评论

暂无评论...
验证码 换一张
取 消