Premier exemple (en WPF)

Ajouter un bouton sur la partie form

Puis le code

MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EngineIO;


namespace testHomeIo
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private bool ft1 = false;
        private bool ft2 = false;
        private bool X1 = true;
        private bool X2 = false;
        private bool front = false;
        private bool bpPrec = false;
        private bool bp;

        private MemoryBit lampe;

        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
            dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(20);
            dispatcherTimer.Start();

            //conditions initiales
            this.X1 = true;
            this.X2 = false;
            this.bpPrec = false;
            this.lampe = MemoryMap.Instance.GetBit(0, MemoryType.Output);

        }

        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("tick");
            this.runCycleApi();
        }

        private void runCycleApi()
        {
            //mise à jour HomeIO
            MemoryMap.Instance.Update();

            bpPrec = this.bp;
            //lecture des entrées
            this.bp = MemoryMap.Instance.GetBit(2, MemoryType.Input).Value;

            //calculs des FTs
            this.front = !this.bpPrec && this.bp;

            this.ft1 = this.X1 && this.front;
            this.ft2 = this.X2 && this.front;
            //calculs des étapes
            this.X1 = this.ft2 || this.X1 && !this.ft1;
            this.X2 = this.ft1 || this.X2 && !this.ft2;

            //écriture des sorties
            lampe.Value = X2;

            //mise à jour HomeIO
            MemoryMap.Instance.Update();
        }
    }
}

Last updated