Functions that can use instead of setmode()

Greetings.

below is my mission planner plugin code.

When I use this code there is always warning in the console that “setmode” function is obsolete.

is there any alternative for this function?

Thank you very much in advance.

public void changeModeToRTL_FD_Click(object sender, EventArgs e)
{
    foreach (MAVLinkInterface mav in MainV2.Comports)
    {
       if (mav.sysidcurrent != 0)
       {
            if (mav.MAV.cs.firmware == MissionPlanner.ArduPilot.Firmwares.ArduPlane)
            {
               try
               {
                   mav.setMode("RTL");//obsolete.
               }
              catch
               {
                   MessageBox.Show("Failed to change mode to RTL");
               }
             }
        }
     }
 }

If you look at the Mission Planner code, you can see why it is obsolete…

       [Obsolete]
       public void setMode(string modern)
       {
           setMode(MAV.sysid, MAV.compid, modein);
       }

       public void setMode(byte sysid, byte compid, string modein)
       {
           mavlink_set_mode_t mode = new mavlink_set_mode_t();

           if (translateMode(sysid, compid, modein, ref mode))
           {
               log.Info("setMode " + modein + " (" + mode.custom_mode + ")");
               setMode(sysid, compid, mode);
           }
       }

It’s been replaced with a function where you have to add the sysid and the compiid. You should use this format…

1 Like

Thank you very much.

As I’m now on south pacific, on the ship, I was not available on the internet, it was hard to look through github for code…

You always give me lots of help. Thanks.