I am trying to read data from an RS232 scale interface. It sends a continuous stream of ASCII string through the serial port I'm having problems with. I just want to get one row of data that it sends. I suppose I assumed that I would use Readline to get the data, but it just blocks the PC when I start it. I think he is trying to get all the data and will not stop until the data stops? Here is the code I'm using:
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM4";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;
serialPort1.Open();
string str = serialPort1.ReadLine();
MessageBox.Show(str);
serialPort1.Close();
}
Can you help me determine how to get only one line of output and close the connection?
source
share