Q:

What i can do against the following C# SerialPort Error

If I run my following Code, which I created with SharpDevelop:
        SerialPort serial = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);

        void sendMsg_Click(object sender, EventArgs e)
        {
            serial.Open();
            serial.WriteLine(textBox1.Text);
            serial.Write(new byte[] {0x0A, 0xE2, 0xFF}, 0, 3);
            serial.Close();
        }

Below is the Exception appearing while executing the code :
The Exception is the following:
System.IO.IOException: Falscher Parameter.
bei System.IO.Ports.InternalResources.WinIOError
bei System.IO.Ports.SerialStream.EndWrite
bei System.IO.Ports.SerialStream.Write
bei System.IO.Ports.SerialPort.Write
bei System.IO.Ports.SerialPort.WriteLine
bei Chat_via_RS232.MainForm.sendMsg_Click in c:\Users\admin\Documents\SharpDevelop Projects\Latias.eu IT\Chat via RS232\MainForm.cs:Zeile 35
bei System.Windows.Forms.Control.OnClick
bei System.Windows.Forms.Button.OnClick
bei System.Windows.Forms.Button.OnMouseUp
bei System.Windows.Forms.Control.WmMouseUp
bei System.Windows.Forms.Control.WndProc
bei System.Windows.Forms.ButtonBase.WndProc
bei System.Windows.Forms.Button.WndProc
bei System.Windows.Forms.Control.ControlNativeWindow.OnMessage
bei System.Windows.Forms.Control.ControlNativeWindow.WndProc
bei System.Windows.Forms.NativeWindow.DebuggableCallback
bei System.Windows.Forms.Application.ComponentManager.FPushMessageLoop
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner
bei System.Windows.Forms.Application.ThreadContext.RunMessageLoop
bei System.Windows.Forms.Application.Run
bei Chat_via_RS232.Program.Main in c:\Users\admin\Documents\SharpDevelop Projects\Latias.eu IT\Chat via RS232\Program.cs:Zeile 24

Can someone help me please.
Regards
Lala

A:

The error is on this line:
serial.WriteLine(textBox1.Text)

Your exception report shows an IOException being raised, however the documentation for WriteLine does not list IOException as a documented exception: https://msdn.microsoft.com/en-us/library/system.io.ports.serialport.writeline(v=vs.110).aspx - it's possible something else is going wrong.
The documentation for SerialPort.Open indicates if the port is unavailable then an exception is thrown there ( https://msdn.microsoft.com/en-us/library/system.io.ports.serialport.open(v=vs.110).aspx ) but this isn't happening in your program. I suspect there might be invalid values being passed into the WriteLine function. What happens if you move the Write( Byte[] ) call to before the WriteLine call?

