J
jodleren
Hi all
I have programmed for 20 years, but only little in C/C++ and even less
in C#. I am learning the hard way now.
Right, to the issue:
I have create a small app, which should communicate with a PCB.
We use a FreeRTOS CDC demo to access the PCB. The connection is
actually by USB.
In Hyperterminal and a Delphi app I have no problems.
However, in C# I can open the port, but my app stops when writing to
the com port.
Using COM1, a real port with a null modem it works.
Usinc COM3 for my PCB, I can see that it gets some data, as I cannot
access it afterwards from any other app. I have to restart the PCB. I
asume that it sends one byte but the waits for something.
Still, I dont get it.
I am lost - any ideas?
Sonnich
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM3";
serialPort1.BaudRate = 9600;
serialPort1.Parity = System.IO.Ports.Parity.None;
serialPort1.StopBits = System.IO.Ports.StopBits.One;
serialPort1.DataBits = 8;
serialPort1.Open();
button1.Enabled = !serialPort1.IsOpen;
}
private void serialPort1_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
int count = (sender as SerialPort).BytesToRead;
byte[] buffer = new byte[count];
int offset = 0;
serialPort1.Read(buffer, offset, count);
if (label1.InvokeRequired)
{
BeginInvoke(new MethodInvoker(delegate()
{
label1.Text = Encoding.ASCII.GetString(buffer);
label1.Text = label1.Text + " " +
count.ToString();
}));
}
else
{
label1.Text = buffer.ToString(); //.Trim()
//label1.Text = label1.Text + " " + count.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Write("!VERSION\r"); <- stops here
label1.Text = "sent";
}
I have programmed for 20 years, but only little in C/C++ and even less
in C#. I am learning the hard way now.
Right, to the issue:
I have create a small app, which should communicate with a PCB.
We use a FreeRTOS CDC demo to access the PCB. The connection is
actually by USB.
In Hyperterminal and a Delphi app I have no problems.
However, in C# I can open the port, but my app stops when writing to
the com port.
Using COM1, a real port with a null modem it works.
Usinc COM3 for my PCB, I can see that it gets some data, as I cannot
access it afterwards from any other app. I have to restart the PCB. I
asume that it sends one byte but the waits for something.
Still, I dont get it.
I am lost - any ideas?
Sonnich
private void button1_Click(object sender, EventArgs e)
{
serialPort1.PortName = "COM3";
serialPort1.BaudRate = 9600;
serialPort1.Parity = System.IO.Ports.Parity.None;
serialPort1.StopBits = System.IO.Ports.StopBits.One;
serialPort1.DataBits = 8;
serialPort1.Open();
button1.Enabled = !serialPort1.IsOpen;
}
private void serialPort1_DataReceived(object sender,
System.IO.Ports.SerialDataReceivedEventArgs e)
{
int count = (sender as SerialPort).BytesToRead;
byte[] buffer = new byte[count];
int offset = 0;
serialPort1.Read(buffer, offset, count);
if (label1.InvokeRequired)
{
BeginInvoke(new MethodInvoker(delegate()
{
label1.Text = Encoding.ASCII.GetString(buffer);
label1.Text = label1.Text + " " +
count.ToString();
}));
}
else
{
label1.Text = buffer.ToString(); //.Trim()
//label1.Text = label1.Text + " " + count.ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
serialPort1.Write("!VERSION\r"); <- stops here
label1.Text = "sent";
}