Если я запускаю свой следующий код, который я создал с помощью 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();
}
Ниже показано исключение, возникающее при выполнении кода:
Исключением является следующее:
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
Может кто-то мне помочь, пожалуйста.
С уважением
Лала
textBox1.Text
при возникновении ошибки? - person Dai   schedule 30.01.2017SerialPort.Close
, то это проблема с параметрами, которые вы передаете методуOpen
. MSDN говорит, что будет выдана ошибка IOException, если попытка установить состояние базового порта не удалась. Например, параметры, переданные из этого объекта SerialPort, недействительны - person Pikoh   schedule 30.01.2017SerialPort
только имя порта и посмотреть, не получите ли вы таким образом ошибку?SerialPort serial = new SerialPort("COM2");
- person Pikoh   schedule 30.01.2017