NotSoTragicHero said:davewill said:*snip*The read and write buffer sizes are 4096 and 2048 respectively, so I don't think it is that.
I don't believe there is any way to check the other side of the cable.
The device's manual states that hardware handshaking is in fact enabled, however.
Currently, I am only getting the ReadLine time out exception.
Current Code:
using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.IO.Ports; using System.Collections; using System.Threading; namespace SerialComTest { public partial class form_SerialCom : Form { private SerialPort port; private String displayString; public form_SerialCom() { InitializeComponent(); button_Send.Click += new EventHandler(button_Send_Click); port = new SerialPort("COM1", 115200, Parity.None, 8, StopBits.One); port.Open(); port.NewLine = Environment.NewLine; port.RtsEnable = true; port.DtrEnable = false; port.Handshake = Handshake.RequestToSend; port.ReceivedBytesThreshold = 1; port.WriteTimeout = 500; port.ReadTimeout = 500; port.DiscardInBuffer(); port.DiscardOutBuffer(); port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived); port.ErrorReceived += new SerialErrorReceivedEventHandler(port_ErrorReceived); if (port.IsOpen) { textBox_Rec.Text += "Connected to " + port.PortName + Environment.NewLine; } Thread thread = new Thread(delegate() { while (true) { try { String test = port.ReadLine(); textBox_Rec.Text += test + Environment.NewLine; } catch (TimeoutException) { } } }); thread.Start(); } void port_ErrorReceived(object sender, SerialErrorReceivedEventArgs e) { throw new NotImplementedException(); } void port_DataReceived(object sender, SerialDataReceivedEventArgs e) { displayString = port.ReadLine(); try { this.Invoke(new EventHandler(SetText)); } catch (Exception ex) { Console.WriteLine(ex.Message); } } private void SetText(object o, EventArgs e) { textBox_Rec.Text += displayString + Environment.NewLine; displayString = string.Empty; } void button_Send_Click(object sender, EventArgs e) { try { port.WriteLine(textBox_Send.Text); } catch (TimeoutException) { textBox_Rec.Text += ("The write operation timed out." + Environment.NewLine); } textBox_Send.Text = ""; } } }
ok. so your getting problems on the ReadLine. That means the event is firing. The code needs a little work on the actual using of the received data. The port is setup to trigger the event when each byte enters the receive buffer (ReceivedBytesThreshold=1) ... yet your DataReceived event is trying to read a line at a time rather than doing something like
displayString &= port.ReadByte();