Ejemplo n.º 1
0
        private void btnReadParam_Click(object sender, EventArgs e)
        {
            if (_serialPort == null)
            {
                Log("Serial port is not connected.", Color.Red);
                return;
            }
            if (cmbParameter.SelectedIndex < 0)
            {
                Log("Select a parameter.", Color.Red);
                return;
            }

            try
            {
                Read_Param command = new Read_Param();
                if (!InitCommand(command))
                {
                    return;
                }
                try
                {
                    command.Parameter      = new DriveParameter();
                    command.Parameter.Type = (DriveParameterType)Enum.Parse(typeof(DriveParameterType), cmbParameter.SelectedItem.ToString());
                }
                catch (Exception ex)
                {
                    Log(ex.Message, Color.Red);
                    return;
                }

                command.Send(_serialPort);
                if (!command.Receive(_serialPort))
                {
                    return;
                }
                Log(command.ToString(), Color.Black);
            }
            catch (Exception ex)
            {
                Log(ex.Message, Color.Red);
                Log(ex.StackTrace, Color.Red);
            }
        }
Ejemplo n.º 2
0
        private void btnReadParam_Click(object sender, EventArgs e)
        {
            if (_serialPort == null)
            {
                Log("Serial port is not connected.", Color.Red);
                return;
            }
            if (cmbParameter.SelectedIndex < 0)
            {
                Log("Select a parameter.", Color.Red);
                return;
            }

            try
            {
                Read_Param command = new Read_Param();
                if (!InitCommand(command))
                    return;
                try
                {
                    command.Parameter = new DriveParameter();
                    command.Parameter.Type = (DriveParameterType)Enum.Parse(typeof(DriveParameterType), cmbParameter.SelectedItem.ToString());
                }
                catch (Exception ex)
                {
                    Log(ex.Message, Color.Red);
                    return;
                }

                command.Send(_serialPort);
                if (!command.Receive(_serialPort))
                    return;
                Log(command.ToString(), Color.Black);
            }
            catch (Exception ex)
            {
                Log(ex.Message, Color.Red);
                Log(ex.StackTrace, Color.Red);
            }
        }