コード例 #1
0
        /// <summary>
        /// OnClick handler for "Write To Emulator Serial Port" menu item. It launches a
        /// SendToSerialPortDialogBox to get the string, and send the string to the emulator
        /// serial port using its StreamOut stream (from the inherited ComPortToMemoryStream).
        /// </summary>
        /// <param name="sender">the menu item that was clicked</param>
        /// <param name="e">Not used</param>
        private void WriteToEmulatorSerialPortOnClick(Object sender, EventArgs e)
        {
            ToolStripItem item = sender as ToolStripItem;

            if (item != null)
            {
                EmulatorSerialPort esp = emulatorSPs[item.Name];

                try
                {
                    SendToSerialPortDialogBox sendToSerialPortDialogBox = new SendToSerialPortDialogBox();

                    if (sendToSerialPortDialogBox.ShowDialog() == DialogResult.OK)
                    {
                        byte[] data = Encoding.UTF8.GetBytes(sendToSerialPortDialogBox.TextToSend);
                        esp.StreamOut.Write(data, 0, data.Length);
                        esp.StreamOut.Flush();
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                    return;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// OnClick handler for "Write To Emulator Serial Port" menu item. It launches a 
        /// SendToSerialPortDialogBox to get the string, and send the string to the emulator
        /// serial port using its StreamOut stream (from the inherited ComPortToMemoryStream).
        /// </summary>
        /// <param name="sender">the menu item that was clicked</param>
        /// <param name="e">Not used</param>
        private void WriteToEmulatorSerialPortOnClick(Object sender, EventArgs e)
        {
            ToolStripItem item = sender as ToolStripItem;
            if (item != null)
            {
                EmulatorSerialPort esp = emulatorSPs[item.Name];

                try
                {
                    SendToSerialPortDialogBox sendToSerialPortDialogBox = new SendToSerialPortDialogBox();

                    if (sendToSerialPortDialogBox.ShowDialog() == DialogResult.OK)
                    {
                        byte[] data = Encoding.UTF8.GetBytes(sendToSerialPortDialogBox.TextToSend);
                        esp.StreamOut.Write(data, 0, data.Length);
                        esp.StreamOut.Flush();
                    }
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.ToString());
                    return;
                }
            }
        }