/// <summary>
 /// Store an enqueued code for transmission to RepRapFirmware
 /// </summary>
 /// <param name="queuedCode">Code to transfer</param>
 /// <returns>True if the code could be buffered</returns>
 private bool BufferCode(QueuedCode queuedCode)
 {
     try
     {
         if (Interface.BufferCode(queuedCode, out int codeLength))
         {
             BytesBuffered += codeLength;
             BufferedCodes.Add(queuedCode);
             _logger.Debug("Sent {0}, remaining space {1}, needed {2}", queuedCode.Code, Settings.MaxBufferSpacePerChannel - BytesBuffered, codeLength);
             return(true);
         }
         return(false);
     }
     catch (Exception e)
     {
         _logger.Debug(e, "Failed to buffer code {0}", queuedCode.Code);
         queuedCode.SetException(e);
         return(true);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Send a queued code to the firmware
 /// </summary>
 /// <param name="queuedCode">Code to send</param>
 /// <returns>Whether the code could be processed</returns>
 public static bool BufferCode(QueuedCode queuedCode)
 {
     try
     {
         int codeLength = Communication.Consts.BufferedCodeHeaderSize + DataTransfer.GetCodeSize(queuedCode.Code);
         if (_bufferSpace > codeLength && DataTransfer.WriteCode(queuedCode.Code))
         {
             Console.WriteLine($"[info] Sent {queuedCode.Code}, remaining space {_bufferSpace}, need {codeLength}");
             _bytesReserved += codeLength;
             _bufferSpace   -= codeLength;
             Channels[queuedCode.Code.Channel].BufferedCodes.Add(queuedCode);
             return(true);
         }
     }
     catch (Exception e)
     {
         queuedCode.SetException(e);
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
        private bool BufferCode(QueuedCode queuedCode)
        {
            if (queuedCode.Code.Type == CodeType.MCode && queuedCode.Code.MajorNumber == 291)
            {
                int sParam = queuedCode.Code.Parameter('S', 0);
                if (sParam == 2 || sParam == 3)
                {
                    // This M291 call interrupts the G-code flow, wait for M292 next
                    WaitingForMessageAcknowledgement = true;
                }
            }
            else if (queuedCode.Code.Type == CodeType.MCode && queuedCode.Code.MajorNumber == 292)
            {
                // The pending message box is about to be closed
                WaitingForMessageAcknowledgement = false;
            }
            else if (WaitingForMessageAcknowledgement)
            {
                // Still waiting for M292...
                return(false);
            }

            // Try to send this code to the firmware
            try
            {
                if (Interface.BufferCode(queuedCode, out int codeLength))
                {
                    BytesBuffered += codeLength;
                    BufferedCodes.Add(queuedCode);
                    return(true);
                }
                return(false);
            }
            catch (Exception e)
            {
                queuedCode.SetException(e);
                return(true);
            }
        }