Exemplo n.º 1
0
 protected virtual void OnSerialDataChanged(SerialDataEventArgs e)
 {
     if (SerialDataEvent != null)
     {
         SerialDataEvent(this, e);
     }
 }
Exemplo n.º 2
0
        private static void com_SerialDataEvent(object sender, SerialDataEventArgs e)
        {
            StatusByteCode nextByte = new byte();
            StatusByteCode _receivedByte = (StatusByteCode)e.DataByte;

            if (_receivedByte == 0x00)
                return;

            switch (_receivedByte)
            {
                case StatusByteCode.Left:
                    nextByte = StatusByteCode.Acknowledged;
                    break;
                case StatusByteCode.Right:
                    nextByte = StatusByteCode.Acknowledged;
                    break;
                case StatusByteCode.Forward:
                    nextByte = StatusByteCode.Acknowledged;
                    break;
                case StatusByteCode.Turn:
                    nextByte = StatusByteCode.Acknowledged;
                    break;
                case StatusByteCode.Acknowledged:
                    break;
                case StatusByteCode.Done:
                    return;
                default:
                    break;
            }

            if (nextByte != 0x00)
                com.SendByte((byte)nextByte);

            System.Threading.Thread.Sleep(500);
            if (!minehere)
            {
                com.SendByte((byte)StatusByteCode.Halfway);
                System.Threading.Thread.Sleep(500);
            }
            else
                minehere = false;

            com.SendByte((byte)StatusByteCode.Enquiry);
        }
Exemplo n.º 3
0
 private void com_SerialDataEvent(object sender, SerialDataEventArgs e)
 {
     System.Diagnostics.Debug.WriteLine("Serial data byte received; {0}", e.DataByte);
 }
Exemplo n.º 4
0
 protected virtual void OnSerialDataChanged(SerialDataEventArgs e)
 {
     if (SerialDataEvent != null)
     {
         SerialDataEvent(this, e);
     }
 }
Exemplo n.º 5
0
 void Serial_SerialDataEvent(object sender, SerialDataEventArgs e)
 {
     handleSerial(e.DataByte);
 }
Exemplo n.º 6
0
 static void com_SerialDataEvent(object sender, SerialDataEventArgs e)
 {
     Console.WriteLine(e.DataByte);
 }
Exemplo n.º 7
0
        private void com_SerialDataEvent(object sender, SerialDataEventArgs e)
        {
            if (!_robotControlIsEnabled)
                return;

            _receivedByte = e.DataByte.ToStatusByteCode();

            if (_receivedByte == StatusByteCode.Acknowledged)
            {
                if (_sentDirectiveIsUnacknowledged)
                {
                    if (_done == true)
                        DisableRobotControl();

                    if (_nextDirective == StatusByteCode.Back)
                    {
                        Data.nav.currentPos = new NodeConnection(Data.nav.currentPos.From, true);
                        _halfway = true;
                    }
                    else
                    {
                        _halfway = false;
                        _robotDirection = _nextAbsoluteDirection;
                        Data.nav.currentPos = _nextNodeConnection;
                    }

                    _i++; //Advance to next item in path
                    _sentDirectiveIsUnacknowledged = false;
                }
                else
                {
                    return;
                }
            }
            else if (_receivedByte == StatusByteCode.NotAcknowledged)
            {
                //Resend directives
                Data.com.SendByte((byte)_nextDirective);
            }
            else if (_sentDirectiveIsUnacknowledged == false)
            {
                if (_receivedByte == StatusByteCode.Enquiry)
                {
                    if (_i > 0 && Data.challenge == Challenge.FindPath && (!_halfway && _nextDirective != StatusByteCode.Turn) && !Data.nav.fullPath[_i].FromPoint)
                        return;

                    if (Data.nav.fullPath.Count != 0)
                    {
                        getNextDirective();
                        Data.com.SendByte((byte)_nextDirective);
                    }
                    else
                    {
                        Data.com.SendByte((byte)StatusByteCode.Unknown);
                    }

                    if (Data.challenge == Challenge.FindPath)
                    {
                        if (_done == true)
                            Data.com.SendByte((byte)StatusByteCode.Done);

                        if (_continue == true)
                            Data.com.SendByte((byte)StatusByteCode.Continue);

                        _continue = false;
                    }

                    if (Data.challenge == Challenge.FindTreasure)
                    {
                        if (_done == true)
                            DisableRobotControl();
                    }

                    _sentDirectiveIsUnacknowledged = true;
                }
                else if (_receivedByte == StatusByteCode.MineDetected)
                {
                    if (_i == 0)
                        return;

                    //Detected mine, add to list
                    if (Data.challenge == Challenge.FindTreasure)
                    {
                        if (!treasureSearchList.Remove(Data.nav.currentPos))
                            treasureSearchList.Remove(Data.nav.currentPos.Flipped);
                        Data.nav.visited.Add(Data.nav.currentPos);
                    }

                    Data.nav.mines.Add(Data.nav.fullPath[_i - 1]);

                    _i = 0;
                    Data.nav.recalculatePath();
                    Data.com.SendByte((byte)StatusByteCode.Acknowledged);
                    _halfway = true;
                }
                else if (_receivedByte == StatusByteCode.Halfway)
                {
                    if (Data.challenge == Challenge.FindTreasure)
                    {
                        if (!treasureSearchList.Remove(Data.nav.currentPos))
                            treasureSearchList.Remove(Data.nav.currentPos.Flipped);
                        Data.nav.visited.Add(Data.nav.currentPos);
                    }

                    _halfway = true;
                    Data.com.SendByte((byte)StatusByteCode.Acknowledged);
                }
            }
            else
            {
                //Invalid bytecode or out of sync
                return;
            }

            Data.vis.DrawField();
            Data.db.UpdateProperty("MineCount");
            Data.db.UpdateProperty("CurrentPosText");
        }