Beispiel #1
0
        //Выполнение команды
        private void Button1_Click_1(object sender, EventArgs e)
        {
            if (portStatus.Text == "Порт закрыт")
            {
                MessageBox.Show("Откройте порт");
            }
            else if (command.Text == "")
            {
                MessageBox.Show("Выберите команду");
            }
            else
            {
                HighLevel high = new HighLevel();

                byte[]   workBytes = new byte[] { };
                ushort   ush1, ush2, ush3, ush4;
                byte     by1, by2, by3, by4, by5, by6, by7, by8;
                string[] decodeText;

                try
                {
                    switch (CommandIndex)
                    {
                    case 2:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Second(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 3:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Third(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        workBytes  = Decode.GetAnswerBytes(workBytes, numberParity: true);
                        decodeText = Decode.DecodeThird(workBytes);

                        ShowAnswerText(decodeText);


                        break;

                    case 4:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Fourth(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        workBytes  = Decode.GetAnswerBytes(workBytes, numberParity: true);
                        decodeText = Decode.DecodeFourth(workBytes);

                        ShowAnswerText(decodeText);

                        break;

                    case 5:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Fifth(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        workBytes  = Decode.GetAnswerBytes(workBytes);
                        decodeText = Decode.DecodeFifth(workBytes);

                        ShowAnswerText(decodeText);

                        break;

                    case 6:

                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Sixth(ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 7:

                        workBytes = high.Seventh();
                        ShowAnswerBytes(workBytes);

                        workBytes = Decode.GetAnswerBytes(workBytes);

                        decodeText = Decode.DecodeSeventh(workBytes[0]);

                        ShowAnswerText(decodeText);

                        break;

                    case 8:

                        ush1 = ushort.Parse(ushort1.Text);
                        by1  = byte.Parse(byte1.Text);
                        by2  = byte.Parse(byte2.Text);

                        workBytes = high.Eighth(ush1, by1, by2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 9:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        ush3 = ushort.Parse(ushort3.Text);

                        workBytes = high.Nineth(by1, ush1, ush2, ush3);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 10:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        ush3 = ushort.Parse(ushort3.Text);
                        by3  = byte.Parse(byte3.Text);
                        by4  = byte.Parse(byte4.Text);
                        by5  = byte.Parse(byte5.Text);
                        by6  = byte.Parse(byte6.Text);
                        by7  = byte.Parse(byte7.Text);
                        by8  = byte.Parse(byte8.Text);

                        workBytes = high.Tenth(by1, ush1, ush2, ush3, by3, by4, by5, by6, by7, by8);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 11:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Eleventh(by1, ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 16:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        ush3 = ushort.Parse(ushort3.Text);
                        ush4 = ushort.Parse(ushort4.Text);

                        workBytes = high.Sixteenth(by1, ush1, ush2, ush3, ush4);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 17:

                        workBytes = high.Seventeenth();
                        ShowAnswerBytes(workBytes);

                        break;

                    case 18:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);

                        workBytes = high.Eightteenth(by1, ush1, ush2);
                        ShowAnswerBytes(workBytes);

                        break;

                    case 19:

                        by1  = byte.Parse(byte1.Text);
                        ush1 = ushort.Parse(ushort1.Text);
                        ush2 = ushort.Parse(ushort2.Text);
                        by3  = byte.Parse(byte3.Text);
                        by4  = byte.Parse(byte3.Text);
                        by5  = byte.Parse(byte3.Text);
                        by6  = byte.Parse(byte3.Text);

                        workBytes = high.Nineteenth(by1, ush1, ush2, by3, by4, by5, by6);
                        ShowAnswerBytes(workBytes);

                        break;
                    }
                }
                catch (OverflowException)
                {
                    MessageBox.Show("Слишком большое или слишком маленькое значение одного из аргументов,OfverflowException");
                }
                catch (ArgumentException)
                {
                    MessageBox.Show("Один из аргументов имеет недопустимый формат,ArgumentException");
                }
                catch (FormatException)
                {
                    MessageBox.Show("Введите корректные значения,FormatException");
                }
            }
        }