protected virtual int GetAndStoreResponse() { int result = 0; while (_rxData.Count > 0) { char[] buffer; if (_rxData.TryDequeue(out buffer)) { if (_responseDoing == null) { _responseDoing = new GrblResponse(); } _responseDoing.SetContent(new string(buffer)); if (_responseDoing.IsFinished) { if (_requestDoing != null) { if (_requestDoing.IsRequestType(GrblRequestEnum.CurrentStatus)) { if (_responseDoing.IsResponseType(GrblResponseEnum.Status)) { _responseDoing.SetRequest(_requestDoing); _requestDoing.SetResponse(_responseDoing); } else if (_tempRequestDoing != null) { _responseDoing.SetRequest(_tempRequestDoing); _tempRequestDoing.SetResponse(_responseDoing); } } else { _responseDoing.SetRequest(_requestDoing); _requestDoing.SetResponse(_responseDoing); } if (_requestDoing.IsFinished) { RequestsDone.Add(_requestDoing); if (_tempRequestDoing != null && _tempRequestDoing.IsFinished) { RequestsDone.Add(_tempRequestDoing); _tempRequestDoing = null; } _requestDoing = _tempRequestDoing; _tempRequestDoing = null; } } result++; Responses.Add(_responseDoing); _responseDoing = null; } } } return(result); }
protected virtual int GetAndSendSpecial() { int result = 0; while (SpecialRequests.Count > 0) { GrblRequest specialRequest = SpecialRequests.Pop(); if (specialRequest.IsRequestType(GrblRequestEnum.CurrentStatus)) { GetAndSendRequest(specialRequest); } else { specialRequest.Stamp(); _txData.Enqueue(specialRequest.Content.ToCharArray()); RequestsDone.Add(specialRequest); result++; } } return(result); }
protected virtual bool GetAndSendRequest(GrblRequest request = null) { bool result = false; if (_requestDoing == null || request != null && _tempRequestDoing == null) { _tempRequestDoing = _requestDoing; _requestDoing = request; if (_requestDoing == null) { RequestsToDo.TryDequeue(out _requestDoing); } if (_requestDoing != null) { if (_requestDoing.IsValid && !_requestDoing.IsStamped) { _requestDoing.Stamp(); if (_requestDoing.IsSpecial) { _txData.Enqueue((_requestDoing.Content).ToCharArray()); } else { _txData.Enqueue((_requestDoing.Content + "\n").ToCharArray()); } _requestCancelSource.Dispose(); _requestCancelSource = new CancellationTokenSource(); result = true; } if (_requestDoing.IsFinished) { RequestsDone.Add(_requestDoing); _requestDoing = null; } } } return(result); }