Exemplo n.º 1
0
        public async void Init()
        {
            Status.Text = "Establishing Connection";
            await Task.Run(() => Thread.Sleep(1000));

            await Task.Run(() => IoSerial.Instance.FindAndConnect());

            rounds = 0;
            Designer designer = (Designer)App.Current.MainWindow;

            Status.Text = "Switching Device To Wireless Context";
            Thread.Sleep(1000);
            IoSerial.Instance.Write("00", CommandType.Wireless);
            Thread.Sleep(1000);
            Status.Text = "Starting Sweep Scan";

            IoSerial.Instance.Write("10", CommandType.Command);
            ReaderFunctionIndex1 = Convert.ToInt32(1 + 0.ToString());
            ReaderFunctionIndex2 = Convert.ToInt32(1 + 1.ToString());
            IoSerial.Instance.NewMessageArrived += InstanceOnNewMessageArrived;
            IoSerial.Instance.Write(ReaderFunctionIndex1.ToString(), CommandType.Command);

            MapCanvas.Children.Add(poly);
            poly.Fill            = designer.backgroundColorPanel.Background;
            poly.Stroke          = designer.foregroundColorPanel.Background;
            poly.StrokeThickness = 1;
            poly.FillRule        = FillRule.Nonzero;
            IoSerial.Instance.Write("11", CommandType.Command);
            GrdStartup.Visibility = Visibility.Hidden;
        }
        private void InstanceOnNewMessageArrived(Message msg)
        {
            if (msg != null && msg.Command != String.Empty)
            {
                try
                {
                    if (msg.Response.FunctionIndex == ReaderFunctionIndex1.ToString())
                    //update the events if the this is the right sensor
                    {
                        prevMessage = msg;
                    }
                    if (msg.Response.FunctionIndex == ReaderFunctionIndex2.ToString() && prevMessage != null)
                    {
                        CurrentValue = Convert.ToInt32(Response.GetResponse(msg).Value);
                        double position = Convert.ToDouble(Response.GetResponse(prevMessage).Value);
                        double distance = Convert.ToDouble(Response.GetResponse(msg).Value);
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            distance         = (int)((distance / 100.0) * 50);
                            txtDistance.Text = distance.ToString();


                            txtStatus.Text = "Completed!";
                        }));
                        prevMessage = null;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Exemplo n.º 3
0
        private void InstanceOnNewMessageArrived(Message msg)
        {
            if (msg != null && msg.Command != String.Empty)
            {
                try
                {
                    if (msg.Response.FunctionIndex == ReaderFunctionIndex1.ToString())
                    //update the events if the this is the right sensor
                    {
                        prevMessage = msg;
                    }
                    if (msg.Response.FunctionIndex == ReaderFunctionIndex2.ToString() && prevMessage != null)
                    {
                        CurrentValue = Convert.ToInt32(Response.GetResponse(msg).Value);
                        double position = Convert.ToDouble(Response.GetResponse(prevMessage).Value);
                        double distance = Convert.ToDouble(Response.GetResponse(msg).Value);
                        Application.Current.Dispatcher.BeginInvoke(new Action(() =>
                        {
                            distance = (int)((distance / 100.0) * 50);


                            prog.Maximum     = 170;
                            prog.Value       = position;
                            txtStatus.Text   = "Scanning";
                            txtDegrees.Text  = position + "°";
                            txtDistance.Text = distance + "m";
                            Point p2;
                            p2 = new Point((int)(MapCanvas.ActualWidth / 2.0 - distance * Math.Cos(Math.PI * position / 180)),
                                           (int)(MapCanvas.ActualHeight / 2.0 - distance * Math.Sin(Math.PI * position / 180)));
                            poly.Points.Add(p2);
                            if (position > 180)
                            {
                                Grid.IsEnabled = true;
                            }
                        }));
                        prevMessage = null;
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
 /// <summary>
 ///     Initialize the contnous sensor loop.
 ///     This method must not be used if sensor was initialized with continous mode.
 /// </summary>
 /// <param name="readinterval"></param>
 public void StartContinousReading(long readinterval)
 {
     // IoSerial.Instance.Write(ReaderFunctionIndex2.ToString(), CommandType.Command);
     IoSerial.Instance.Write(ReaderFunctionIndex1.ToString(), CommandType.Command);
 }