コード例 #1
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!");
                    }
                }
            }
        }
コード例 #2
0
        private void NewDataAvailable(byte data)
        {
            lock (thisLock)
            {
                elapsedCounter = 0;
                if (currentCommand == null)
                {
                    Console.WriteLine("Error: Received data, but no command was sent!");
                    Console.Write(data.ToString("x") + ", ");
                    Console.WriteLine();
                }
                else
                {
                    if (currentCommand.ProcessResponse(data))
                    {
                        bool canAcceptMoveCommand = false;
                        if (currentCommand is IRobotCommandWithStatus)
                        {
                            IRobotCommandWithStatus status = currentCommand as IRobotCommandWithStatus;
                            currentPosition      = status.CurrentPosition;
                            canAcceptMoveCommand = status.CanAcceptMoveCommand;
                            if (this.lastPositionKnown == false)
                            {
                                lastPosition      = currentPosition;
                                lastPositionKnown = true;
                            }
                            if (onRobotStatusChange != null)
                            {
                                onRobotStatusChange(status, EventArgs.Empty);
                            }
                        }
                        else if (currentCommand is RobotDetectionCommand)
                        {
                            RobotDetectionCommand r = currentCommand as RobotDetectionCommand;
                            commandGenerator = r.GetCommandGenerator();
                        }

                        currentCommand = GetNextCommand(canAcceptMoveCommand);
                        serial.Transmit(currentCommand.GenerateCommand());
                    }
                }
            }
        }
コード例 #3
0
        void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            t.Stop();
            lock (thisLock)
            {
                if (serial != null && serial.IsOpen)
                {
                    elapsedCounter++;
                    if ((elapsedCounter * 50) > (1000)) // More than 1 second to reply
                    {
                        Console.WriteLine("Device Timeout!");

                        // Send a status command
                        currentCommand = new StatusCommand();
                        
                        serial.Transmit(currentCommand.GenerateCommand(), 0x21);
                        elapsedCounter = 0;
                    }
                }
            }
            t.Start();
        }
コード例 #4
0
        void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            t.Stop();
            lock (thisLock)
            {
                if (elapsedCounter > timeout_ms)
                {
                    if (currentCommand != null && currentCommand is RobotDetectionCommand)
                    {
                        Console.WriteLine("Unexpected Response from robot detection: " + (currentCommand as RobotDetectionCommand).DumpData());
                    }
                    // Expected reply not received within 1 second, assume command was lost.
                    Console.WriteLine("Device Timeout!");
                }

                if (serial == null || !serial.IsOpen || elapsedCounter > timeout_ms)
                {
                    lastPositionKnown = false;
                    commandGenerator  = null;
                    currentCommand    = null;
                    elapsedCounter    = 0;
                }
                else
                {
                    if (currentCommand == null)
                    {
                        currentCommand = new RobotDetectionCommand();
                        serial.Transmit(currentCommand.GenerateCommand());
                        elapsedCounter = 0;
                    }
                    else
                    {
                        elapsedCounter += 50;
                    }
                }
            }
            t.Start();
        }
コード例 #5
0
ファイル: Robot.cs プロジェクト: JackTing/PathCAM
        void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            t.Stop();
            lock (thisLock)
            {
                if (elapsedCounter > timeout_ms)
                {
                    if (currentCommand != null && currentCommand is RobotDetectionCommand)
                    {
                        Console.WriteLine("Unexpected Response from robot detection: " + (currentCommand as RobotDetectionCommand).DumpData());
                    }
                    // Expected reply not received within 1 second, assume command was lost.
                    Console.WriteLine("Device Timeout!");
                }

                if (serial == null || !serial.IsOpen || elapsedCounter > timeout_ms)
                {
                    lastPositionKnown = false;
                    commandGenerator = null;
                    currentCommand = null;
                    elapsedCounter = 0;
                }
                else
                {
                    if (currentCommand == null)
                    {
                        currentCommand = new RobotDetectionCommand();
                        serial.Transmit(currentCommand.GenerateCommand());
                        elapsedCounter = 0;
                    }
                    else
                    {
                        elapsedCounter += 50;
                    }
                }
            }
            t.Start();
        }
コード例 #6
0
ファイル: Robot.cs プロジェクト: JackTing/PathCAM
        private void NewDataAvailable(byte data)
        {
            lock (thisLock)
            {
                elapsedCounter = 0;
                if (currentCommand == null)
                {
                    Console.WriteLine("Error: Received data, but no command was sent!");
                    Console.Write(data.ToString("x") + ", ");
                    Console.WriteLine();
                }
                else
                {
                    if (currentCommand.ProcessResponse(data))
                    {
                        bool canAcceptMoveCommand = false;
                        if (currentCommand is IRobotCommandWithStatus)
                        {
                            IRobotCommandWithStatus status = currentCommand as IRobotCommandWithStatus;
                            currentPosition = status.CurrentPosition;
                            canAcceptMoveCommand = status.CanAcceptMoveCommand;
                            if (this.lastPositionKnown == false)
                            {
                                lastPosition = currentPosition;
                                lastPositionKnown = true;
                            }
                            if (onRobotStatusChange != null)
                            {
                                onRobotStatusChange(status, EventArgs.Empty);
                            }
                        }
                        else if (currentCommand is RobotDetectionCommand)
                        {
                            RobotDetectionCommand r = currentCommand as RobotDetectionCommand;
                            commandGenerator = r.GetCommandGenerator();
                        }

                        currentCommand = GetNextCommand(canAcceptMoveCommand);
                        serial.Transmit(currentCommand.GenerateCommand());
                    }
                }
            }
        }
コード例 #7
0
ファイル: Robot.cs プロジェクト: glocklueng/cnc_machine
        void t_Elapsed(object sender, ElapsedEventArgs e)
        {
            t.Stop();
            lock (thisLock)
            {
                if (serial != null && serial.IsOpen)
                {
                    elapsedCounter++;
                    if ((elapsedCounter * 50) > (1000)) // More than 1 second to reply
                    {
                        Console.WriteLine("Device Timeout!");

                        // Send a status command
                        currentCommand = new StatusCommand();

                        serial.Transmit(currentCommand.GenerateCommand(), 0x21);
                        elapsedCounter = 0;
                    }
                }
            }
            t.Start();
        }
コード例 #8
0
ファイル: Robot.cs プロジェクト: glocklueng/cnc_machine
        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!");
                    }
                }
            }
        }