Exemple #1
0
        public COMPortForm(SerialPortWrapper p)
        {
            if (p == null)
            {
                throw new NullReferenceException("Serial Port Wrapper object cannot be null");
            }

            InitializeComponent();
            port = p;

            t_Tick(null, EventArgs.Empty);
            baudBox.Text = port.BaudRate.ToString();
            SelectPortName(port.PortName);
            if (port.IsOpen)
            {
                connect.Text = "Disconnect";
            }
            else
            {
                if (comboBox1.SelectedItem == null || comboBox1.SelectedItem == "")
                {
                    connect.Enabled = false;
                }
                //if (listBox1.SelectedItem == null)
                //{
                //    connect.Enabled = false;
                //}
            }

            t = new Timer();
            t.Interval = 100;
            t.Tick += new EventHandler(t_Tick);
            t.Start();
        }
Exemple #2
0
 public Robot(SerialPortWrapper serial)
 {
     commandGenerator = null;
     this.serial = serial;
     serial.newDataAvailable += new SerialPortWrapper.newDataAvailableDelegate(NewDataAvailable);
     t = new Timer();
     t.Interval = 50;
     t.Start();
     t.Elapsed += new ElapsedEventHandler(t_Elapsed);
 }
Exemple #3
0
 public Robot(SerialPortWrapper serial)
 {
     this.serial = serial;
     serial.newDataAvailable += new SerialPortWrapper.newDataAvailableDelegate(NewDataAvailable);
     serial.receiveDataError += new SerialPortWrapper.receiveDataErrorDelegate(ReceiveDataError);
     t = new Timer();
     t.Interval = 50;
     t.Start();
     t.Elapsed += new ElapsedEventHandler(t_Elapsed);
 }
Exemple #4
0
 public RobotGUI(SerialPortWrapper serial, Router.Router router)
     : base(serial)
 {
     this.router = router;
     base.onRobotStatusChange += new EventHandler (RouterPositionUpdate);
 }
Exemple #5
0
 public RobotControl()
 {
     InitializeComponent();
     serial = new SerialPortWrapper();
 }
Exemple #6
0
        private void NewDataAvailable(SerialPortWrapper.SimpleSerialPacket packet)
        {
            lock (thisLock)
            {
                if (currentCommand == null)
                {
                    Console.WriteLine("Error: Received data, but no command was sent!");
                    foreach (byte b in packet.Data)
                    {
                        Console.Write(b.ToString("x") + ", ");
                    }
                    Console.WriteLine();
                }
                else
                {
                    currentCommand.ProcessResponse(packet.Data);
                    if (currentCommand.IsDataValid())
                    {
                        // See if there's any state information in the command used to
                        // update location or other fields...
                        byte locations = MaxLocations;
                        if (currentCommand is StatusCommand)
                        {
                            StatusCommand c = currentCommand as StatusCommand;
                            currentPosition = Vector3.Divide (c.CurrentPosition.ToVector3(), ScaleFactors);
                            locations = c.Locations;
                            if (onPositionUpdate != null)
                            {
                                onPositionUpdate(this, EventArgs.Empty);
                            }
                        }
                        if (currentCommand is MoveCommand)
                        {
                            MoveCommand m = currentCommand as MoveCommand;
                            locations = m.Locations;
                        }

                        currentCommand = GetNextCommand(locations);

                        elapsedCounter = 0;
                        serial.Transmit(currentCommand.GenerateCommand(), 0x21);
                    }
                    else
                    {
                        Console.WriteLine("Error: Did not process data correctly!");
                    }
                }
            }
        }