function setVar(Var_id,Value,COMOPT,s) % Envoie la valeur pour une variable (stand alone function) if sum(Var_id == [1:6,10,13:26]) %Var is a float Value = typecast(Value,'uint32'); end if sum(Var_id == [8,9]) %Var is a int Value = typecast(Value,'uint32'); end tmp0 = dec2hex(Var_id,2); tmp1 = dec2hex(Value,8); packet = [COMOPT.StartFrame + COMOPT.PC_MESSAGE_SET_VAR,... %Header hex2dec(tmp0(1)), hex2dec(tmp0(2)),... %1 byte with the Var_id hex2dec(tmp1(7)),hex2dec(tmp1(8)),hex2dec(tmp1(5)),hex2dec(tmp1(6)),...%4 bytes with the value hex2dec(tmp1(3)),hex2dec(tmp1(4)),hex2dec(tmp1(1)),hex2dec(tmp1(2))]; %78 56 34 12 because this corresponds to the data bytes 3 2 1 0. fwrite(s,packet); end