protected virtual void OnSerialDataChanged(SerialDataEventArgs e) { if (SerialDataEvent != null) { SerialDataEvent(this, e); } }
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); }
private void com_SerialDataEvent(object sender, SerialDataEventArgs e) { System.Diagnostics.Debug.WriteLine("Serial data byte received; {0}", e.DataByte); }
void Serial_SerialDataEvent(object sender, SerialDataEventArgs e) { handleSerial(e.DataByte); }
static void com_SerialDataEvent(object sender, SerialDataEventArgs e) { Console.WriteLine(e.DataByte); }
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"); }