private void SendModbusMessage(byte[] modbusMessage) { // ЕСЛИ ПОРТ ЗАКРЫТ if (!SerialPort.IsOpen) { try { SerialPort.Open(); } catch (InvalidOperationException ex) { SerialPortOpeningError?.Invoke($"Возникла ошибка при попытке открыть порт {SerialPort.PortName}. Подробнее о возникшей исключительной ситуации: \n\n {ex.Message}"); } } // Очищаем буффер исходящих данных (порт может быть уже открытым и там могут быть данные с прошлой отправки) SerialPort.DiscardOutBuffer(); Thread.Sleep(50); try { // Отправляем данные SerialPort.Write(modbusMessage, 0, modbusMessage.Length); } catch (TimeoutException ex) // По истечении WriteTimeout [мс] { SerialPortWritingError?.Invoke($"Произошла ошибка при записи данных порт. \n\nПодробнее о возникшей исключительной ситуации: \n\n {ex.Message}"); } RequestSent?.Invoke(modbusMessage); // Вызов события "отправлена команда" Thread.Sleep(ResponseTimeout); // Задержка выжидания поступления данных на COM порт }
/// <summary> /// Raises the <see cref="RequestSent"/> event. Note, sender is null. /// </summary> public static void onRequestSent(Uri inUri, HttpWebResponse inResponse) { // Written, 02.09.2017 onSendingStopWatch.Stop(); requestsSentThisSession++; Console.WriteLine("Request Completed: Total RS: {0} ({1}ms)", requestsSentThisSession, onSendingStopWatch.Elapsed.TotalMilliseconds.ToString("F2")); RequestSent?.Invoke(null, new RequestSentEventArgs(inUri, inResponse)); }
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { RequestSent?.Invoke(request); if (ResponseMap.ContainsKey(request.RequestUri)) { return(Task.FromResult(ResponseMap[request.RequestUri])); } return(Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound) { RequestMessage = request })); }
/// <summary> /// Tworzy i wysyła zapytanie do serwera. Na odpowiedź na zapytanie należy nasłuchiwać na event'cie RequestResponseReceived /// </summary> /// <param name="requestData">Dane zapytania do wysłania, metoda obudowuje je dodatkowo odpowiednimi meta-danymi zapytania</param> public Request SendRequest(JObject requestData) { var requestId = CurrentRequestId; _CurrentRequestId++; var wrapper = new StandardRequestWrapperSerializer() { RequestCode = requestId, Data = requestData }; var request = new Request(this, wrapper.GetApiObject(), requestId); OnGoingRequests.Add(requestId, request); request.Send(); RequestSent?.Invoke(this, request); return(request); }
private void SendRequests(CancellationToken token) { while (!token.IsCancellationRequested) { lock (_locker) { // awaiting acknowledgement from server if (!_awaitingRequests.IsEmpty) { continue; } // do nothing if buffer is empty if (_operationsBuffer.IsEmpty) { continue; } // if no subscriber (server) attached do not send operations if (RequestSent == null) { continue; } // send a new request with the queued operations from the buffer IRequest request = RequestFactory.CreateRequest(ClientId, _revision, _operationsBuffer.ToList()); RequestSent.Invoke(request); _awaitingRequests.Enqueue(request); _operationsBuffer.Clear(); if (_logginEnabled) { _logger.LogWriteLine($"Client with ID: '{ClientId}' sent new request to the server"); } } } }
internal static void Sent(HttpWebRequest request, string json) => RequestSent?.Invoke(request, json);
protected RemoteDebuggerMessage OnRequestSent(RemoteDebuggerMessage message) { return(RequestSent?.Invoke(message)); }
public virtual void OnRequestSent(WebEventArgs e) { RequestSent?.Invoke(e.Context, e); }
public void Execute(string card, string area, int count) { var products = SearchProducts("a"); for (var i = 0; i < count; i++) { var id = products[rnd.Next(0, products.Count - 1)].Id; var response = SubmitOrder(new OrderRequest() { Id = Guid.NewGuid(), Product = id, Address = "Unit 1, 100 John Street, Sydney", Quantity = rnd.Next(1, 9), Payment = GenerateCreditCardNumber(card), Zip = GenerateAreaCode(area), Country = "Australia" }); if (response.Data.Status) { RequestPassed?.Invoke(this, new EventArgs()); } else { RequestFailed?.Invoke(this, new EventArgs()); } foreach (var o in response.Downstream) { if (o.Endpoint.Contains("payment")) { if (o.Version.Equals(1)) { RequestProcessedByPaymentServer1?.Invoke(this, new EventArgs()); } if (o.Version.Equals(2)) { RequestProcessedByPaymentServer2?.Invoke(this, new EventArgs()); } } if (o.Endpoint.Contains("address")) { if (o.Version.Equals(1)) { RequestProcessedByAddressServer1?.Invoke(this, new EventArgs()); } if (o.Version.Equals(2)) { RequestProcessedByAddressServer2?.Invoke(this, new EventArgs()); } if (o.Version.Equals(3)) { RequestProcessedByAddressServer3?.Invoke(this, new EventArgs()); } } } RequestSent?.Invoke(this, new EventArgs()); } }