Initialer Import
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
# Build
|
||||
bin/
|
||||
obj/
|
||||
|
||||
# Visual Studio
|
||||
.vs/
|
||||
*.user
|
||||
*.suo
|
||||
|
||||
# VS Code
|
||||
.vscode/
|
||||
|
||||
# Rider
|
||||
.idea/
|
||||
|
||||
# Logs
|
||||
*.log
|
||||
|
||||
# Windows
|
||||
Thumbs.db
|
||||
Desktop.ini
|
||||
@@ -0,0 +1,27 @@
|
||||
# RTC-Control / Rtc5MiniControl
|
||||
|
||||
## Ziel
|
||||
Steuerung eines RTC5 Mini Systems zur Laserbearbeitung.
|
||||
|
||||
## Technologien
|
||||
- C#
|
||||
- .NET 8
|
||||
- Windows Forms
|
||||
|
||||
## Projektstruktur
|
||||
- MainForm.cs: Haupt-GUI
|
||||
- Rtc5Controller.cs: RTC5-Ansteuerung
|
||||
- Models.cs: Datenmodelle
|
||||
- CsvPathLoader.cs: CSV-Import
|
||||
|
||||
## Wichtige Regeln
|
||||
- Keine Build-Artefakte committen.
|
||||
- Kleine nachvollziehbare Commits.
|
||||
- Vor größeren Refactorings bestehende Struktur analysieren.
|
||||
- Hardwarezugriffe vorsichtig ändern.
|
||||
|
||||
## Build
|
||||
dotnet build
|
||||
|
||||
## Start
|
||||
dotnet run
|
||||
@@ -0,0 +1,65 @@
|
||||
# RTC5 Mini Control
|
||||
|
||||
Kleine C#/.NET-WinForms-Testapp fuer eine SCANLAB RTC5-Karte.
|
||||
|
||||
## Voraussetzungen
|
||||
|
||||
- Windows 11
|
||||
- RTC5-Treiber installiert
|
||||
- .NET 8 Desktop SDK oder Visual Studio Community mit ".NET desktop development"
|
||||
- RTC5-Dateien/DLLs aus dem SCANLAB-SDK, typischerweise:
|
||||
- `RTC5DLLx64.dll`
|
||||
- `RTC5DAT.dat`
|
||||
- `RTC5RBF.rbf`
|
||||
- `RTC5OUT.out`
|
||||
|
||||
Im Feld `RTC-Dateien` in der App den Ordner mit diesen Dateien auswaehlen. Wenn kein Korrekturfile angegeben wird, wird die RTC5 mit der internen 1:1-Korrektur initialisiert. Optional kann eine `.ct5`-Datei von SCANLAB angegeben werden.
|
||||
Die GUI ist in eine linke Seitenleiste und eine grosse Vorschauflaeche aufgeteilt. In der Seitenleiste trennen Tabs `Grundeinstellungen`, `Manuell` und `Prozess`.
|
||||
Der Button `Stop / Laser aus` sitzt fest oben in der Seitenleiste und bleibt in jedem Tab erreichbar.
|
||||
|
||||
## CSV-Format
|
||||
|
||||
```csv
|
||||
0,0
|
||||
1,0
|
||||
1,1
|
||||
|
||||
2,1
|
||||
2,2
|
||||
```
|
||||
|
||||
Koordinaten sind Millimeter. Eine Leerzeile bedeutet: der naechste Koordinatenwechsel wird als `jump_abs` mit Laser aus ausgefuehrt. Fortlaufende Zeilen werden als `mark_abs` verarbeitet.
|
||||
Optionales Format `X,Y,Z` wird ebenfalls akzeptiert; `Z` wird ignoriert.
|
||||
|
||||
## Wichtige Startwerte
|
||||
|
||||
- `Kalib. bits/mm`: Umrechnung von mm in RTC-Koordinaten. Typisch 1000 bis 100000.
|
||||
- `Laser Mode`: Default `0`. Fuer andere Laserarten ggf. gemaess SCANLAB-Handbuch anpassen.
|
||||
- `Laser Control`: Basis-Hex-Wert, Default `0x0`.
|
||||
- `LASERON low-aktiv / invertiert`: setzt intern die Low-Active-Bits `0x18`, wie in SCANLABs CO2/YAG-Demos beschrieben.
|
||||
- `Jump Speed`, `Mark Speed`: Werte in RTC-Einheiten `bits/ms`.
|
||||
|
||||
Die Buttons `LASERON an/aus` steuern den Laser-Ausgang direkt ueber `laser_signal_on()` und `laser_signal_off()`. Beim ersten Einschalten fragt die App nach einer Bestaetigung.
|
||||
|
||||
## Zusatzfunktionen
|
||||
|
||||
- `Home 0,0`: springt mit Laser aus auf X/Y `0,0`.
|
||||
- `Wiederholungen`: fuehrt dieselbe CSV-Datei ein- oder mehrfach aus. Standard ist `1`.
|
||||
- `Job abbrechen nach aktueller Wiederholung`: beendet einen laufenden Mehrfachjob geordnet nach dem aktuellen Durchlauf.
|
||||
- `Skalierung`: multipliziert alle CSV-X/Y-Koordinaten vor Vorschau und Ausfuehrung. Default ist `1`.
|
||||
- `X-Achse umkehren`, `Y-Achse umkehren`: spiegelt die CSV-Koordinaten fuer andere Koordinatensysteme.
|
||||
- `CSV ohne Laser`: faehrt die CSV-Koordinaten ohne Markierbewegungen ab.
|
||||
- `Geometrie-Vorschau`: zeichnet die CSV-Kontur bei Bedarf; grosse Dateien werden fuer die Anzeige ausgeduennt.
|
||||
- In der Vorschau: `Fit` oder Doppelklick passt alles ein, `Ctrl+Mausrad` zoomt um den Mauszeiger, Ziehen verschiebt die Ansicht.
|
||||
- `Tabellenvorschau anzeigen`: blendet die Koordinatentabelle optional ein. Standardmaessig bleibt sie ausgeblendet.
|
||||
- `Grenzcheck`: prueft vor CSV-Start, ob alle Punkte innerhalb der angegebenen X/Y-Grenzen liegen.
|
||||
- Nach der letzten ausgefuehrten CSV-Wiederholung springt die App mit Laser aus auf X/Y `0,0`.
|
||||
- `Einstellungen speichern`: schreibt die aktuellen Einstellungen nach `%AppData%\Rtc5MiniControl\settings.json` und laedt sie beim naechsten Programmstart wieder.
|
||||
|
||||
## Bauen
|
||||
|
||||
```powershell
|
||||
dotnet build .\Rtc5MiniControl.csproj -c Release
|
||||
```
|
||||
|
||||
Falls `dotnet --info` keine SDKs zeigt, muss zuerst das .NET 8 SDK oder Visual Studio Community installiert werden.
|
||||
@@ -0,0 +1,64 @@
|
||||
Dies ist zunächst eine Ideensammlung - noch nichts ändern!
|
||||
|
||||
Automatische Energiekalibration des Lasers
|
||||
über RTC5 Analogausgang und Ophir Juno Powermeter.
|
||||
|
||||
## Hardware
|
||||
|
||||
- RTC5 Mini
|
||||
- Analog Out
|
||||
- Digital Out
|
||||
|
||||
- Laser
|
||||
- Leistungssteuerung per Analogspannung
|
||||
|
||||
- Spiegel
|
||||
- Schaltung per Digitalausgang
|
||||
|
||||
- Ophir Juno Powermeter
|
||||
- Leistungsmessung über DLL/API (COM-Objekt)
|
||||
|
||||
## Sequenz
|
||||
|
||||
1. Spiegel in Messposition schalten
|
||||
2. Wartezeit bis Spiegel stabil
|
||||
3. Referenzspannung setzen
|
||||
4. Wartezeit bis Laser stabil
|
||||
5. Laserleistung messen
|
||||
6. Mehrfachmessung mitteln
|
||||
7. Messwert speichern
|
||||
8. Nächste Spannung
|
||||
9. Spiegel zurückschalten
|
||||
|
||||
## Timing
|
||||
|
||||
- Spiegelumschaltung:
|
||||
~200 ms Wartezeit
|
||||
|
||||
- Laserstabilisierung:
|
||||
~500 ms
|
||||
|
||||
- Powermeter:
|
||||
thermisch träge
|
||||
ggf. Mittelung notwendig
|
||||
|
||||
## Sicherheitsregeln
|
||||
|
||||
- Bei Fehler:
|
||||
- Laser sofort deaktivieren
|
||||
- Analogausgang auf 0
|
||||
- Spiegel in sicheren Zustand
|
||||
|
||||
- Keine Laserfreigabe ohne gültige Hardwareverbindung
|
||||
|
||||
## Offene Fragen
|
||||
|
||||
- Wie schnell aktualisiert Ophir?
|
||||
- Blocking oder async API?
|
||||
- Welche Spannungsskala?
|
||||
- Messbereich linear?
|
||||
- Mittelwertbildung nötig?
|
||||
- Invertierbar
|
||||
- Welche Ein/Ausgänge
|
||||
- Messkurve > Wie lange bis Wert stabil?
|
||||
-
|
||||
Binary file not shown.
Binary file not shown.
File diff suppressed because one or more lines are too long
@@ -0,0 +1,2 @@
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Rtc5MiniControl;
|
||||
|
||||
internal static class AppSettingsStore
|
||||
{
|
||||
private static readonly JsonSerializerOptions SerializerOptions = new()
|
||||
{
|
||||
WriteIndented = true
|
||||
};
|
||||
|
||||
public static string SettingsFile { get; } = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
"Rtc5MiniControl",
|
||||
"settings.json");
|
||||
|
||||
public static AppSettings Load()
|
||||
{
|
||||
if (!File.Exists(SettingsFile))
|
||||
{
|
||||
return new AppSettings();
|
||||
}
|
||||
|
||||
var json = File.ReadAllText(SettingsFile);
|
||||
return JsonSerializer.Deserialize<AppSettings>(json, SerializerOptions) ?? new AppSettings();
|
||||
}
|
||||
|
||||
public static void Save(AppSettings settings)
|
||||
{
|
||||
var directory = Path.GetDirectoryName(SettingsFile);
|
||||
if (!string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var json = JsonSerializer.Serialize(settings, SerializerOptions);
|
||||
File.WriteAllText(SettingsFile, json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace Rtc5MiniControl;
|
||||
|
||||
internal static class CsvPathLoader
|
||||
{
|
||||
public static IReadOnlyList<ScanPoint> Load(string path)
|
||||
{
|
||||
var points = new List<ScanPoint>();
|
||||
var breakBeforeNextPoint = true;
|
||||
var lines = File.ReadLines(path);
|
||||
var lineNumber = 0;
|
||||
|
||||
foreach (var rawLine in lines)
|
||||
{
|
||||
lineNumber++;
|
||||
var line = rawLine.Trim();
|
||||
|
||||
if (line.Length == 0)
|
||||
{
|
||||
breakBeforeNextPoint = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (line.StartsWith("#", StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var parts = line.Split(new[] { ',', ';', '\t' }, StringSplitOptions.TrimEntries);
|
||||
if (parts.Length < 2)
|
||||
{
|
||||
throw new FormatException($"Zeile {lineNumber}: Erwartet wird X,Y oder X,Y,Z.");
|
||||
}
|
||||
|
||||
// RTC5 Mini Control is a 2D tool; optional Z columns are accepted and ignored.
|
||||
var x = ParseDouble(parts[0], lineNumber);
|
||||
var y = ParseDouble(parts[1], lineNumber);
|
||||
if (!double.IsFinite(x) || !double.IsFinite(y))
|
||||
{
|
||||
throw new FormatException($"Zeile {lineNumber}: Koordinaten müssen endliche Zahlen sein.");
|
||||
}
|
||||
|
||||
var laserFromPrevious = points.Count > 0 && !breakBeforeNextPoint;
|
||||
|
||||
points.Add(new ScanPoint(x, y, laserFromPrevious, lineNumber));
|
||||
breakBeforeNextPoint = false;
|
||||
}
|
||||
|
||||
if (points.Count == 0)
|
||||
{
|
||||
throw new FormatException("Die CSV-Datei enthält keine Koordinaten.");
|
||||
}
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
private static double ParseDouble(string value, int lineNumber)
|
||||
{
|
||||
if (double.TryParse(value, NumberStyles.Float, CultureInfo.InvariantCulture, out var invariant))
|
||||
{
|
||||
return invariant;
|
||||
}
|
||||
|
||||
if (double.TryParse(value, NumberStyles.Float, CultureInfo.CurrentCulture, out var current))
|
||||
{
|
||||
return current;
|
||||
}
|
||||
|
||||
throw new FormatException($"Zeile {lineNumber}: '{value}' ist keine gültige Zahl.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
global using System;
|
||||
global using System.Collections.Generic;
|
||||
global using System.Drawing;
|
||||
global using System.IO;
|
||||
global using System.Linq;
|
||||
global using System.Threading;
|
||||
global using System.Threading.Tasks;
|
||||
global using System.Windows.Forms;
|
||||
+1384
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,70 @@
|
||||
namespace Rtc5MiniControl;
|
||||
|
||||
internal sealed record ScanPoint(double Xmm, double Ymm, bool LaserFromPrevious, int SourceLine);
|
||||
|
||||
internal sealed record RtcStatus(
|
||||
uint Busy,
|
||||
uint Position,
|
||||
uint LastError,
|
||||
uint DllVersion,
|
||||
uint SerialNumber,
|
||||
uint HexVersion,
|
||||
uint RtcVersion,
|
||||
uint LaserPinInput);
|
||||
|
||||
internal sealed record RtcProgress(int Percent, uint Busy, uint Position, string Message);
|
||||
|
||||
internal sealed class Rtc5ConnectionSettings
|
||||
{
|
||||
public const uint LaserSignalLowActiveMask = 0x18U;
|
||||
|
||||
public uint CardNumber { get; set; } = 1;
|
||||
public string? RtcFilesDirectory { get; set; }
|
||||
public string? CorrectionFile { get; set; }
|
||||
public double CalibrationFactor { get; set; } = 10000.0;
|
||||
public uint LaserMode { get; set; } = 0;
|
||||
public uint LaserControl { get; set; } = 0;
|
||||
public bool LaserSignalsLowActive { get; set; }
|
||||
public double JumpSpeed { get; set; } = 1000.0;
|
||||
public double MarkSpeed { get; set; } = 250.0;
|
||||
public uint JumpDelay { get; set; } = 25;
|
||||
public uint MarkDelay { get; set; } = 10;
|
||||
public uint PolygonDelay { get; set; } = 5;
|
||||
public int LaserOnDelay { get; set; } = 100;
|
||||
public uint LaserOffDelay { get; set; } = 100;
|
||||
public uint LaserHalfPeriod { get; set; } = 800;
|
||||
public uint LaserPulseWidth { get; set; } = 400;
|
||||
|
||||
public Rtc5ConnectionSettings Clone() => (Rtc5ConnectionSettings)MemberwiseClone();
|
||||
|
||||
public uint EffectiveLaserControl =>
|
||||
LaserSignalsLowActive
|
||||
? LaserControl | LaserSignalLowActiveMask
|
||||
: LaserControl & ~LaserSignalLowActiveMask;
|
||||
}
|
||||
|
||||
internal sealed class PathRunOptions
|
||||
{
|
||||
public bool LaserDisabled { get; set; }
|
||||
public bool BoundsEnabled { get; set; }
|
||||
public int RepeatCount { get; set; } = 1;
|
||||
public double MinXmm { get; set; } = -50.0;
|
||||
public double MaxXmm { get; set; } = 50.0;
|
||||
public double MinYmm { get; set; } = -50.0;
|
||||
public double MaxYmm { get; set; } = 50.0;
|
||||
|
||||
public PathRunOptions Clone() => (PathRunOptions)MemberwiseClone();
|
||||
}
|
||||
|
||||
internal sealed class AppSettings
|
||||
{
|
||||
public Rtc5ConnectionSettings Connection { get; set; } = new();
|
||||
public PathRunOptions PathOptions { get; set; } = new();
|
||||
public string? CsvFile { get; set; }
|
||||
public double StepMm { get; set; } = 1.0;
|
||||
public bool GeometryPreviewEnabled { get; set; } = true;
|
||||
public bool TablePreviewEnabled { get; set; }
|
||||
public double CoordinateScaleFactor { get; set; } = 1.0;
|
||||
public bool InvertX { get; set; }
|
||||
public bool InvertY { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Rtc5MiniControl;
|
||||
|
||||
internal static class Program
|
||||
{
|
||||
[STAThread]
|
||||
private static void Main()
|
||||
{
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new MainForm());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,576 @@
|
||||
namespace Rtc5MiniControl;
|
||||
|
||||
internal sealed class Rtc5Controller : IDisposable
|
||||
{
|
||||
private readonly object _gate = new();
|
||||
private Rtc5Native? _native;
|
||||
private Rtc5ConnectionSettings _settings = new();
|
||||
private double _currentXmm;
|
||||
private double _currentYmm;
|
||||
private bool _stopAfterCurrentRepeatRequested;
|
||||
private bool _disposed;
|
||||
|
||||
public bool IsConnected => _native is not null;
|
||||
public double CurrentXmm => _currentXmm;
|
||||
public double CurrentYmm => _currentYmm;
|
||||
|
||||
public string Connect(Rtc5ConnectionSettings settings)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
ThrowIfDisposed();
|
||||
DisconnectCore();
|
||||
|
||||
_settings = settings.Clone();
|
||||
_native = new Rtc5Native(NormalizeOptionalDirectory(_settings.RtcFilesDirectory));
|
||||
|
||||
try
|
||||
{
|
||||
var initError = _native.InitRtc5Dll();
|
||||
var cardCount = _native.Rtc5CountCards();
|
||||
if (initError != 0 && cardCount == 0)
|
||||
{
|
||||
throw new InvalidOperationException($"init_rtc5_dll fehlgeschlagen: Fehler {initError}.");
|
||||
}
|
||||
|
||||
if (initError != 0)
|
||||
{
|
||||
var accumulatedErrors = 0U;
|
||||
for (var card = 1U; card <= cardCount; card++)
|
||||
{
|
||||
var cardError = _native.NGetLastError(card);
|
||||
if (cardError == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
accumulatedErrors |= cardError;
|
||||
_native.NResetError(card, cardError);
|
||||
}
|
||||
|
||||
if (accumulatedErrors != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"RTC5-Initialisierung meldet Kartenfehler 0x{accumulatedErrors:X}.");
|
||||
}
|
||||
}
|
||||
|
||||
SelectCardWithVersionRecovery(_settings.CardNumber);
|
||||
|
||||
_native.SetRtc4Mode();
|
||||
_native.StopExecution();
|
||||
|
||||
var programLoadError = _native.LoadProgramFile(NormalizeOptionalDirectory(_settings.RtcFilesDirectory));
|
||||
if (programLoadError != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"load_program_file fehlgeschlagen: Fehler {programLoadError}.");
|
||||
}
|
||||
|
||||
var correctionFile = NormalizeOptionalFile(_settings.CorrectionFile);
|
||||
var correctionError = _native.LoadCorrectionFile(correctionFile, 1U, 2U);
|
||||
if (correctionError != 0)
|
||||
{
|
||||
throw new InvalidOperationException($"load_correction_file fehlgeschlagen: Fehler {correctionError}.");
|
||||
}
|
||||
|
||||
_native.SelectCorrectionTable(1U, 0U);
|
||||
_native.ResetError(uint.MaxValue);
|
||||
_native.ConfigList(uint.MaxValue, 0U);
|
||||
ApplyLaserSetup();
|
||||
ExecuteSetupList(CancellationToken.None, null);
|
||||
_currentXmm = 0.0;
|
||||
_currentYmm = 0.0;
|
||||
|
||||
var status = ReadStatusCore();
|
||||
return $"Verbunden. Karten: {cardCount}, Seriennummer: {status.SerialNumber}, DLL: 0x{status.DllVersion:X}, LaserCtrl effektiv: 0x{_settings.EffectiveLaserControl:X}.";
|
||||
}
|
||||
catch
|
||||
{
|
||||
try
|
||||
{
|
||||
DisconnectCore();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Keep the original initialization exception visible.
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
DisconnectCore();
|
||||
}
|
||||
}
|
||||
|
||||
public RtcStatus ReadStatus()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
EnsureConnected();
|
||||
return ReadStatusCore();
|
||||
}
|
||||
}
|
||||
|
||||
public void RequestStopAfterCurrentRepeat()
|
||||
{
|
||||
_stopAfterCurrentRepeatRequested = true;
|
||||
}
|
||||
|
||||
public void UpdateSettings(Rtc5ConnectionSettings settings)
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_settings = settings.Clone();
|
||||
if (_native is not null)
|
||||
{
|
||||
ApplyLaserSetup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task MoveRelativeAsync(double dxMm, double dyMm, IProgress<RtcProgress>? progress, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
EnsureConnected();
|
||||
var nextX = _currentXmm + dxMm;
|
||||
var nextY = _currentYmm + dyMm;
|
||||
ExecuteJumpTo(nextX, nextY, "Manuelle Bewegung", progress, cancellationToken);
|
||||
_currentXmm = nextX;
|
||||
_currentYmm = nextY;
|
||||
}
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public Task HomeAsync(IProgress<RtcProgress>? progress, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
EnsureConnected();
|
||||
ExecuteJumpTo(0.0, 0.0, "Home 0,0", progress, cancellationToken);
|
||||
_currentXmm = 0.0;
|
||||
_currentYmm = 0.0;
|
||||
}
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public Task<int> RunPathAsync(
|
||||
IReadOnlyList<ScanPoint> points,
|
||||
PathRunOptions options,
|
||||
IProgress<RtcProgress>? progress,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (points.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("Die Punktliste ist leer.", nameof(points));
|
||||
}
|
||||
|
||||
var runOptions = options.Clone();
|
||||
if (runOptions.RepeatCount < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(options), "Die Wiederholzahl muss mindestens 1 sein.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
EnsureConnected();
|
||||
ValidatePath(points, runOptions);
|
||||
var native = _native!;
|
||||
var completedRepeats = 0;
|
||||
_stopAfterCurrentRepeatRequested = false;
|
||||
|
||||
try
|
||||
{
|
||||
var commandCountPerRun = 7 + points.Count;
|
||||
var totalCommandCount = (long)commandCountPerRun * runOptions.RepeatCount;
|
||||
|
||||
for (var repeat = 0; repeat < runOptions.RepeatCount; repeat++)
|
||||
{
|
||||
OpenListForWriting(native, cancellationToken);
|
||||
EmitMotionSetup(native);
|
||||
native.LaserSignalOffList();
|
||||
if (!runOptions.LaserDisabled)
|
||||
{
|
||||
native.EnableLaser();
|
||||
}
|
||||
|
||||
for (var index = 0; index < points.Count; index++)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var point = points[index];
|
||||
var x = ScaleToRtcBits(point.Xmm);
|
||||
var y = ScaleToRtcBits(point.Ymm);
|
||||
|
||||
if (point.LaserFromPrevious && !runOptions.LaserDisabled)
|
||||
{
|
||||
native.MarkAbs(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
native.LaserSignalOffList();
|
||||
native.JumpAbs(x, y);
|
||||
}
|
||||
}
|
||||
|
||||
native.LaserSignalOffList();
|
||||
native.SetEndOfList();
|
||||
native.ExecuteList(1U);
|
||||
|
||||
var completedBeforeRun = (long)repeat * commandCountPerRun;
|
||||
var message = runOptions.RepeatCount == 1
|
||||
? "CSV wird abgearbeitet"
|
||||
: $"CSV Wiederholung {repeat + 1}/{runOptions.RepeatCount}";
|
||||
WaitForCompletion(native, commandCountPerRun, totalCommandCount, completedBeforeRun, message, progress, cancellationToken);
|
||||
completedRepeats++;
|
||||
|
||||
if (_stopAfterCurrentRepeatRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ExecuteJumpTo(0.0, 0.0, "Rücksprung 0,0", progress, cancellationToken);
|
||||
_currentXmm = 0.0;
|
||||
_currentYmm = 0.0;
|
||||
return completedRepeats;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
StopAndForceLaserOffCore();
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ForceLaserOffCore();
|
||||
}
|
||||
}
|
||||
}, cancellationToken);
|
||||
}
|
||||
|
||||
public void LaserOn()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
EnsureConnected();
|
||||
var native = _native!;
|
||||
native.SetLaserMode(_settings.LaserMode);
|
||||
native.SetLaserControl(_settings.EffectiveLaserControl);
|
||||
native.EnableLaser();
|
||||
native.LaserSignalOn();
|
||||
}
|
||||
}
|
||||
|
||||
public void LaserOff()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
EnsureConnected();
|
||||
ForceLaserOffCore();
|
||||
}
|
||||
}
|
||||
|
||||
public void StopAndForceLaserOff()
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
if (_native is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
StopAndForceLaserOffCore();
|
||||
}
|
||||
}
|
||||
|
||||
private void SelectCardWithVersionRecovery(uint cardNumber)
|
||||
{
|
||||
var native = _native!;
|
||||
if (native.SelectRtc(cardNumber) == cardNumber)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var selectError = native.NGetLastError(cardNumber);
|
||||
if ((selectError & 256U) != 0)
|
||||
{
|
||||
var loadError = native.NLoadProgramFile(cardNumber, NormalizeOptionalDirectory(_settings.RtcFilesDirectory));
|
||||
if (loadError == 0 && native.SelectRtc(cardNumber) == cardNumber)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new InvalidOperationException($"RTC5-Karte {cardNumber} konnte nicht ausgewählt werden. Fehler 0x{selectError:X}.");
|
||||
}
|
||||
|
||||
private void ExecuteJumpTo(
|
||||
double xMm,
|
||||
double yMm,
|
||||
string message,
|
||||
IProgress<RtcProgress>? progress,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var native = _native!;
|
||||
try
|
||||
{
|
||||
OpenListForWriting(native, cancellationToken);
|
||||
EmitMotionSetup(native);
|
||||
native.LaserSignalOffList();
|
||||
native.JumpAbs(ScaleToRtcBits(xMm), ScaleToRtcBits(yMm));
|
||||
native.SetEndOfList();
|
||||
native.ExecuteList(1U);
|
||||
WaitForCompletion(native, 8, 8, 0, message, progress, cancellationToken);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
StopAndForceLaserOffCore();
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
ForceLaserOffCore();
|
||||
}
|
||||
}
|
||||
|
||||
private void ExecuteSetupList(CancellationToken cancellationToken, IProgress<RtcProgress>? progress)
|
||||
{
|
||||
var native = _native!;
|
||||
OpenListForWriting(native, cancellationToken);
|
||||
EmitMotionSetup(native);
|
||||
native.LaserSignalOffList();
|
||||
native.SetEndOfList();
|
||||
native.ExecuteList(1U);
|
||||
WaitForCompletion(native, 7, 7, 0, "RTC5-Setup", progress, cancellationToken);
|
||||
}
|
||||
|
||||
private void ApplyLaserSetup()
|
||||
{
|
||||
var native = _native!;
|
||||
native.SetLaserMode(_settings.LaserMode);
|
||||
native.SetLaserControl(_settings.EffectiveLaserControl);
|
||||
ForceLaserOffCore();
|
||||
}
|
||||
|
||||
private void EmitMotionSetup(Rtc5Native native)
|
||||
{
|
||||
native.SetLaserPulses(_settings.LaserHalfPeriod, _settings.LaserPulseWidth);
|
||||
native.SetScannerDelays(_settings.JumpDelay, _settings.MarkDelay, _settings.PolygonDelay);
|
||||
native.SetLaserDelays(_settings.LaserOnDelay, _settings.LaserOffDelay);
|
||||
native.SetJumpSpeed(_settings.JumpSpeed);
|
||||
native.SetMarkSpeed(_settings.MarkSpeed);
|
||||
}
|
||||
|
||||
private void OpenListForWriting(Rtc5Native native, CancellationToken cancellationToken)
|
||||
{
|
||||
for (var attempt = 0; attempt < 400; attempt++)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
if (native.LoadList(1U, 0U) != 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(5);
|
||||
}
|
||||
|
||||
throw new TimeoutException("RTC5-Liste 1 wurde nicht zum Schreiben frei.");
|
||||
}
|
||||
|
||||
private void WaitForCompletion(
|
||||
Rtc5Native native,
|
||||
int commandCount,
|
||||
long totalCommandCount,
|
||||
long completedCommandCount,
|
||||
string message,
|
||||
IProgress<RtcProgress>? progress,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var safeCommandCount = Math.Max(commandCount, 1);
|
||||
var safeTotalCommandCount = Math.Max(totalCommandCount, safeCommandCount);
|
||||
|
||||
while (true)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
native.GetStatus(out var busy, out var position);
|
||||
var clampedPosition = Math.Min(position, (uint)safeCommandCount);
|
||||
var completedOverall = busy == 0
|
||||
? completedCommandCount + safeCommandCount
|
||||
: completedCommandCount + clampedPosition;
|
||||
var percent = busy == 0
|
||||
? 100
|
||||
: Math.Clamp((int)Math.Round(completedOverall * 100.0 / safeTotalCommandCount), 0, 99);
|
||||
progress?.Report(new RtcProgress(percent, busy, position, message));
|
||||
|
||||
if (busy == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(50);
|
||||
}
|
||||
}
|
||||
|
||||
private RtcStatus ReadStatusCore()
|
||||
{
|
||||
var native = _native!;
|
||||
native.GetStatus(out var busy, out var position);
|
||||
return new RtcStatus(
|
||||
busy,
|
||||
position,
|
||||
native.GetLastError(),
|
||||
native.GetDllVersion(),
|
||||
native.GetSerialNumber(),
|
||||
native.GetHexVersion(),
|
||||
native.GetRtcVersion(),
|
||||
native.GetLaserPinInput());
|
||||
}
|
||||
|
||||
private static void ValidatePath(IReadOnlyList<ScanPoint> points, PathRunOptions options)
|
||||
{
|
||||
if (!options.BoundsEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (options.MinXmm > options.MaxXmm || options.MinYmm > options.MaxYmm)
|
||||
{
|
||||
throw new InvalidOperationException("Die Arbeitsfeldgrenzen sind ungültig: Min muss kleiner oder gleich Max sein.");
|
||||
}
|
||||
|
||||
foreach (var point in points)
|
||||
{
|
||||
if (point.Xmm < options.MinXmm || point.Xmm > options.MaxXmm ||
|
||||
point.Ymm < options.MinYmm || point.Ymm > options.MaxYmm)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"CSV-Zeile {point.SourceLine}: Punkt ({point.Xmm:0.###}, {point.Ymm:0.###}) mm liegt außerhalb der Arbeitsfeldgrenzen.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int ScaleToRtcBits(double millimeters)
|
||||
{
|
||||
if (_settings.CalibrationFactor <= 0)
|
||||
{
|
||||
throw new InvalidOperationException("Der Kalibrationsfaktor muss größer als 0 sein.");
|
||||
}
|
||||
|
||||
var scaled = millimeters * _settings.CalibrationFactor;
|
||||
if (!double.IsFinite(scaled))
|
||||
{
|
||||
throw new OverflowException($"Koordinate {millimeters} mm ist kein endlicher RTC-Wert.");
|
||||
}
|
||||
|
||||
if (scaled > int.MaxValue || scaled < int.MinValue)
|
||||
{
|
||||
throw new OverflowException($"Koordinate {millimeters} mm liegt außerhalb des Int32-RTC-Bereichs.");
|
||||
}
|
||||
|
||||
return checked((int)Math.Round(scaled));
|
||||
}
|
||||
|
||||
private void ForceLaserOffCore()
|
||||
{
|
||||
if (_native is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_native.LaserSignalOff();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_native.DisableLaser();
|
||||
}
|
||||
}
|
||||
|
||||
private void StopAndForceLaserOffCore()
|
||||
{
|
||||
if (_native is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_native.StopExecution();
|
||||
}
|
||||
finally
|
||||
{
|
||||
ForceLaserOffCore();
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureConnected()
|
||||
{
|
||||
if (_native is null)
|
||||
{
|
||||
throw new InvalidOperationException("Nicht mit der RTC5 verbunden.");
|
||||
}
|
||||
}
|
||||
|
||||
private void DisconnectCore()
|
||||
{
|
||||
if (_native is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
StopAndForceLaserOffCore();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_native.Dispose();
|
||||
_native = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowIfDisposed()
|
||||
{
|
||||
ObjectDisposedException.ThrowIf(_disposed, this);
|
||||
}
|
||||
|
||||
private static string? NormalizeOptionalDirectory(string? path)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(path))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var fullPath = Path.GetFullPath(path);
|
||||
return fullPath.EndsWith(Path.DirectorySeparatorChar)
|
||||
? fullPath
|
||||
: fullPath + Path.DirectorySeparatorChar;
|
||||
}
|
||||
|
||||
private static string? NormalizeOptionalFile(string? path)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(path) ? null : Path.GetFullPath(path);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Disconnect();
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<UseWindowsForms>true</UseWindowsForms>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,243 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace Rtc5MiniControl;
|
||||
|
||||
internal sealed class Rtc5Native : IDisposable
|
||||
{
|
||||
private readonly IntPtr _libraryHandle;
|
||||
private bool _disposed;
|
||||
|
||||
public Rtc5Native(string? rtcFilesDirectory)
|
||||
{
|
||||
var dllName = Environment.Is64BitProcess ? "RTC5DLLx64.dll" : "RTC5DLL.dll";
|
||||
var dllPath = string.IsNullOrWhiteSpace(rtcFilesDirectory)
|
||||
? dllName
|
||||
: Path.Combine(rtcFilesDirectory, dllName);
|
||||
|
||||
_libraryHandle = NativeLibrary.Load(dllPath);
|
||||
|
||||
InitRtc5Dll = Import<InitRtc5DllDelegate>("init_rtc5_dll");
|
||||
FreeRtc5Dll = Import<FreeRtc5DllDelegate>("free_rtc5_dll");
|
||||
SetRtc4Mode = Import<SetRtc4ModeDelegate>("set_rtc4_mode");
|
||||
Rtc5CountCards = Import<Rtc5CountCardsDelegate>("rtc5_count_cards");
|
||||
SelectRtc = Import<SelectRtcDelegate>("select_rtc");
|
||||
GetDllVersion = Import<GetDllVersionDelegate>("get_dll_version");
|
||||
NGetLastError = Import<NGetLastErrorDelegate>("n_get_last_error");
|
||||
NResetError = Import<NResetErrorDelegate>("n_reset_error");
|
||||
GetLastError = Import<GetLastErrorDelegate>("get_last_error");
|
||||
ResetError = Import<ResetErrorDelegate>("reset_error");
|
||||
GetSerialNumber = Import<GetSerialNumberDelegate>("get_serial_number");
|
||||
GetHexVersion = Import<GetHexVersionDelegate>("get_hex_version");
|
||||
GetRtcVersion = Import<GetRtcVersionDelegate>("get_rtc_version");
|
||||
NLoadProgramFile = Import<NLoadProgramFileDelegate>("n_load_program_file");
|
||||
LoadProgramFile = Import<LoadProgramFileDelegate>("load_program_file");
|
||||
LoadCorrectionFile = Import<LoadCorrectionFileDelegate>("load_correction_file");
|
||||
SelectCorrectionTable = Import<SelectCorrectionTableDelegate>("select_cor_table");
|
||||
StopExecution = Import<StopExecutionDelegate>("stop_execution");
|
||||
GetStatus = Import<GetStatusDelegate>("get_status");
|
||||
ConfigList = Import<ConfigListDelegate>("config_list");
|
||||
LoadList = Import<LoadListDelegate>("load_list");
|
||||
SetEndOfList = Import<SetEndOfListDelegate>("set_end_of_list");
|
||||
ExecuteList = Import<ExecuteListDelegate>("execute_list");
|
||||
JumpAbs = Import<JumpAbsDelegate>("jump_abs");
|
||||
MarkAbs = Import<MarkAbsDelegate>("mark_abs");
|
||||
SetLaserMode = Import<SetLaserModeDelegate>("set_laser_mode");
|
||||
SetLaserControl = Import<SetLaserControlDelegate>("set_laser_control");
|
||||
EnableLaser = Import<EnableLaserDelegate>("enable_laser");
|
||||
DisableLaser = Import<DisableLaserDelegate>("disable_laser");
|
||||
LaserSignalOn = Import<LaserSignalOnDelegate>("laser_signal_on");
|
||||
LaserSignalOff = Import<LaserSignalOffDelegate>("laser_signal_off");
|
||||
LaserSignalOnList = Import<LaserSignalOnListDelegate>("laser_signal_on_list");
|
||||
LaserSignalOffList = Import<LaserSignalOffListDelegate>("laser_signal_off_list");
|
||||
SetLaserPulses = Import<SetLaserPulsesDelegate>("set_laser_pulses");
|
||||
SetLaserDelays = Import<SetLaserDelaysDelegate>("set_laser_delays");
|
||||
SetScannerDelays = Import<SetScannerDelaysDelegate>("set_scanner_delays");
|
||||
SetJumpSpeed = Import<SetJumpSpeedDelegate>("set_jump_speed");
|
||||
SetMarkSpeed = Import<SetMarkSpeedDelegate>("set_mark_speed");
|
||||
GetLaserPinInput = Import<GetLaserPinInputDelegate>("get_laser_pin_in");
|
||||
}
|
||||
|
||||
public InitRtc5DllDelegate InitRtc5Dll { get; }
|
||||
public FreeRtc5DllDelegate FreeRtc5Dll { get; }
|
||||
public SetRtc4ModeDelegate SetRtc4Mode { get; }
|
||||
public Rtc5CountCardsDelegate Rtc5CountCards { get; }
|
||||
public SelectRtcDelegate SelectRtc { get; }
|
||||
public GetDllVersionDelegate GetDllVersion { get; }
|
||||
public NGetLastErrorDelegate NGetLastError { get; }
|
||||
public NResetErrorDelegate NResetError { get; }
|
||||
public GetLastErrorDelegate GetLastError { get; }
|
||||
public ResetErrorDelegate ResetError { get; }
|
||||
public GetSerialNumberDelegate GetSerialNumber { get; }
|
||||
public GetHexVersionDelegate GetHexVersion { get; }
|
||||
public GetRtcVersionDelegate GetRtcVersion { get; }
|
||||
public NLoadProgramFileDelegate NLoadProgramFile { get; }
|
||||
public LoadProgramFileDelegate LoadProgramFile { get; }
|
||||
public LoadCorrectionFileDelegate LoadCorrectionFile { get; }
|
||||
public SelectCorrectionTableDelegate SelectCorrectionTable { get; }
|
||||
public StopExecutionDelegate StopExecution { get; }
|
||||
public GetStatusDelegate GetStatus { get; }
|
||||
public ConfigListDelegate ConfigList { get; }
|
||||
public LoadListDelegate LoadList { get; }
|
||||
public SetEndOfListDelegate SetEndOfList { get; }
|
||||
public ExecuteListDelegate ExecuteList { get; }
|
||||
public JumpAbsDelegate JumpAbs { get; }
|
||||
public MarkAbsDelegate MarkAbs { get; }
|
||||
public SetLaserModeDelegate SetLaserMode { get; }
|
||||
public SetLaserControlDelegate SetLaserControl { get; }
|
||||
public EnableLaserDelegate EnableLaser { get; }
|
||||
public DisableLaserDelegate DisableLaser { get; }
|
||||
public LaserSignalOnDelegate LaserSignalOn { get; }
|
||||
public LaserSignalOffDelegate LaserSignalOff { get; }
|
||||
public LaserSignalOnListDelegate LaserSignalOnList { get; }
|
||||
public LaserSignalOffListDelegate LaserSignalOffList { get; }
|
||||
public SetLaserPulsesDelegate SetLaserPulses { get; }
|
||||
public SetLaserDelaysDelegate SetLaserDelays { get; }
|
||||
public SetScannerDelaysDelegate SetScannerDelays { get; }
|
||||
public SetJumpSpeedDelegate SetJumpSpeed { get; }
|
||||
public SetMarkSpeedDelegate SetMarkSpeed { get; }
|
||||
public GetLaserPinInputDelegate GetLaserPinInput { get; }
|
||||
|
||||
private T Import<T>(string functionName)
|
||||
where T : Delegate
|
||||
{
|
||||
var address = NativeLibrary.GetExport(_libraryHandle, functionName);
|
||||
return Marshal.GetDelegateForFunctionPointer<T>(address);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
FreeRtc5Dll();
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The DLL may not have been initialized successfully.
|
||||
}
|
||||
|
||||
NativeLibrary.Free(_libraryHandle);
|
||||
_disposed = true;
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint InitRtc5DllDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void FreeRtc5DllDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetRtc4ModeDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint Rtc5CountCardsDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint SelectRtcDelegate(uint cardNumber);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint GetDllVersionDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint NGetLastErrorDelegate(uint cardNumber);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void NResetErrorDelegate(uint cardNumber, uint code);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint GetLastErrorDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void ResetErrorDelegate(uint code);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint GetSerialNumberDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint GetHexVersionDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint GetRtcVersionDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Ansi)]
|
||||
public delegate uint NLoadProgramFileDelegate(uint cardNumber, [MarshalAs(UnmanagedType.LPStr)] string? path);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Ansi)]
|
||||
public delegate uint LoadProgramFileDelegate([MarshalAs(UnmanagedType.LPStr)] string? path);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi, CharSet = CharSet.Ansi)]
|
||||
public delegate uint LoadCorrectionFileDelegate([MarshalAs(UnmanagedType.LPStr)] string? name, uint number, uint dimension);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SelectCorrectionTableDelegate(uint headA, uint headB);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void StopExecutionDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void GetStatusDelegate(out uint busy, out uint position);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void ConfigListDelegate(uint memory1, uint memory2);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint LoadListDelegate(uint listNumber, uint position);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetEndOfListDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void ExecuteListDelegate(uint listNumber);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void JumpAbsDelegate(int x, int y);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void MarkAbsDelegate(int x, int y);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetLaserModeDelegate(uint mode);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetLaserControlDelegate(uint control);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void EnableLaserDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void DisableLaserDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void LaserSignalOnDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void LaserSignalOffDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void LaserSignalOnListDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void LaserSignalOffListDelegate();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetLaserPulsesDelegate(uint halfPeriod, uint pulseLength);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetLaserDelaysDelegate(int laserOnDelay, uint laserOffDelay);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetScannerDelaysDelegate(uint jump, uint mark, uint polygon);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetJumpSpeedDelegate(double speed);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate void SetMarkSpeedDelegate(double speed);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
|
||||
public delegate uint GetLaserPinInputDelegate();
|
||||
}
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
0,0
|
||||
1,0
|
||||
1,1
|
||||
|
||||
2,1
|
||||
2,2
|
||||
|
@@ -0,0 +1,277 @@
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$outputDirectory = Join-Path $PSScriptRoot "..\docs"
|
||||
$outputPath = Join-Path $outputDirectory "Rtc5MiniControl-Referenzhandbuch.pdf"
|
||||
New-Item -ItemType Directory -Force -Path $outputDirectory | Out-Null
|
||||
|
||||
$encoding = [System.Text.Encoding]::GetEncoding(1252)
|
||||
|
||||
function ConvertTo-PdfString {
|
||||
param([string]$Text)
|
||||
|
||||
$bytes = $encoding.GetBytes($Text)
|
||||
$builder = [System.Text.StringBuilder]::new()
|
||||
|
||||
foreach ($byte in $bytes) {
|
||||
if ($byte -eq 40 -or $byte -eq 41 -or $byte -eq 92) {
|
||||
[void]$builder.Append("\")
|
||||
[void]$builder.Append([char]$byte)
|
||||
}
|
||||
elseif ($byte -lt 32 -or $byte -gt 126) {
|
||||
[void]$builder.Append("\")
|
||||
[void]$builder.Append([Convert]::ToString($byte, 8).PadLeft(3, "0"))
|
||||
}
|
||||
else {
|
||||
[void]$builder.Append([char]$byte)
|
||||
}
|
||||
}
|
||||
|
||||
return $builder.ToString()
|
||||
}
|
||||
|
||||
function Add-TextLine {
|
||||
param(
|
||||
[System.Text.StringBuilder]$Builder,
|
||||
[string]$Font,
|
||||
[double]$Size,
|
||||
[int]$X,
|
||||
[int]$Y,
|
||||
[string]$Text
|
||||
)
|
||||
|
||||
$escaped = ConvertTo-PdfString $Text
|
||||
[void]$Builder.AppendFormat([System.Globalization.CultureInfo]::InvariantCulture, "BT /{0} {1:0.##} Tf {2} {3} Td ({4}) Tj ET`n", $Font, $Size, $X, $Y, $escaped)
|
||||
}
|
||||
|
||||
function Add-Section {
|
||||
param(
|
||||
[System.Text.StringBuilder]$Builder,
|
||||
[ref]$Y,
|
||||
[string]$Title
|
||||
)
|
||||
|
||||
$Y.Value -= 18
|
||||
Add-TextLine $Builder "F2" 12 42 $Y.Value $Title
|
||||
$Y.Value -= 14
|
||||
}
|
||||
|
||||
function Add-ParagraphLine {
|
||||
param(
|
||||
[System.Text.StringBuilder]$Builder,
|
||||
[ref]$Y,
|
||||
[string]$Text
|
||||
)
|
||||
|
||||
Add-TextLine $Builder "F1" 9.7 42 $Y.Value $Text
|
||||
$Y.Value -= 13
|
||||
}
|
||||
|
||||
function Add-Bullet {
|
||||
param(
|
||||
[System.Text.StringBuilder]$Builder,
|
||||
[ref]$Y,
|
||||
[string]$Text
|
||||
)
|
||||
|
||||
Add-TextLine $Builder "F1" 9.7 52 $Y.Value "- $Text"
|
||||
$Y.Value -= 13
|
||||
}
|
||||
|
||||
function Add-CodeLine {
|
||||
param(
|
||||
[System.Text.StringBuilder]$Builder,
|
||||
[ref]$Y,
|
||||
[string]$Text
|
||||
)
|
||||
|
||||
Add-TextLine $Builder "F3" 9.5 58 $Y.Value $Text
|
||||
$Y.Value -= 12
|
||||
}
|
||||
|
||||
function Add-Header {
|
||||
param(
|
||||
[System.Text.StringBuilder]$Builder,
|
||||
[string]$Title,
|
||||
[string]$PageText
|
||||
)
|
||||
|
||||
[void]$Builder.Append("0.08 0.18 0.27 rg 0 806 595 36 re f`n")
|
||||
[void]$Builder.Append("1 1 1 rg`n")
|
||||
Add-TextLine $Builder "F2" 16 42 820 $Title
|
||||
Add-TextLine $Builder "F1" 9 505 820 $PageText
|
||||
[void]$Builder.Append("0 0 0 rg`n")
|
||||
}
|
||||
|
||||
function Add-Footer {
|
||||
param(
|
||||
[System.Text.StringBuilder]$Builder,
|
||||
[string]$Text
|
||||
)
|
||||
|
||||
[void]$Builder.Append("0.75 0.75 0.75 RG 42 38 m 553 38 l S`n")
|
||||
[void]$Builder.Append("0.35 0.35 0.35 rg`n")
|
||||
Add-TextLine $Builder "F1" 8 42 24 $Text
|
||||
[void]$Builder.Append("0 0 0 rg`n")
|
||||
}
|
||||
|
||||
function New-PageOneContent {
|
||||
$builder = [System.Text.StringBuilder]::new()
|
||||
Add-Header $builder "RTC5 Mini Control - Referenzhandbuch" "Seite 1/2"
|
||||
$y = 780
|
||||
|
||||
Add-Section $builder ([ref]$y) "Zweck und Sicherheit"
|
||||
Add-ParagraphLine $builder ([ref]$y) "Diese Kurzreferenz beschreibt Start, Einrichtung und Bedienung der WinForms-Testapp"
|
||||
Add-ParagraphLine $builder ([ref]$y) "fuer SCANLAB RTC5 mit intelliSCAN III. Die Laserleistung wird extern gesetzt."
|
||||
Add-Bullet $builder ([ref]$y) "Vor jedem Test Shutter, Strahlweg, Probe und Interlocks pruefen."
|
||||
Add-Bullet $builder ([ref]$y) "LASERON an schaltet den RTC-LASER-Ausgang; beim ersten Klick erscheint eine Warnung."
|
||||
Add-Bullet $builder ([ref]$y) "Fuer neue CSVs zuerst CSV ohne Laser oder sehr kleine Leistung verwenden."
|
||||
|
||||
Add-Section $builder ([ref]$y) "Programm starten"
|
||||
Add-Bullet $builder ([ref]$y) "Release-EXE starten: bin\Release\net8.0-windows\Rtc5MiniControl.exe"
|
||||
Add-Bullet $builder ([ref]$y) "Falls aus Visual Studio: Projekt Rtc5MiniControl oeffnen und Starten/F5 ausfuehren."
|
||||
Add-Bullet $builder ([ref]$y) "Das Programm laedt gespeicherte Einstellungen automatisch aus %AppData%."
|
||||
Add-Bullet $builder ([ref]$y) "Links sind Tabs fuer Grundeinstellungen, Manuell und Prozess; rechts die Vorschau."
|
||||
Add-Bullet $builder ([ref]$y) "Stop / Laser aus bleibt oben in der Seitenleiste immer erreichbar."
|
||||
|
||||
Add-Section $builder ([ref]$y) "RTC5 einrichten"
|
||||
Add-Bullet $builder ([ref]$y) "RTC-Dateien: Ordner mit RTC5DLLx64.dll, RTC5DAT.dat, RTC5RBF.rbf und RTC5OUT.out."
|
||||
Add-Bullet $builder ([ref]$y) "Korrekturfile: optional eine passende SCANLAB-.ct5 Datei auswaehlen."
|
||||
Add-Bullet $builder ([ref]$y) "Kalib. bits/mm: Umrechnung von mm in RTC-Koordinaten, z.B. 1000 bis 100000."
|
||||
Add-Bullet $builder ([ref]$y) "Laser Mode und Laser Ctrl hex gemaess System setzen; Default ist Mode 0 und Ctrl 0x0."
|
||||
Add-Bullet $builder ([ref]$y) "LASERON low-aktiv / invertiert setzen, wenn das System active-low erwartet."
|
||||
Add-Bullet $builder ([ref]$y) "Verbinden druecken. Im Log muessen Seriennummer, DLL-Version und Status erscheinen."
|
||||
|
||||
Add-Section $builder ([ref]$y) "Manuelle Tests"
|
||||
Add-Bullet $builder ([ref]$y) "Schritt mm einstellen und mit X-/X+/Y-/Y+ kleine Jump-Bewegungen ausloesen."
|
||||
Add-Bullet $builder ([ref]$y) "Home 0,0 springt mit Laser aus auf den Ursprung und setzt die interne Positionsanzeige."
|
||||
Add-Bullet $builder ([ref]$y) "LASERON an/aus testet den Laser-Ausgang direkt; Farben: rot = an, gruen = aus."
|
||||
Add-Bullet $builder ([ref]$y) "Stop / Laser aus stoppt die Ausfuehrung und erzwingt LASERON aus."
|
||||
|
||||
Add-Footer $builder "RTC5 Mini Control - Kurzreferenz fuer neue Benutzer"
|
||||
return $builder.ToString()
|
||||
}
|
||||
|
||||
function New-PageTwoContent {
|
||||
$builder = [System.Text.StringBuilder]::new()
|
||||
Add-Header $builder "RTC5 Mini Control - Referenzhandbuch" "Seite 2/2"
|
||||
$y = 780
|
||||
|
||||
Add-Section $builder ([ref]$y) "CSV abarbeiten"
|
||||
Add-Bullet $builder ([ref]$y) "CSV-Datei auswaehlen und CSV laden druecken. Rechts erscheint die Geometrie-Vorschau."
|
||||
Add-Bullet $builder ([ref]$y) "Koordinaten sind Millimeter. X,Y,Z ist erlaubt; Z wird ignoriert."
|
||||
Add-Bullet $builder ([ref]$y) "Dezimalpunkt und deutsches Dezimalkomma werden akzeptiert."
|
||||
Add-Bullet $builder ([ref]$y) "Fortlaufende Zeilen werden als Markierbewegung ausgefuehrt."
|
||||
Add-Bullet $builder ([ref]$y) "Eine Leerzeile trennt Konturen: der naechste Punkt wird mit Laser aus angefahren."
|
||||
Add-Bullet $builder ([ref]$y) "Wiederholungen bestimmt, wie oft dieselbe CSV nacheinander ausgefuehrt wird."
|
||||
Add-Bullet $builder ([ref]$y) "Job abbrechen nach aktueller Wiederholung stoppt geordnet nach dem laufenden Durchlauf."
|
||||
Add-Bullet $builder ([ref]$y) "Skalierung multipliziert X/Y; X-Achse und Y-Achse koennen gespiegelt werden."
|
||||
Add-Bullet $builder ([ref]$y) "CSV ohne Laser faehrt alle Punkte als sichere Jump-Bewegungen ab."
|
||||
Add-Bullet $builder ([ref]$y) "Geometrie-Vorschau zeichnet die CSV-Kontur nur bei aktivierter Checkbox."
|
||||
Add-Bullet $builder ([ref]$y) "Fit oder Doppelklick passt ein; Ctrl+Mausrad zoomt; Ziehen verschiebt die Ansicht."
|
||||
Add-Bullet $builder ([ref]$y) "Tabellenvorschau anzeigen blendet die Koordinatentabelle bei Bedarf ein."
|
||||
Add-Bullet $builder ([ref]$y) "Grenzcheck prueft vor dem Start X/Y min/max und bricht bei Ausreissern ab."
|
||||
Add-Bullet $builder ([ref]$y) "CSV starten beginnt die Listenverarbeitung; am Ende springt die App auf X/Y 0,0."
|
||||
|
||||
Add-Section $builder ([ref]$y) "Minimalbeispiel CSV"
|
||||
[void]$builder.Append("0.94 0.94 0.94 rg 48 465 250 88 re f`n0 0 0 rg`n")
|
||||
Add-CodeLine $builder ([ref]$y) "0,0"
|
||||
Add-CodeLine $builder ([ref]$y) "1,0"
|
||||
Add-CodeLine $builder ([ref]$y) "1,1"
|
||||
Add-CodeLine $builder ([ref]$y) ""
|
||||
Add-CodeLine $builder ([ref]$y) "2,1"
|
||||
Add-CodeLine $builder ([ref]$y) "2,2"
|
||||
$y -= 4
|
||||
Add-ParagraphLine $builder ([ref]$y) "Interpretation: 0,0 wird angefahren, 1,0 und 1,1 werden markiert."
|
||||
Add-ParagraphLine $builder ([ref]$y) "Nach der Leerzeile wird 2,1 mit Laser aus angesprungen, 2,2 wird markiert."
|
||||
|
||||
Add-Section $builder ([ref]$y) "Einstellungen speichern"
|
||||
Add-Bullet $builder ([ref]$y) "Einstellungen speichern schreibt Pfade, Laserlogik, Kalibrierung, Speed und CSV-Optionen."
|
||||
Add-Bullet $builder ([ref]$y) "Speicherort: %AppData%\Rtc5MiniControl\settings.json"
|
||||
Add-Bullet $builder ([ref]$y) "Beim naechsten Start werden die Werte automatisch geladen."
|
||||
|
||||
Add-Section $builder ([ref]$y) "Schnelle Fehlersuche"
|
||||
Add-Bullet $builder ([ref]$y) "DLL nicht gefunden: RTC-Dateien-Ordner pruefen und 64-Bit-DLL verwenden."
|
||||
Add-Bullet $builder ([ref]$y) "Keine Karte: Treiber, Stromversorgung, Karte 1 und exklusiven Zugriff pruefen."
|
||||
Add-Bullet $builder ([ref]$y) "Laserlogik falsch: LASERON low-aktiv / invertiert umschalten und mit Messgeraet pruefen."
|
||||
Add-Bullet $builder ([ref]$y) "CSV stoppt sofort: Grenzcheck, Zahlenformat und Leerzeilen kontrollieren."
|
||||
|
||||
Add-Footer $builder "Stand: 2026-05-12 - zweiseitige Kurzreferenz"
|
||||
return $builder.ToString()
|
||||
}
|
||||
|
||||
function New-PdfStreamObject {
|
||||
param([string]$Content)
|
||||
|
||||
$contentBytes = $encoding.GetBytes($Content)
|
||||
$header = $encoding.GetBytes("<< /Length $($contentBytes.Length) >>`nstream`n")
|
||||
$footer = $encoding.GetBytes("`nendstream")
|
||||
$stream = [System.IO.MemoryStream]::new()
|
||||
$stream.Write($header, 0, $header.Length)
|
||||
$stream.Write($contentBytes, 0, $contentBytes.Length)
|
||||
$stream.Write($footer, 0, $footer.Length)
|
||||
return $stream.ToArray()
|
||||
}
|
||||
|
||||
function New-PdfTextObject {
|
||||
param([string]$Text)
|
||||
return $encoding.GetBytes($Text)
|
||||
}
|
||||
|
||||
function Write-Bytes {
|
||||
param(
|
||||
[System.IO.MemoryStream]$Stream,
|
||||
[byte[]]$Bytes
|
||||
)
|
||||
|
||||
$Stream.Write($Bytes, 0, $Bytes.Length)
|
||||
}
|
||||
|
||||
function Write-Text {
|
||||
param(
|
||||
[System.IO.MemoryStream]$Stream,
|
||||
[string]$Text
|
||||
)
|
||||
|
||||
$bytes = $encoding.GetBytes($Text)
|
||||
Write-Bytes $Stream $bytes
|
||||
}
|
||||
|
||||
$pageOne = New-PageOneContent
|
||||
$pageTwo = New-PageTwoContent
|
||||
|
||||
$resources = "<< /Font << /F1 5 0 R /F2 6 0 R /F3 7 0 R >> >>"
|
||||
$objects = @(
|
||||
(New-PdfTextObject "<< /Type /Catalog /Pages 2 0 R >>"),
|
||||
(New-PdfTextObject "<< /Type /Pages /Kids [3 0 R 4 0 R] /Count 2 >>"),
|
||||
(New-PdfTextObject "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Resources $resources /Contents 8 0 R >>"),
|
||||
(New-PdfTextObject "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 595 842] /Resources $resources /Contents 9 0 R >>"),
|
||||
(New-PdfTextObject "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica /Encoding /WinAnsiEncoding >>"),
|
||||
(New-PdfTextObject "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica-Bold /Encoding /WinAnsiEncoding >>"),
|
||||
(New-PdfTextObject "<< /Type /Font /Subtype /Type1 /BaseFont /Courier /Encoding /WinAnsiEncoding >>"),
|
||||
(New-PdfStreamObject $pageOne),
|
||||
(New-PdfStreamObject $pageTwo)
|
||||
)
|
||||
|
||||
$pdf = [System.IO.MemoryStream]::new()
|
||||
Write-Text $pdf "%PDF-1.4`n"
|
||||
|
||||
$offsets = New-Object System.Collections.Generic.List[int]
|
||||
for ($index = 0; $index -lt $objects.Count; $index++) {
|
||||
$objectNumber = $index + 1
|
||||
$offsets.Add([int]$pdf.Position)
|
||||
Write-Text $pdf "$objectNumber 0 obj`n"
|
||||
Write-Bytes $pdf $objects[$index]
|
||||
Write-Text $pdf "`nendobj`n"
|
||||
}
|
||||
|
||||
$xrefOffset = [int]$pdf.Position
|
||||
Write-Text $pdf "xref`n0 $($objects.Count + 1)`n"
|
||||
Write-Text $pdf "0000000000 65535 f `n"
|
||||
foreach ($offset in $offsets) {
|
||||
Write-Text $pdf ("{0:0000000000} 00000 n `n" -f $offset)
|
||||
}
|
||||
|
||||
Write-Text $pdf "trailer`n<< /Size $($objects.Count + 1) /Root 1 0 R >>`nstartxref`n$xrefOffset`n%%EOF`n"
|
||||
|
||||
[System.IO.File]::WriteAllBytes((Resolve-Path $outputDirectory).Path + "\Rtc5MiniControl-Referenzhandbuch.pdf", $pdf.ToArray())
|
||||
Write-Host $outputPath
|
||||
Reference in New Issue
Block a user