davewill said:NotSoTragicHero said:*snip*Make sure the port on the GSM side is using hardware handshaking.
If you are getting a timeout on the Write then it sure sounds like it is waiting on the GSM side to give the goahead.
How about the send and recv buffer sizes on both sides of the cable? are they sufficient.
set port.rts = true and port.dtr = false since using hardware handshaking.
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 = "";
}
}
}