Exemple #1
0
    public void Send_PID()
    {
        reglage_pid pid = new reglage_pid();

        pid.id = ID;

        if (coef_P.text != "")
        {
            pid.P = float.Parse(coef_P.text, Common_settings.culture);
        }
        if (coef_I.text != "")
        {
            pid.I = float.Parse(coef_I.text, Common_settings.culture);
        }
        if (coef_D.text != "")
        {
            pid.D = float.Parse(coef_D.text, Common_settings.culture);
        }

        if (Max_Min.text != "")
        {
            pid.Min_Max = (byte)float.Parse(Max_Min.text, Common_settings.culture);
        }
        if (Cumul.text != "")
        {
            pid.Cumul = (short)float.Parse(Cumul.text, Common_settings.culture);
        }

        if (Sommation.isOn)
        {
            pid.Sommation = 1;
        }
        else
        {
            pid.Sommation = 0;
        }

        if (Enable.isOn)
        {
            pid.Enable = 1;
        }
        else
        {
            pid.Enable = 0;
        }

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame = Communication.GetTrameFromClass <reglage_pid>(pid);

        trame.Slave_Adresse  = Communication.Slave_Adresses.MultiFct_1; //uniquement la carte 1 qui gère les déplacement
        trame.Instruction    = Communication.Com_Instruction.PARAMETRES_PID;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        GameObject.FindWithTag("Communication port").GetComponent <Message_Sender>().Send_Trame(trame);
    }
    public void Send_PID()
    {
        reglage_pid pid = new reglage_pid();

        pid.id = ID;

        if (coef_P.text != "")
        {
            pid.P = Convert.ToSingle(coef_P.text.Replace('.', ','));
        }
        if (coef_I.text != "")
        {
            pid.I = Convert.ToSingle(coef_I.text.Replace('.', ','));
        }
        if (coef_D.text != "")
        {
            pid.D = Convert.ToSingle(coef_D.text.Replace('.', ','));
        }

        if (Max_Min.text != "")
        {
            pid.Min_Max = (byte)Convert.ToSingle(Max_Min.text.Replace('.', ','));
        }
        if (Cumul.text != "")
        {
            pid.Cumul = (short)Convert.ToSingle(Cumul.text.Replace('.', ','));
        }

        if (Sommation.isOn)
        {
            pid.Sommation = 1;
        }
        else
        {
            pid.Sommation = 0;
        }

        if (Enable.isOn)
        {
            pid.Enable = 1;
        }
        else
        {
            pid.Enable = 0;
        }

        Communication.Communication_Trame trame = new Communication.Communication_Trame();

        trame.Slave_Adresse  = Communication.Slave_Adresses.ALL_CARDS;
        trame.Instruction    = Communication.Com_Instruction.PARAMETRES_PID;
        trame.XBEE_DEST_ADDR = Communication.Adress_Xbee.ALL_XBEE;

        int size = Marshal.SizeOf(pid);

        byte[] arr = new byte[size];

        IntPtr ptr = Marshal.AllocHGlobal(size);

        Marshal.StructureToPtr(pid, ptr, true);
        Marshal.Copy(ptr, arr, 0, size);
        Marshal.FreeHGlobal(ptr);
        trame.Data   = arr;
        trame.Length = (byte)size;

        Communication_port.GetComponent <Communication_Send_Instructions>().Send_Instruction(trame);
    }