public void Print(Stream fs) { PrintStarted?.Invoke(this, new PrintEventArgs("printing started")); PrintInternal(fs); PrintCompleted?.Invoke(this, new PrintEventArgs("printing completed")); }
/// <summary> /// Notify the firmware that a print has started /// </summary> /// <param name="to">Destination</param> /// <param name="info">Information about the file being printed</param> /// <returns>Number of bytes written</returns> /// <exception cref="ArgumentException">One of the supplied values is too big</exception> public static int WritePrintStarted(Span <byte> to, ParsedFileInfo info) { Span <byte> unicodeFilename = Encoding.UTF8.GetBytes(info.FileName); if (unicodeFilename.Length > 254) { throw new ArgumentException("Value is too long", nameof(info.FileName)); } Span <byte> unicodeGeneratedBy = Encoding.UTF8.GetBytes(info.GeneratedBy); if (unicodeGeneratedBy.Length > 254) { throw new ArgumentException("Value is too long", nameof(info.GeneratedBy)); } // Write header PrintStarted header = new PrintStarted { FilenameLength = (byte)unicodeFilename.Length, GeneratedByLength = (byte)unicodeGeneratedBy.Length, NumFilaments = (ushort)info.Filament.Count, FileSize = (uint)info.Size, LastModifiedTime = info.LastModified.HasValue ? (ulong)(info.LastModified.Value - new DateTime(1970, 1, 1)).TotalSeconds : 0, FirstLayerHeight = info.FirstLayerHeight, LayerHeight = info.LayerHeight, ObjectHeight = info.Height, PrintTime = (uint)info.PrintTime, SimulatedTime = (uint)info.SimulatedTime }; MemoryMarshal.Write(to, ref header); int bytesWritten = Marshal.SizeOf(header); // Write filaments foreach (double filament in info.Filament) { float filamentUsage = (float)filament; MemoryMarshal.Write(to.Slice(bytesWritten), ref filamentUsage); bytesWritten += Marshal.SizeOf(filamentUsage); } // Write filename unicodeFilename.CopyTo(to.Slice(bytesWritten)); bytesWritten += unicodeFilename.Length; // Write slicer unicodeGeneratedBy.CopyTo(to.Slice(bytesWritten)); bytesWritten += unicodeGeneratedBy.Length; return(AddPadding(to, bytesWritten)); }
protected virtual void OnPrintStarted(EventArgs e) { PrintStarted?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Prints something on the stream. /// </summary> /// <param name="stream">Certain stream.</param> public virtual void Print(Stream stream) { PrintStarted?.Invoke(this, new PrintStartedEventArgs("Print started.")); Printing(stream); PrintFinished?.Invoke(this, new PrintFinishedEventArgs("Print finished")); }
private void OnPrintStarted() { Thread.Sleep(1000); PrintStarted?.Invoke(this, EventArgs.Empty); }