Example #1
0
        /// <summary>
        /// Send CTRL-X to the machine
        /// </summary>
        public void SoftReset()
        {
            if (AssertConnected())
            {
                Mode = OperatingMode.Manual;

                lock (_queueAccessLocker)
                {
                    _toSend.Clear();
                    _toSendPriority.Clear();
                    _sentQueue.Clear();
                    PendingQueue.Clear();
                    if (Settings.MachineType == FirmwareTypes.GRBL1_1)
                    {
                        _toSendPriority.Enqueue(((char)0x18).ToString());
                    }
                    else if (Settings.MachineType == FirmwareTypes.Repeteir_PnP)
                    {
                        _toSendPriority.Enqueue("M112");
                    }

                    Vacuum1On   = false;
                    Vacuum2On   = false;
                    SolendoidOn = false;
                }

                UnacknowledgedBytesSent = 0;
            }
        }
Example #2
0
        /// <summary>
        /// Cleanly disconnects the server.  Pending requests are placed back in a sending queue to be resent upon reconnection
        /// </summary>
        public void Disconnect()
        {
            // Close the connection superficially
            CommunicationEstablished = false;

            try
            {
                // Stop the ack processing loop.
                Logger.Log <MTProtoSender>(Logger.Level.Debug, $"Trying to stop Ack Handler");
                if (AckCancellation != null)
                {
                    AckCancellation.Cancel();
                }
                if (AckHandler != null)
                {
                    AckHandler.Wait();
                }

                // Close the connection to the server
                // ToDo: Should we also dispose?
                Connection.Disconnect();

                // Remove any event handlers
                Logger.Log <MTProtoSender>(Logger.Level.Debug, $"Removing event handlers");
                Connection.DataReceivedEvent -= Connection_DataReceivedEvent;

                // Place all the pending messages back in the queue to resend
                // Note: Leave pending acks alone.  We will pick up where we left off later
                PendingQueue.Values.ToList().ForEach(x => SendQueue.Add(x));
                PendingQueue.Clear();
            }
            catch (Exception ex)
            {
                Logger.Log(Logger.Level.Error, $"An error occurred while disconnecting.\n\n{ex.Message}");
            }
        }