private void UpdateCommandDataDisplay(MDACommand LocalMDACommand) { AxText.BeginInvoke(new InvokeDelegateFloat(UpdateAx), LocalMDACommand.a_x); AyText.BeginInvoke(new InvokeDelegateFloat(UpdateAy), LocalMDACommand.a_y); AzText.BeginInvoke(new InvokeDelegateFloat(UpdateAz), LocalMDACommand.a_z); ArollText.BeginInvoke(new InvokeDelegateFloat(UpdateAroll), LocalMDACommand.a_roll); ApitchText.BeginInvoke(new InvokeDelegateFloat(UpdateApitch), LocalMDACommand.a_pitch); AyawText.BeginInvoke(new InvokeDelegateFloat(UpdateAyaw), LocalMDACommand.a_yaw); VrollText.BeginInvoke(new InvokeDelegateFloat(UpdateVroll), LocalMDACommand.v_roll); VpitchText.BeginInvoke(new InvokeDelegateFloat(UpdateVpitch), LocalMDACommand.v_pitch); VyawText.BeginInvoke(new InvokeDelegateFloat(UpdateVyaw), LocalMDACommand.v_yaw); RollText.BeginInvoke(new InvokeDelegateFloat(UpdateRoll), LocalMDACommand.roll); PitchText.BeginInvoke(new InvokeDelegateFloat(UpdatePitch), LocalMDACommand.pitch); YawText.BeginInvoke(new InvokeDelegateFloat(UpdateYaw), LocalMDACommand.yaw); TimeOffsetText.BeginInvoke(new InvokeDelegateTextString(UpdateTextBoxValue), TimeOffsetText, recvDeltaTime.ToString("0.000")); if (LocalMDACommand.MCW == 0x36) //Control Input Data sent also { XPRollRatioText.BeginInvoke(new InvokeDelegateTextString(UpdateTextBoxValue), XPRollRatioText, (LocalMDACommand.buffet_roll).ToString()); XPPitchRatioText.BeginInvoke(new InvokeDelegateTextString(UpdateTextBoxValue), XPPitchRatioText, (LocalMDACommand.buffet_pitch).ToString()); XPYawRatioText.BeginInvoke(new InvokeDelegateTextString(UpdateTextBoxValue), XPYawRatioText, (LocalMDACommand.buffet_yaw).ToString()); } }
//Returns array of bytes from MDACommand structure to send to MOOG byte[] getBytes(MDACommand str) { int size = Marshal.SizeOf(str); byte[] arr = new byte[size]; IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(str, ptr, true); Marshal.Copy(ptr, arr, 0, size); Marshal.FreeHGlobal(ptr); return arr; }
byte[] flipStrBytes(MDACommand str) { byte[] arr = getBytes(str); byte[] new_arr = new byte[arr.Length]; for (int j = 0; j < arr.Length; j = j + 4) { for (int i = 0; i < 4; i++) { new_arr[i + j] = arr[3 - i + j]; } //for } //for return new_arr; }
//Returns MDACommand structure from array of bytes MDACommand fromBytes(byte[] arr) { MDACommand str = new MDACommand(); int size = Marshal.SizeOf(str); IntPtr ptr = Marshal.AllocHGlobal(size); Marshal.Copy(arr, 0, ptr, size); str = (MDACommand)Marshal.PtrToStructure(ptr, str.GetType()); Marshal.FreeHGlobal(ptr); return str; }
public ControlGUI() { InitializeComponent(); //C# automatic form Stuff CurrentMDACommand = new MDACommand(); MotionInputBytes = getBytes(CurrentMDACommand); InitializeThread(); cmb_Connection.Items.AddRange(SerialPort.GetPortNames()); cmb_ArduinoConnection.Items.AddRange(SerialPort.GetPortNames()); }