/// <summary> /// Method that checks wether /// </summary> /// <param name="json"></param> private void ZoneHandling(JsonDataMessage json) { if (json.Zone1Tripped) { zone1.BackColor = Color.DarkGray; } else { zone1.BackColor = Color.White; } if (json.Zone2Tripped) { zone2.BackColor = Color.DarkGray; } else { zone2.BackColor = Color.White; } if (json.Zone3Tripped) { zone3.BackColor = Color.DarkGray; } else { zone3.BackColor = Color.White; } if (json.Zone4Tripped) { zone4.BackColor = Color.DarkGray; } else { zone4.BackColor = Color.White; } }
/// <summary> /// Method for invoking the DataLog event. /// </summary> public void SendData(JsonDataMessage json) { if (LogDataBit) { LogData(1, json.BatteryLevel); LogData(3, json.Speed); LogDataBit = false; //RunUpdateData(); } }
private void dealWithDataReady(object sender, EventArgs e) { try { ///Here all the logging and alarm checking can be done JsonDataMessage toBeChecked = communication.LatestMessage; alarmCollection.AlarmCheck(toBeChecked); //Sending the values from arduino to alarmclass alarmCollection.AlarmCheck(picBoxAlarm); dataHandling.SendData(toBeChecked); ZoneHandling(toBeChecked); } catch (Exception exe) { MessageBox.Show(exe.Message); } }
private void DataRecieved(object sender, SerialDataReceivedEventArgs e) { try { recievedData = ReadLine(); lastMsg = JsonConvert.DeserializeObject <JsonDataMessage>(recievedData); if (!lastMsg.Zone1Tripped) { Speed = lastMsg.Speed; } else { Speed = 0; } dataReady = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "dataRecieved error"); dataReady = false; } dataIsReady(this, new EventArgs()); }
public void AlarmCheck(JsonDataMessage arduinoValues) //Checking the alarmvalues and makes event if true { ActiveAlarms = 0; foreach (PropertyInfo prop in arduinoValues.GetType().GetProperties()) //Getting values from arudino { alarmListValue.Add(prop.GetValue(arduinoValues).ToString()); //adding values to list of the last updated value from arduino alarmListName.Add(prop.Name); //Adding names to the list with alarmnames } if (alarmCheck[0] == false) //Checking if the emergencyStop bool is active { if (alarmListValue[0] == "true") //Checking the value on emergencyStop { alarmCheck[0] = true; Emergency(this, new EventArgs()); //Making event for Emergency } } if (alarmCheck[1] == false) //Checking if the speed bool is false { if (Convert.ToInt64(alarmListValue[1]) > 10) //If the speed is faster then...MUST CHANGE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! { alarmCheck[1] = true; Speed(this, new EventArgs()); //Making event for high speed } } if (alarmCheck[2] == false) //Checking if the Zone1 bool is false { if (alarmListValue[2] != "False") //Checking if the Zone1 value is false { alarmCheck[2] = (true); ZoneActive1(this, new EventArgs()); //Making event for Zone1 activated } } if (alarmCheck[3] == false) //Checking if the Zone2 bool is false { if (alarmListValue[3] != "False") //Checking if the Zone2 value is false { alarmCheck[3] = (true); ZoneActive2(this, new EventArgs()); //Making event for Zone2 activated } } if (alarmCheck[4] == false) //Checking if the Zone3 bool is false { if (alarmListValue[4] != "False") //Checking if the Zone3 value is false { alarmCheck[4] = (true); ZoneActive3(this, new EventArgs()); //Making event for Zone3 activated } } if (alarmCheck[5] == false) //Checking if the Zone4 bool is false { if (alarmListValue[5] != "False") //Checking if the Zone4 value is false { alarmCheck[5] = (true); ZoneActive4(this, new EventArgs()); //Making event for Zone4 activated } } if (alarmCheck[6] == false) //Checking if the battery low bool is false { if (Convert.ToInt64(alarmListValue[6]) < 100) //MUST CHANGE VALUE TO MORE SPESIFIC!!!!!!!!!!!!!! { alarmCheck[6] = (true); Battery(this, new EventArgs()); //Making event for low battery } } for (int i = 0; i < alarmCheck.Length; i++) { if (alarmCheck[i]) { ActiveAlarms += 1; } } }