Пример #1
0
        private void ButtonSendStat_Click(object sender, RoutedEventArgs e)
        {
            byte[] data = new byte[20];
            byte[] floatData;
            float  value1, value2, value3, value4, value5;

            if (!Single.TryParse(TextBoxMin.Text, out value1))
            {
                MessageBox.Show("Could not parse minimum value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!Single.TryParse(TextBoxMax.Text, out value2))
            {
                MessageBox.Show("Could not parse maximum value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!Single.TryParse(TextBoxAvg.Text, out value3))
            {
                MessageBox.Show("Could not parse average value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!Single.TryParse(TextBoxRange.Text, out value4))
            {
                MessageBox.Show("Could not parse range value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            if (!Single.TryParse(TextBoxSTD.Text, out value5))
            {
                MessageBox.Show("Could not parse standard deviation value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            // set floats
            floatData = BitConverter.GetBytes(value1);
            data[0]   = floatData[0];
            data[1]   = floatData[1];
            data[2]   = floatData[2];
            data[3]   = floatData[3];
            floatData = BitConverter.GetBytes(value2);
            data[4]   = floatData[0];
            data[5]   = floatData[1];
            data[6]   = floatData[2];
            data[7]   = floatData[3];
            floatData = BitConverter.GetBytes(value3);
            data[8]   = floatData[0];
            data[9]   = floatData[1];
            data[10]  = floatData[2];
            data[11]  = floatData[3];
            floatData = BitConverter.GetBytes(value4);
            data[12]  = floatData[0];
            data[13]  = floatData[1];
            data[14]  = floatData[2];
            data[15]  = floatData[3];
            floatData = BitConverter.GetBytes(value5);
            data[16]  = floatData[0];
            data[17]  = floatData[1];
            data[18]  = floatData[2];
            data[19]  = floatData[3];

            if (!CommandHost.SendStat(_uart, data))
            {
                MessageBox.Show("Transmission error sending data packet.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }