Пример #1
0
        public SimulatedGCodeMachine(FirmwareTypes firmwareType)
        {
            _firmwareType = firmwareType;
            _timer        = Services.TimerFactory.Create(TimeSpan.FromSeconds(0.5));
            _timer.Tick  += _timer_Tick;

            _timer.Start();
        }
		private void ConnectToPrinter(Printer printerRecord)
		{
			PrinterOutputCache.Instance.Clear();
			LinesToWriteQueue.Clear();
			//Attempt connecting to a specific printer
			this.stopTryingToConnect = false;
			firmwareType = FirmwareTypes.Unknown;
			firmwareVersion = null;
			firmwareUriGcodeSend = false;

			// On Android, there will never be more than one serial port available for us to connect to. Override the current .ComPort value to account for
			// this aspect to ensure the validation logic that verifies port availability/in use status can proceed without additional workarounds for Android
#if __ANDROID__
			string currentPortName = FrostedSerialPort.GetPortNames().FirstOrDefault();

			if (!string.IsNullOrEmpty(currentPortName))
			{
				this.ActivePrinter.ComPort = currentPortName;
			}
#endif

			if (SerialPortIsAvailable(this.ActivePrinter.ComPort))
			{
				//Create a timed callback to determine whether connection succeeded
				Timer connectionTimer = new Timer(new TimerCallback(ConnectionCallbackTimer));
				connectionTimer.Change(100, 0);

				//Create and start connection thread
				connectThread = new Thread(Connect_Thread);
				connectThread.Name = "Connect To Printer";
				connectThread.IsBackground = true;
				connectThread.Start();
			}
			else
			{
				Debug.WriteLine("Connection failed: {0}".FormatWith(this.ActivePrinter.ComPort));

				connectionFailureMessage = string.Format(
									"{0} is not available".Localize(),
									this.ActivePrinter.ComPort);

				OnConnectionFailed(null);
			}
		}
		public void PrinterStatesFirmware(object sender, EventArgs e)
		{
			FoundStringEventArgs foundStringEventArgs = e as FoundStringEventArgs;

			string firmwareName = "";
			if (GCodeFile.GetFirstStringAfter("FIRMWARE_NAME:", foundStringEventArgs.LineToCheck, " ", ref firmwareName))
			{
				firmwareName = firmwareName.ToLower();
				if (firmwareName.Contains("repetier"))
				{
					firmwareType = FirmwareTypes.Repetier;
				}
				else if (firmwareName.Contains("marlin"))
				{
					firmwareType = FirmwareTypes.Marlin;
				}
				else if (firmwareName.Contains("sprinter"))
				{
					firmwareType = FirmwareTypes.Sprinter;
				}
			}
			string firmwareVersionReported = "";
			if (GCodeFile.GetFirstStringAfter("MACHINE_TYPE:", foundStringEventArgs.LineToCheck, " EXTRUDER_COUNT", ref firmwareVersionReported))
			{
				char splitChar = '^';
				if (firmwareVersionReported.Contains(splitChar))
				{
					string[] split = firmwareVersionReported.Split(splitChar);
					if (split.Count() == 2)
					{
						deviceCode = split[0];
						firmwareVersionReported = split[1];
					}
				}

				//Firmware version was detected and is different
				if (firmwareVersionReported != "" && firmwareVersion != firmwareVersionReported)
				{
					firmwareVersion = firmwareVersionReported;
					OnFirmwareVersionRead(null);
				}
			}
		}
		public void ConnectToActivePrinter(bool showHelpIfNoPort = false)
		{
			if (PrinterConnectionAndCommunication.Instance.ActivePrinter != null)
			{
				// Start the process of requesting permission and exit if permission is not currently granted
				if (!FrostedSerialPort.EnsureDeviceAccess())
				{
					CommunicationState = CommunicationStates.FailedToConnect;
					return;
				}

				PrinterOutputCache.Instance.Clear();
				//Attempt connecting to a specific printer
				this.stopTryingToConnect = false;
				firmwareType = FirmwareTypes.Unknown;
				firmwareVersion = null;
				firmwareUriGcodeSend = false;

				// On Android, there will never be more than one serial port available for us to connect to. Override the current .ComPort value to account for
				// this aspect to ensure the validation logic that verifies port availability/in use status can proceed without additional workarounds for Android
#if __ANDROID__
				string currentPortName = FrostedSerialPort.GetPortNames().FirstOrDefault();
				if (!string.IsNullOrEmpty(currentPortName))
				{
					// TODO: Ensure that this does *not* cause a write to the settings file and should be an in memory update only
					ActiveSliceSettings.Instance?.Helpers.SetComPort(currentPortName);
				}
#endif

				if (SerialPortIsAvailable(this.ComPort))
				{
					//Create a timed callback to determine whether connection succeeded
					Timer connectionTimer = new Timer(new TimerCallback(ConnectionCallbackTimer));
					connectionTimer.Change(100, 0);

					//Create and start connection thread
					connectThread = new Thread(Connect_Thread);
					connectThread.Name = "Connect To Printer";
					connectThread.IsBackground = true;
					connectThread.Start();
				}
				else
				{
					Debug.WriteLine("Connection failed: {0}".FormatWith(this.ComPort));

					connectionFailureMessage = string.Format(
										"{0} is not available".Localize(),
										this.ComPort);

					OnConnectionFailed(null);

#if !__ANDROID__
					// Only pop up the com port helper if the USER actually CLICKED the connect button.
					if (showHelpIfNoPort)
					{
						WizardWindow.ShowComPortSetup();
					}
#endif
				}
			}
		}
        private void ConnectToPrinter(Printer printerRecord)
        {
            LinesToWriteQueue.Clear();
            //Attempt connecting to a specific printer
            CommunicationState = CommunicationStates.AttemptingToConnect;
            this.stopTryingToConnect = false;
            firmwareType = FirmwareTypes.Unknown;
            firmwareVersion = null;

            if (SerialPortIsAvailable(this.ActivePrinter.ComPort))
            {
                //Create a timed callback to determine whether connection succeeded
                Timer connectionTimer = new Timer(new TimerCallback(ConnectionCallbackTimer));
                connectionTimer.Change(100, 0);

                //Create and start connection thread
                connectThread = new Thread(Connect_Thread);
				connectThread.Name = "Connect To Printer";
                connectThread.IsBackground = true;
                connectThread.Start();
            }
            else
            {
                Debug.WriteLine(string.Format("Connection failed: {0}", this.ActivePrinter.ComPort));
				connectionFailureMessage = "Unavailable";
                OnConnectionFailed(null);
            }
        }
Пример #6
0
 public SimulatedMachine(FirmwareTypes firmwareType)
 {
     _firmwareType = firmwareType;
 }