private void OnMessageReceived(object sender, TypedRequestReceivedEventArgs <MyRequest> e) { // Insert received message at the beginning of the listbox. // Note: we can directly access the listbox because we set threading mode of // InputChannelThreading to the main UI thread. if (e.RequestMessage.Ack == false) { Random rnd = new Random(); ReceivedMessagesListBox.Items.Insert(0, e.RequestMessage); MyResponse resp = new MyResponse(); resp.Temperature = (float)rnd.Next(0, 300) / 10.0f; resp.Pressure = (float)rnd.Next(900, 1100) / 10.0f; resp.Humidity = (float)rnd.Next(0, 1000) / 10.0f; resp.Time = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; // Send message to client which is selected in the listbox. myReceiver.SendResponseMessage(e.ResponseReceiverId, resp); } else { listBoxAcknowledge.Items.Insert(0, e.ResponseReceiverId + ": ACK"); } }
private void OnMessageReceived(object sender, TypedRequestReceivedEventArgs <MyRequest> e) { if (e.RequestMessage.Ack == false) { MyResponse resp = SendWeatherInfo(e.RequestMessage.TimeUnit, e.RequestMessage.numberOfTimeUnitsBack); // Send message to client which is selected in the listbox. if (resp != null) { myReceiver.SendResponseMessage(e.ResponseReceiverId, resp); } } else { if (Serial.IsOpen) { if (clients.IndexOf(GetClient(e.ResponseReceiverId)) != null) { int clientNumver = clients.IndexOf(GetClient(e.ResponseReceiverId)); Serial.Write((clientNumver + 1).ToString() + "#"); LedSerialArgs led = new LedSerialArgs(clientNumver + 1); SendLedInfo?.Invoke(null, led); } else { return; } } } }
public void Send(string aClientId, string message) { if (!string.IsNullOrEmpty(aClientId)) { MyResponse resp = new MyResponse(); //resp.Length = ReceivedMessagesListBox.Items[0].ToString().Length; // Send message to client which is selected in the listbox. myReceiver.SendResponseMessage(aClientId, resp); } }
private void SendMessageBtn_Click(object sender, EventArgs e) { string aClientId = GetSelectedClient(); if (!string.IsNullOrEmpty(aClientId)) { string aMessage = MessageTextBox.Text; MyResponse resp = new MyResponse(); //resp.Length = ReceivedMessagesListBox.Items[0].ToString().Length; // Send message to client which is selected in the listbox. myReceiver.SendResponseMessage(aClientId, resp); } }
private MyResponse SendWeatherInfo(timespan ts, int count) { MyResponse resp; if (ts == timespan.sample) { lock (sampleMutex) { if (count < dataReceiveds.Count) { DataReceived temp = dataReceiveds[(dataReceiveds.Count - count)]; resp = new MyResponse() { Time = (int)temp.timestamp.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, Temperature = temp.temperature, Humidity = temp.humidity, Pressure = temp.pressure }; } else { if (dataReceiveds.Count > 0) { DataReceived temp = dataReceiveds[0]; resp = new MyResponse() { Time = (int)temp.timestamp.Subtract(new DateTime(1970, 1, 1)).TotalSeconds, Temperature = temp.temperature, Humidity = temp.humidity, Pressure = temp.pressure }; } else { return(null); } } } return(resp); } else { string query = Baza.CreateSelectQuery(ts, count, true); List <string>[] result = new List <string> [4]; result = Baza.Select(query); try { DateTime lol = DateTime.Parse(result[0][0]); resp = new MyResponse(); resp.Temperature = Convert.ToSingle((result[1][0])); resp.Pressure = Convert.ToSingle(result[2][0]); resp.Humidity = Convert.ToSingle(result[3][0]); resp.Time = (Int32)(lol.Subtract(new DateTime(1970, 1, 1))).TotalSeconds; return(resp); } catch (ArgumentNullException ex) { return(null); //MessageBox.Show("Brak argumentu " + ex); } catch (FormatException ex) { return(null); //MessageBox.Show("Błąd formatu: " + ex); } catch (OverflowException ex) { return(null); //MessageBox.Show("Błąd przepełnienia " + ex); } } }