Esempio n. 1
0
        public FrmMain()
        {
            InitializeComponent();
            BaudRate = 9600;
            PortName = "COM7";
            tbBaudRate.Text = BaudRate.ToString(CultureInfo.InvariantCulture);
            tbPortName.Text = PortName;

            CheckConnection();
            _curtain.OnPositionChanged += CurtainPositionChangedHandler;

            var mrl = new List<MovementRequest>();

            using (var file = new StreamReader(Environment.CurrentDirectory + "\\" + "MovementRequests.txt"))
            {
                string line;
                while ((line = file.ReadLine()) != null)
                {
                    string[] linePrams = line.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries);
                    if (linePrams.Length != 3)
                        continue;
                    var mr = new MovementRequest
                    {
                        Position = Convert.ToInt32(linePrams[2]),
                        Day = (DayOfWeek) Convert.ToInt32(linePrams[0]),
                        Time = TimeSpan.Parse(linePrams[1])
                    };
                    mrl.Add(mr);
                    //MessageBox.Show(line);
                }

                file.Close();
            }

            if (mrl.Count > 0)
            {
                _curtain.StartPending(mrl);
            }
        }
Esempio n. 2
0
        public void StartPending(List <MovementRequest> list)
        {
            Thread t = new Thread(() =>
            {
                while (true)
                {
                    IOrderedEnumerable <MovementRequest> next = from x in list
                                                                where x.Day == DateTime.Now.DayOfWeek && x.Time >= DateTime.Now - DateTime.Today
                                                                orderby x.Time ascending
                                                                select x;

                    if (next.Any())
                    {
                        MovementRequest r = next.First();
                        Thread.Sleep(DateTime.Today + r.Time - DateTime.Now);
                        try
                        {
                            MoveToPosition(r.Position);
                        }
                        catch (Exception)
                        {
                        }
                        //Console.WriteLine(r.Position);
                    }
                    else
                    {
                        Thread.Sleep(DateTime.Today.AddDays(1) - DateTime.Now);
                    }
                }
                return;
            })
            {
                IsBackground = true
            };

            t.Start();
        }