private void ButtonSendDataPacket_Click(object sender, RoutedEventArgs e) { byte[] data = new byte[12]; byte[] floatData; int hours, minutes, seconds; float value1, value2; if (!Single.TryParse(TextBoxTemp1.Text, out value1)) { MessageBox.Show("Could not parse temperature 1 value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (!Single.TryParse(TextBoxTemp2.Text, out value2)) { MessageBox.Show("Could not parse temperature 2 value.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } // upper byte not used data[0] = 0; hours = DateTime.Now.Hour; minutes = DateTime.Now.Minute; seconds = DateTime.Now.Second; // set time data[1] = (byte)hours; data[2] = (byte)minutes; data[3] = (byte)seconds; // set floats floatData = BitConverter.GetBytes(value1); data[4] = floatData[0]; data[5] = floatData[1]; data[6] = floatData[2]; data[7] = floatData[3]; floatData = BitConverter.GetBytes(value2); data[8] = floatData[0]; data[9] = floatData[1]; data[10] = floatData[2]; data[11] = floatData[3]; if (!CommandHost.SendDataPacket(_uart, data)) { MessageBox.Show("Transmission error sending data packet.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
public void Each_Tick(object o, EventArgs sender) { int temp1 = rnd1.Next(Min, Max); int temp2 = rnd2.Next(Min, Max); byte[] data = new byte[12]; byte[] floatData; int hours, minutes, seconds; // upper byte not used data[0] = 0; hours = DateTime.Now.Hour; minutes = DateTime.Now.Minute; seconds = DateTime.Now.Second; // set time data[1] = (byte)hours; data[2] = (byte)minutes; data[3] = (byte)seconds; // set floats floatData = BitConverter.GetBytes(temp1); data[4] = floatData[0]; data[5] = floatData[1]; data[6] = floatData[2]; data[7] = floatData[3]; floatData = BitConverter.GetBytes(temp2); data[8] = floatData[0]; data[9] = floatData[1]; data[10] = floatData[2]; data[11] = floatData[3]; if (!CommandHost.SendDataPacket(_uart, data)) { MessageBox.Show("Transmission error sending data packet.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }