public void Read()
        {
            while (_continueReading)
            {
                try
                {
                    String message = _serialPort.ReadLine();
                    Debug.Write("received Serial Data:");
                    Debug.WriteLine(message);

                    String[] substrings = message.Split(':');

                    if (substrings[0].CompareTo("position") == 0)
                    {
                        double x = Convert.ToDouble(substrings[1]);
                        double y = Convert.ToDouble(substrings[2]);
                        double z = Convert.ToDouble(substrings[3]);

                        PositionEventArgs e = new PositionEventArgs(x, y, z);


                        OnPositionEvent(e);
                    }
                }
                catch (TimeoutException)
                {
                    this.Disconnect();
                }
                catch (System.UnauthorizedAccessException)
                {
                    this.Disconnect();
                }
            }
        }
 public void OnPositionEvent(PositionEventArgs e)
 {
     // checks if the event has an subscriber
     if (PositionEvent != null)
     {
         PositionEvent(this, e);
     }
 }
示例#3
0
        void PositionEventHandler(object sender, PositionEventArgs e)
        {
            if (this.InvokeRequired == true)
            {
                Debug.WriteLine("positionData: callback required");

                positionCallback callback = new positionCallback(PositionEventHandler);
                this.Invoke(callback, sender, e);
            }
            else
            {
                Debug.WriteLine("positionData: NO callback required");


                Debug.WriteLine("received positionEvent:");
                Debug.Write("x:");
                Debug.WriteLine(e.xPosition);
                Debug.Write("y:");
                Debug.WriteLine(e.yPosition);
                Debug.Write("z:");
                Debug.WriteLine(e.zPosition);

                Thread thread = Thread.CurrentThread;
                String msg    = String.Format("   Thread ID: {0}\n", thread.ManagedThreadId);

                Debug.WriteLine(msg);


                if (waitForTimeKeepPosition == true)
                {
                    waitForTimeKeepPosition = false;

                    int i = 0;
                    foreach (var issueControl in this.issueControls)
                    {
                        Debug.WriteLine(issueControl.IssueKey);

                        if (issueControl.IssueKey.CompareTo(issueKeyForNewPosition) == 0)
                        {
                            Debug.Write("set position data for issue: ");
                            Debug.Write(issueControl.IssueKey);

                            //issueControl.IssueKey = "testEmi";

                            issueControl.timeKeepData.x           = e.xPosition;
                            issueControl.timeKeepData.y           = e.yPosition;
                            issueControl.timeKeepData.z           = e.zPosition;
                            issueControl.timeKeepData.positionSet = true;
                            issueControl.SetTrackerColor();
                            break;
                        }
                        i++;
                    }
                }
                else
                {
                    double threshold    = 50;
                    int    i            = 0;
                    bool   timerStarted = false;
                    String issueStarted = "";
                    foreach (var issueControl in this.issueControls)
                    {
                        try
                        {
                            timerStarted = false;
                            //first check if position-time-tracking is enabled for the current issueControl

                            if (issueControl.timeKeepData.positionSet == true)
                            {
                                if ((issueControl.timeKeepData.x < e.xPosition + threshold) & (issueControl.timeKeepData.x > e.xPosition - threshold))
                                {
                                    if ((issueControl.timeKeepData.y < e.yPosition + threshold) & (issueControl.timeKeepData.y > e.yPosition - threshold))
                                    {
                                        if ((issueControl.timeKeepData.z < e.zPosition + threshold) & (issueControl.timeKeepData.z > e.zPosition - threshold))
                                        {
                                            Debug.Write("current position matches to this issue: ");
                                            Debug.Write(issueControl.IssueKey);

                                            issueStarted = issueControl.IssueKey;

                                            issueControl.WatchTimer.GetState();
                                            issueControl.Start();

                                            timerStarted = true;
                                        }
                                    }
                                }
                            }

                            //stop timer if timer wasn't started
                            if (timerStarted == false)
                            {
                                issueControl.Pause();
                            }
                        }
                        catch (Exception)
                        {
                        }
                        i++;
                    }
                }
            }
        }