Click to See Complete Forum and Search --> : C# SerialPort Class


HF Interface
August 6th, 2009, 10:47 AM
Q. I'm trying to write a string of characters to the serial port, which is successful, However as soon as i try and read back what has been sent, it only reads half of the the data initially sent. can anybody please help? Do i need some sort of a delay when reading or sending?

Code:

serialPort1.Open();
serialPort1.Write("Communications Solutions");


recieved_data = serialPort1.ReadExisting();

textBox1.Text = recieved_data;

serialPort1.Close();

// Recieved_data only displays half the characters in the text box.

PeejAvery
August 7th, 2009, 10:07 AM
[ moved ]

RaleTheBlade
August 7th, 2009, 11:36 AM
When you send data, it uses a transmit buffer and when you receive data it uses a receive buffer. You're essentially using two different buffers for serial communication.

If you want to get some of the data "back" that you've sent, you'll need to use whats called a null modem or use a boomerang application that will receive the data on the other end and write it back to the serial port.

I'm studying serial communication with the 8051 architecture and it explains a lot of how serial ports work. I even have to generate my own baud rates! haha