public void GenerateMessageSetVlimit(object sender, DoubleArgs e) { byte[] payload = new byte[4]; payload = ((float)(e.Value)).GetBytes(); OnMessageToRespirator((Int16)Commands.SetVlimit, 4, payload); }
public void GenerateMessageSetSeuilDetection(object sender, DoubleArgs e) { byte[] payload = new byte[4]; payload = ((float)(e.Value * 100)).GetBytes(); OnMessageToRespirator((Int16)Commands.SetSeuilAssistance, 4, payload); }
//Methode appelée sur evenement (event) provenant du port Serie. //Cette methode est donc appelée depuis le thread du port Serie. Ce qui peut poser des problemes d'acces inter-thread public void ActualizeSpeed(object sender, DoubleArgs e) { //La solution consiste a passer par un delegué qui executera l'action a effectuer depuis le thread concerné. //Ici, l'action a effectuer est la modification d'un bouton. Ce bouton est un objet UI, et donc l'action doit etre executée depuis un thread UI. //Sachant que chaque objet UI (d'interface graphique) dispose d'un dispatcher qui permet d'executer un delegué (une methode) depuis son propre thread. //La difference entre un Invoke et un beginInvoke est le fait que le Invoke attend la fin de l'execution de l'action avant de sortir. labelSpeed.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(delegate() { labelSpeed.Content = Convert.ToString(e.Value); })); }
public override IFeedBack ProcessCommand(TcpServer Server, string[] args) { if (ArgumentsValidation(args)) { DoubleArgs firstArg = Inputs[0] as DoubleArgs; DoubleArgs secondArg = Inputs[1] as DoubleArgs; string result = Server.Adder(double.Parse(firstArg.GetValue()), double.Parse(secondArg.GetValue())).ToString(); return(new ValidFeedBack(string.Format("Result is: {0}", result))); } return(InvalidInputParameter()); }
// Создаем метод, который принимает делегат // То есть на практике, этот метод сможет принимать любой метод // с такой же сигнатурой как у делегата public static void Table(DoubleArgs D, double x, double a, double b) { Console.WriteLine("----- X ----- A ----- Y -----"); while (x <= b) { //внимание трюк - а заменяется на i чтобы не переписывать значение входящей переменной в итерации for (double i = a; i <= b; i++) { Console.WriteLine("| {0,8:0.000} | {1,8:0.000} | {2,8:0.000} |", x, i, D(x, i)); } x++; } Console.WriteLine("---------------------"); }