/// <summary> /// Deserialize a Printhead. /// </summary> /// <param name="xmlReader"></param> /// <param name="printerViewModel"></param> private void LoadPrinthead(XmlReader xmlReader, PrinterViewModel printerViewModel) { //Name of the new Printhead. string printheadName = xmlReader.GetAttribute("Name"); //Reference of the new Printhead that will be deserialized. PrintheadViewModel newPrinthead = null; //See if there is a matching Printhead. bool matchingPrinthead = false; foreach (PrintheadViewModel printheadViewModel in printerViewModel.PrintheadViewModelList) { if (printheadViewModel.Name == printheadName) { matchingPrinthead = true; newPrinthead = printheadViewModel; break; } } //If there is no matching Printhead, then create a new Printhead. if (matchingPrinthead == false) { newPrinthead = printerViewModel.AddPrinthead(printheadName); } //Loads the new Printhead with properties from XML and remembers the newly deserialized Printhead. if (newPrinthead != null) { _printheadXMLDeserializerModel.DeserializePrinthead(xmlReader, newPrinthead); _deserializedPrintheadViewModelsList.Add(newPrinthead); } }
/// <summary> /// Translates task queued message when a Set Motorized Printhead task is complete. /// Sets parameters for the Real Time Status. /// </summary> /// <param name="taskQueuedMessage"></param> /// <returns></returns> public void InterpretSetMotorizedPrintheadComplete(string taskQueuedMessage) { string printheadName = taskQueuedMessage.Substring(25, taskQueuedMessage.IndexOf(" S") - 25); // Name of the Printhead. Labelled as unknown if Printhead cannot be found. double[] parameterValues = ParseDoubleArray(taskQueuedMessage.Substring(taskQueuedMessage.IndexOf(" S"))); //Array of numerical values in incomingMessage. printheadName = (_printerModel.FindPrinthead(printheadName) != null) ? printheadName : "Unknown Motorized Printhead"; int maxSpeed = (int)parameterValues[0]; int acceleration = (int)parameterValues[1]; string oldPrintheadName = _realTimeStatusDataModel.ActivePrintheadModel.Name; //The old Printhead Name is used to revert the active status of the old Printhead. //Set Real Time Status parameters based on this incomingMessage. if (printheadName != "Unknown Motorized Printhead") { PrintheadViewModel oldPrintheadViewModel = _printerViewModel.FindPrinthead(oldPrintheadName); if (oldPrintheadViewModel != null) { oldPrintheadViewModel.PrintheadStatus = PrintheadStatus.Idle; } _realTimeStatusDataModel.RecordSetMotorizedPrinthead(printheadName, maxSpeed, acceleration); _printerViewModel.FindPrinthead(printheadName).PrintheadStatus = PrintheadStatus.Active; } }
/// <summary> /// Writes PrintheadViewModel properties into a XmlWriter. /// </summary> /// <param name="xmlWriter"></param> /// <param name="printheadViewModel"></param> public void SerializePrinthead(XmlWriter xmlWriter, PrintheadViewModel printheadViewModel) { //Outmost element should be "Printhead". xmlWriter.WriteStartElement("Printhead"); //Outmost element should contain properties required for identification and instantiation. //Name. xmlWriter.WriteAttributeString("Name", printheadViewModel.Name); //Z Axis. if (printheadViewModel.AttachedZAxisViewModel != null) { xmlWriter.WriteElementString("ZAxisName", printheadViewModel.AttachedZAxisViewModel.Name); } //Printhead Type. PrintheadTypeXMLSerializerModel printheadTypeXMLSerializerModel = null; switch (printheadViewModel.PrintheadType) { case PrintheadType.Motorized: printheadTypeXMLSerializerModel = new MotorizedPrintheadTypeXMLSerializerModel(); break; case PrintheadType.Valve: printheadTypeXMLSerializerModel = new ValvePrintheadTypeXMLSerializerModel(); break; case PrintheadType.Custom: printheadTypeXMLSerializerModel = new CustomPrintheadTypeXMLSerializerModel(); break; case PrintheadType.Unset: xmlWriter.WriteElementString("UnsetPrintheadType", ""); break; } if (printheadTypeXMLSerializerModel != null) { printheadTypeXMLSerializerModel.SerializePrintheadType(xmlWriter, printheadViewModel.PrintheadTypeViewModel); } //XOffset. xmlWriter.WriteElementString("XOffset", printheadViewModel.XOffset.ToString()); //YOffset. xmlWriter.WriteElementString("YOffset", printheadViewModel.YOffset.ToString()); //End "Printhead" outmost element. xmlWriter.WriteEndElement(); }
/// <summary> /// Translates task queued message when a Set Valve Printhead task is complete. /// Sets parameters for the Real Time Status. /// </summary> /// <param name="taskQueuedMessage"></param> /// <returns></returns> public void InterpretSetValvePrintheadComplete(string taskQueuedMessage) { string printheadName = taskQueuedMessage.Substring(21); //Name of the Printhead. Labelled as unknown if Axis cannot be found. double[] parameterValues = ParseDoubleArray(taskQueuedMessage); //Array of numerical values in incomingMessage. printheadName = (_printerModel.FindPrinthead(printheadName) != null) ? printheadName : "Unknown Valve Printhead"; string oldPrintheadName = _realTimeStatusDataModel.ActivePrintheadModel.Name; //The old Printhead Name is used to revert the active status of the old Printhead. //Set Real Time Status parameters based on this incomingMessage. if (printheadName != "Unknown Valve Printhead") { PrintheadViewModel oldPrintheadViewModel = _printerViewModel.FindPrinthead(oldPrintheadName); if (oldPrintheadViewModel != null) { oldPrintheadViewModel.PrintheadStatus = PrintheadStatus.Idle; } _realTimeStatusDataModel.RecordSetValvePrinthead(printheadName); _printerViewModel.FindPrinthead(printheadName).PrintheadStatus = PrintheadStatus.Active; } }
/// <summary> /// Reads PrintheadViewModel properties from XML and sets a PrintheadViewModel with said properties. /// </summary> /// <param name="xmlReader"></param> /// <param name="printheadViewModel"></param> public void DeserializePrinthead(XmlReader xmlReader, PrintheadViewModel printheadViewModel) { //Read through each element of the XML string and populate each property of the Axis. PrintheadTypeXMLDeserializerModel printheadTypeXMLDeserializerModel = null; while (xmlReader.Read()) { //Skip through newlines (this program's XML Writer uses newlines). if ((xmlReader.Name != "\n") && (!String.IsNullOrWhiteSpace(xmlReader.Name))) { //End method if the end of "Printhead" element is reached. if ((xmlReader.Name == "Printhead") && (xmlReader.NodeType == XmlNodeType.EndElement)) { return; } switch (xmlReader.Name) { case "PrintheadName": //See if there is a mismatch between the Printhead argument and the deserialized Printhead. if (xmlReader.ReadElementContentAsString() != printheadViewModel.Name) { base.ReportErrorMismatchedEqupment(xmlReader); } break; case "ZAxisName": printheadViewModel.AttachedZAxisViewModel = _printerViewModel.FindAxis(xmlReader.ReadElementContentAsString()); break; case "MotorizedPrintheadType": printheadViewModel.PrintheadType = PrintheadType.Motorized; printheadTypeXMLDeserializerModel = new MotorizedPrintheadTypeXMLDeserializer(_printerViewModel.MicrocontrollerViewModel, base._errorListViewModel); printheadTypeXMLDeserializerModel.DeserializePrintheadType(xmlReader, printheadViewModel.PrintheadTypeViewModel); break; case "ValvePrintheadType": printheadViewModel.PrintheadType = PrintheadType.Valve; printheadTypeXMLDeserializerModel = new ValvePrintheadTypeXMLDeserializerModel(_printerViewModel.MicrocontrollerViewModel, base._errorListViewModel); printheadTypeXMLDeserializerModel.DeserializePrintheadType(xmlReader, printheadViewModel.PrintheadTypeViewModel); break; case "CustomPrintheadType": printheadViewModel.PrintheadType = PrintheadType.Custom; printheadTypeXMLDeserializerModel = new CustomPrintheadTypeXMLDeserializerModel(_printerViewModel.MicrocontrollerViewModel, base._errorListViewModel); printheadTypeXMLDeserializerModel.DeserializePrintheadType(xmlReader, printheadViewModel.PrintheadTypeViewModel); break; case "UnsetPrintheadType": //Do nothing. break; case "XOffset": printheadViewModel.XOffset = xmlReader.ReadElementContentAsDouble(); break; case "YOffset": printheadViewModel.YOffset = xmlReader.ReadElementContentAsDouble(); break; default: base.ReportErrorUnrecognizedElement(xmlReader); break; } } } }