Example #1
0
        /// <summary>
        /// Finds the appropriate WritePrinthead method and returns the converted GCode output.
        /// </summary>
        /// <param name="printheadModel"></param>
        /// <returns></returns>
        public string SetWritePrinthead(PrintheadModel printheadModel)
        {
            string convertedGCode = "";

            try
            {
                switch (printheadModel.PrintheadType)
                {
                case PrintheadType.Motorized:
                    convertedGCode = _writeSetPrintheadModel.WriteSetMotorDrivenPrinthead(printheadModel);
                    break;

                case PrintheadType.Valve:
                    convertedGCode = _writeSetPrintheadModel.WriteSetValvePrinthead(printheadModel);
                    break;

                case PrintheadType.Custom:
                    //To Do:
                    break;

                case PrintheadType.Unset:
                    //To Do: Stop everything something's wrong
                    break;

                default:
                    //To Do: Stop everything something's wrong
                    break;
                }
            }
            catch when(printheadModel == null)  //Catch unset Printhead.
            {
                //This should have been caught earlier.
                convertedGCode = "";
            }
        /// <summary>
        /// Takes manual input parameters for a set motorized printhead command and outputs the command to the serial port.
        /// </summary>
        /// <param name="printheadName"></param>
        /// <param name="maxSpeed"></param>
        /// <param name="acceleration"></param>
        public void ProcessManualSetMotorizedPrintheadCommand(string printheadName, double maxSpeed, double acceleration)
        {
            try
            {
                List <string> outgoingMessagesList = new List <string>();

                PrintheadModel printheadModel = _printerModel.FindPrinthead(printheadName);
                MotorizedPrintheadTypeModel motorizedPrintheadTypeModel = (MotorizedPrintheadTypeModel)printheadModel.PrintheadTypeModel;

                int    printheadLimitPinID = (motorizedPrintheadTypeModel.AttachedLimitSwitchGPIOPinModel == null) ? GlobalValues.PinIDNull : motorizedPrintheadTypeModel.AttachedLimitSwitchGPIOPinModel.PinID;
                string setPrintheadString  = _writeSetPrintheadModel.WriteSetMotorDrivenPrinthead(motorizedPrintheadTypeModel.AttachedMotorStepGPIOPinModel.PinID, motorizedPrintheadTypeModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                                                  motorizedPrintheadTypeModel.StepPulseTime, printheadLimitPinID, maxSpeed, acceleration, motorizedPrintheadTypeModel.MmPerStep);
                outgoingMessagesList.Add(setPrintheadString);

                //Send GCode for the Z Axis attached to the Printhead.
                AxisModel axisModel = printheadModel.AttachedZAxisModel;

                int    zAxisLimitPinID = (axisModel.AttachedLimitSwitchGPIOPinModel == null) ? GlobalValues.PinIDNull : axisModel.AttachedLimitSwitchGPIOPinModel.PinID;
                string setAxisString   = _writeSetAxisModel.WriteSetAxis(axisModel.AxisID, axisModel.AttachedMotorStepGPIOPinModel.PinID, axisModel.AttachedMotorDirectionGPIOPinModel.PinID,
                                                                         axisModel.StepPulseTime, zAxisLimitPinID, axisModel.MaxSpeed, axisModel.MaxAcceleration, axisModel.MmPerStep);

                //Retract Z Axis before changing Printheads.
                outgoingMessagesList.Add(SerialMessageCharacters.SerialCommandSetCharacter + "RetractZ");
                outgoingMessagesList.Add(setAxisString);
                _serialCommunicationOutgoingMessagesModel.QueueNextProspectiveOutgoingMessage(outgoingMessagesList);
            }
            catch (NullReferenceException e)
            {
                _errorListViewModel.AddError("", "Printhead or z actuator needs to be set in Printer Settings before setting printhead in Control Menu.");
            }
            catch
            {
                _errorListViewModel.AddError("", "Unknown error while setting valve printhead.");
            }
        }