4-Opisanie_Programmy_final (1061499), страница 4
Текст из файла (страница 4)
TextBox1.SelectionColor = _messageColor[(int) type];
TextBox1.AppendText(msg);
TextBox1.ScrollToCaret();
}));
else
TextBox2.Invoke(new EventHandler(delegate
{
TextBox2.SelectedText = string.Empty;
TextBox2.SelectionFont = new Font(TextBox2.SelectionFont, FontStyle.Bold);
TextBox2.SelectionColor = _messageColor[(int) type];
TextBox2.AppendText(msg);
TextBox2.ScrollToCaret();
}));
}
public void WriteData(string msg, FrameType currentFrameType, bool msgNoDisplay, SerialPort comPort)
{
lastMsg = msg;
var frameFields = new List<byte> {Start, (byte) currentFrameType};
switch (currentFrameType)
{
case FrameType.DAT:
try
{
if (string.IsNullOrEmpty(msg))
return;
frameFields.AddRange(_coder.CodeString(msg));
comPort.Write(frameFields.ToArray(), 0, frameFields.Count);
if (!msgNoDisplay)
{
DisplayData(MessageType.Outgoing, DateTime.Now + " " + currentFrameType + "\n", false);
DisplayData(MessageType.Outgoing, "\n[ " + DateTime.Now + " ] \n" + msg.Substring(1), true);
}
}
catch (FormatException ex)
{
DisplayData(MessageType.Error, ex.Message, false);
}
break;
default:
if (comPort.IsOpen != true) comPort.Open();
comPort.Write(frameFields.ToArray(), 0, 2);
if (!msgNoDisplay)
DisplayData(MessageType.Outgoing, DateTime.Now + " " + currentFrameType + "\n", false);
break;
}
}
}
}
















