Reputation: 11
Sorry for possible wrong spelling i'm not a native english speaker.
Software written in C# with VisualStudio Community 2015 and .net 4.0. Reading Serial communication with Free Device Monitoring Studio.
USB to RS232 Dongle LogiLink FTDI-Chipset due to no RS232 port available on Notebook.
namespace Serial_Test
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_FormClosed(object sender, System.Windows.Forms.FormClosedEventArgs e)
{
if ((SerialPort1.IsOpen == true))
{
SerialPort1.Close();
}
}
private void button1_Click(object sender, EventArgs e)
{
SerialPort1.PortName = "COM5";
SerialPort1.BaudRate = 9600;
SerialPort1.Parity = Parity.None;
SerialPort1.DataBits = 8;
SerialPort1.StopBits = StopBits.One;
SerialPort1.Handshake = Handshake.None;
if ((SerialPort1.IsOpen == false))
{
SerialPort1.Open();
}
}
private void button2_Click(object sender, EventArgs e)
{
if ((SerialPort1.IsOpen == true))
{
SerialPort1.Write(" --Aus C#-- ");
MessageBox.Show("Data send");
}
}
private void button3_Click(object sender, EventArgs e)
{
if ((SerialPort1.IsOpen == true))
{
SerialPort1.Close();
}
}
}
}
This runs without any errors but won't send Data. But it won't even echo data from a serial port that is not connected to anything.
Then, after closing my program and sending data from any other program (in this case self written VBS) over the same COM port it will send the data that should have been sent before attached to the new data.
I tried 3 different dongles allready (from 20€ to 200€) and got the same problem over and over again.
Upvotes: 1
Views: 908
Reputation: 11
I solved it!
This didn't work:
_SP.Write("VERSION?" + "\r");
This works all fine!
byte[] buffer = new byte[9];
buffer[0] = 0x56;
buffer[1] = 0x45;
buffer[2] = 0x52;
buffer[3] = 0x53;
buffer[4] = 0x49;
buffer[5] = 0x4f;
buffer[6] = 0x4e;
buffer[7] = 0x3f;
buffer[8] = 0x0d;
string text = buffer.ToString();
_SP.Write(buffer,0,9);
Serial Port settings stayed the same. Can somebody explain this behaviour?
Upvotes: 0
Reputation: 190976
You could try calling .Flush
off of your serial port instance. That clears any buffers.
Upvotes: 0