473,322 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

serialPort not works?

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 )
Oct 11 '06 #1
4 4758
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[i] = (byte)sb[i];
}
data[size] = (byte)Convert.ToChar(13);

//send the data
if (serialPort1.IsOpen)
serialPort1.Write(data, 0, size + 1);
}
Oct 11 '06 #2
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.

--
Hope this helps,
Tom Spink

Google first, ask later.
Oct 11 '06 #3
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?
Oct 11 '06 #4
Problem solved.
Solution was to set hanshaking.
Oct 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Joshua Moore | last post by:
I'm trying to convert from a lot of invoked code to c# 2.0 SerialPort code. I can't find a way to set fOutxCtsFlow to true (maybe CTSEnable?) and fRtsControl = RTS_CONTROL_HANDSHAKE (RtsEnable?). ...
4
by: Ben Kim | last post by:
Hello all, Does anyone have an example on how to implement the new SerialPort Class in VB.NET? I have been able to create the class, send (.WriteLine) to the port and Read from the port but...
3
by: Eric | last post by:
Hi, In my application for PDA I use the serialport class to send data to a navigation computer of VDO Dayton. Everything works fine as long as it is connected to the nav-computer. When the...
13
by: Jean Paul Mertens | last post by:
Hello, Someone can tell me why I dont get serial port events in a Service, I created a separate Thread to open the port but no events are coming up (the same happens when I use the timer...
1
by: sranger | last post by:
When I try to use a System.IO.Ports.SerialPort object to read from a serial port, half of the time I have no problems. However, after I successfully read from the serial port, then close the...
3
by: Mugunth | last post by:
Hi, I've a strange problem with serial port class of .NET Framework 2.0 I use com0com (Null Modem COM Port emulator) to emulate a virtual port. This application creates virtual com port pairs...
7
by: Simon | last post by:
Hi all, I'm writing a PocketPC / CE application which communicates with a Bluetooth GPS reciever that is paired to a serial port but I'm experiencing odd behaviour from the CF 2.0 SerialPort...
3
by: Adriano | last post by:
Hello, I'm developing an application in VB.NET 2005 that communicates with a device through RS232, and need to send the following sequence of hexadecimal data to the device: 0xFF, 0x01, 0xC3,...
1
by: Lars Siden | last post by:
Hi, I've really struggled with this. Using Hyperterminal everything works fine. But if I write my own program I can't get "OnDataReceived" to be fired. MS samples from the SDK gives me the...
6
by: Steve Mowbray | last post by:
Hi I am using SerialPort component to send raw binary files to a remote device with RTS/CTS handshaking - the remote device has a small receive buffer and is slow so needs to be hardware flow...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.