S
Simon
Hello All,
My problems continue I after three day I can not find solution for my
problems with SerialPort.
Now I have written simple application that will receive and transmit data.
Connected two PCs and started testing. I can transmit, but to receive data I
have problems. If I set both PCs to the same baud rate speed and other port
settings are also the same I will not get anything. If I set the other PC to
lower speed, than I will get characters on the first PC (in .NET
application). Of course I receive garbage, but the characters are there.
Is there a any known problem with SerialPort?
Is there a working sample of the SerialPort use?
Best regards
Simon
My code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
serialPort.PortName = "COM1";
serialPort.BaudRate = 115200;
serialPort.DataBits = 8;
serialPort.StopBits = System.IO.Ports.StopBits.One;
serialPort.Parity = System.IO.Ports.Parity.None;
serialPort.Handshake = System.IO.Ports.Handshake.None;
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if (this.textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.textBox1.AppendText(text);
}
}
private void serialPort_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DoUpdate));
}
private void button7_Click(object sender, EventArgs e)
{
if (serialPort.IsOpen)
{
button7.Text = "Open";
serialPort.Close();
}
else
{
button7.Text = "Close";
serialPort.Open();
}
}
private void button8_Click(object sender, EventArgs e)
{
if (serialPort.IsOpen)
serialPort.Write("Test\r\n");
}
}
My problems continue I after three day I can not find solution for my
problems with SerialPort.
Now I have written simple application that will receive and transmit data.
Connected two PCs and started testing. I can transmit, but to receive data I
have problems. If I set both PCs to the same baud rate speed and other port
settings are also the same I will not get anything. If I set the other PC to
lower speed, than I will get characters on the first PC (in .NET
application). Of course I receive garbage, but the characters are there.
Is there a any known problem with SerialPort?
Is there a working sample of the SerialPort use?
Best regards
Simon
My code:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
serialPort.PortName = "COM1";
serialPort.BaudRate = 115200;
serialPort.DataBits = 8;
serialPort.StopBits = System.IO.Ports.StopBits.One;
serialPort.Parity = System.IO.Ports.Parity.None;
serialPort.Handshake = System.IO.Ports.Handshake.None;
}
delegate void SetTextCallback(string text);
private void SetText(string text)
{
if (this.textBox1.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.Invoke(d, new object[] { text });
}
else
{
this.textBox1.AppendText(text);
}
}
private void serialPort_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DoUpdate));
}
private void button7_Click(object sender, EventArgs e)
{
if (serialPort.IsOpen)
{
button7.Text = "Open";
serialPort.Close();
}
else
{
button7.Text = "Close";
serialPort.Open();
}
}
private void button8_Click(object sender, EventArgs e)
{
if (serialPort.IsOpen)
serialPort.Write("Test\r\n");
}
}