Esempio n. 1
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();
        }
Esempio n. 2
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();
        }