public void DataReceivedEventHandler(object sender, SerialReadEventArgs serialReadEventArgs) { var text = serialReadEventArgs.Message.Trim(); if (text.StartsWith("{") && text.EndsWith("}")) //Check if is a json-like string. Avoid exceptions. { try { var obj = JsonConvert.DeserializeObject <RobotSensorModel>(text); BotPose.Enabled = obj.Enabled; BotPose.XPosBot = (int)obj.xPos; BotPose.YPosBot = (int)obj.yPos; BotPose.ZAngleBot = (int)obj.zAng; if (obj.message != null && obj.message != oldMessage) { ApplicationView applicationView = ApplicationView.GetForCurrentView(); applicationView.Title = obj.message; oldMessage = obj.message; } if (obj.Enabled) { UpdateObstaclePositions(obj); } } catch { //exterminate} } } }
private void DataReceivedEventHandler(object sender, SerialReadEventArgs serialReadEventArgs) { if (SaveSerialToggleButton.IsChecked.GetValueOrDefault()) { SaveToFile(serialReadEventArgs.Message); } SerialReadTextBlock.Text = serialReadEventArgs.Message; }
protected virtual void OnDataReceived(SerialReadEventArgs e) { // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. EventHandler <SerialReadEventArgs> handler = RaiseDataReceivedEvent; // Event will be null if there are no subscribers if (handler != null) { // Use the () operator to raise the event. handler(this, e); } }