private static void webServer_DataReceived(object sender, ReceivedDataEventArgs e) { try { switch (e.ReceivedData) { case "VENTILATION_OFF": XPH.SendMessage("C01C01COFFCOFFC03C03COFFCOFF"); break; case "VENTILATION_1": XPH.SendMessage("C01C01CONCONC03C03COFFCOFF"); break; case "VENTILATION_2": break; //XPH.SendMessage(""); case "VENTILATION_3": XPH.SendMessage("C01C01CONCONC03C03CONCON"); break; default: break; } } catch (Exception ex) { Debug.Print("error webServer_DataReceived => " + ex.Message.ToString()); } }
private void xph_DataReceived(object sender, ReceivedDataEventArgs e) { try { if (e.ReceivedData != "$<2800!4B#") { Logging.LogMessageToFile(this.ToString() + "- xph_DataReceived - Received => " + e.ReceivedData, "ALL"); } RS232 com = (RS232)sender; string message = ""; int maxNumberofWhiles = 100; int numberOfWhiles = 0; //pass message on to protocol translator and get translation //take into account that multiple submessages can exist in one transmission $<2800?69#$<2800?69#$<2800?69# // handle each # as a complete message from CTX35 // find messages in one message that ends with # bufferString = bufferString + e.ReceivedData; do // loop until there's no end char in the message anymore { if (bufferString.IndexOf("#") > 0) { //at least one message (doesn't have to be a complete one). message = bufferString.Substring(0, bufferString.IndexOf("#") + 1); TranslateIncomingMessage(message); //There are more than one messages if (bufferString.Length > bufferString.IndexOf("#") + 1) { //remove the first message and store the rest in bufferstring bufferString = bufferString.Substring(bufferString.IndexOf("#") + 1, (bufferString.Length - (bufferString.IndexOf("#") + 1))); } else { //the message handled was the only message, clear bufferstring bufferString = ""; } } else { return; } numberOfWhiles++; if (numberOfWhiles >= maxNumberofWhiles) { Logging.LogMessageToFile(this.ToString() + "- Error in While searching for end of message # in " + bufferString, "ALL"); } }while (bufferString.IndexOf("#") > 0 && numberOfWhiles < maxNumberofWhiles); } catch (Exception ex) { Logging.LogMessageToFile(this.ToString() + " - xph_DataReceived => " + ex.Message, "ALL"); } }
/* * private static void ZwaveLogic() * { * double temperature; * int luminiscence; * int humidity; * bool movement; * * try * { * * ZWave.GetSensorBathRoom(out temperature, out luminiscence, out humidity, out movement); * * * tempQ.Enqueue(temperature); * if (tempQ.Count > 100) * { * tempQ.Dequeue(); * } * lumQ.Enqueue(luminiscence); * if (lumQ.Count > 100) * { * lumQ.Dequeue(); * } * humQ.Enqueue(humidity); * if (humQ.Count > 100) * { * humQ.Dequeue(); * } * moveQ.Enqueue(movement); * if (moveQ.Count > 100) * { * moveQ.Dequeue(); * } * * * if (movement == true && StatusBathroomMovement == false) * { * Logging.LogMessageToFile("Bathroom light on by movement", "Logic"); * Debug.Print("Light on by movement"); * StatusBathroomMovement = movement; * XPH.SendMessage("B01B01BONBON"); * } * if (movement == false && StatusBathroomMovement == true) * { * Logging.LogMessageToFile("Bathroom light off by movement off", "Logic"); * Debug.Print("Light off by movement"); * StatusBathroomMovement = movement; * XPH.SendMessage("B01B01BOFFBOFF"); * } * * // Logging.LogMessageToFile("Sensor5 Log," + temperature + "," + luminiscence + "," + humidity,"Bathroom"); * if (humidity > 80 + 10) //humidity is bigger then 70% start ventilation * //if (humQ.Count && humQ[99]>(humQ[0]+10)) * { * if (Zichtakker17Logic.VentilatieL3.status == "OFF") * { * Logging.LogMessageToFile("Ventilation started by humidity sensor >80", "Logic"); * Debug.Print("Started by humidity"); * XPH.SendMessage("C01C01CONCON"); * XPH.SendMessage("C03C03CONCON"); * //ventilatie hoog * } * } * if (humidity <= 85) * { * // humidity lower then 70% and A02OFF then ventilation OFF * if (Zichtakker17Logic.Badkamerlamp.status == "OFF" && Zichtakker17Logic.Afzuigkap.status == "OFF" && Zichtakker17Logic.VentilatieL3.status == "ON") * //if (true) * { * Logging.LogMessageToFile("Ventilation stopped by humidity sensor <85", "Logic"); * Debug.Print("stopped by humidity"); * XPH.SendMessage("C01C01COFFCOFF"); * XPH.SendMessage("C03C03COFFCOFF"); * } * } * } * catch (Exception e) * { * Logging.LogMessageToFile(e.Message, "All"); * } * } */ private static void logic_DataReceived(object sender, ReceivedDataEventArgs e) { try { string data = ""; XanuraProtocolHandler ph = (XanuraProtocolHandler)sender; data = e.ReceivedData; //Debug.Print(DateTime.UtcNow.ToString() + ", --------------RECEIVED from ----------------" + ph.ToString() + " - " + data); Zichtakker17Logic.SetStatus(data); string sendData = Zichtakker17Logic.GetAction(data); if (sendData != "") { XPH.SendMessage(sendData); } } catch (Exception ex) { Logging.LogMessageToFile("Program - logic_DataReceived => " + ex.Message, "All"); } }