public CameraDisplay(QhyCcd camera) { _camera = camera; _form = new DoubleBufferedForm(); _status = "starting..."; Console.WriteLine(camera.Width); Console.WriteLine(camera.Height); _bitmap = new Bitmap(camera.Width, camera.Height, PixelFormat.Format32bppArgb); _form.Paint += OnPaint; }
static void Main(string[] args) { QhyCcd camera = null; Mount mount = null; CameraDisplay display = null; while (true) { Console.Write("> "); Console.Out.Flush(); var cmd = Console.ReadLine().Split((char[])null, StringSplitOptions.RemoveEmptyEntries); if (cmd.Length == 0) { continue; } if (cmd[0] == "quit") { break; } try { if (camera != null) { ReplCamera(cmd, camera, ref display); } else if (mount != null) { ReplMount(cmd, mount).Wait(); } else { ReplMain(cmd, ref camera, ref mount); } } catch (Exception e) { Console.WriteLine($"Error processing command - {e.GetType().FullName}: {e.Message}"); Console.WriteLine(e.ToString()); } } camera?.Dispose(); }
static void ReplMain(string[] cmd, ref QhyCcd camera, ref Mount mount) { switch (cmd[0]) { case "camera": if (cmd.Length == 1) { var numCameras = QhyCcd.NumCameras(); if (numCameras == 0) { Console.WriteLine("No QHY cameras found"); } else if (numCameras == 1) { camera = new QhyCcd(false, 0); Console.WriteLine("One QHY camera found, automatically connected"); } else { Console.WriteLine($"Num cameras: {numCameras}"); for (var i = 0; i < numCameras; i++) { var name = QhyCcd.CameraName(i); Console.WriteLine($"{i} = {name}"); } } } else if (cmd.Length == 2 && int.TryParse(cmd[1], out var index)) { camera = new QhyCcd(false, index); } else { goto default; } break; case "mount": if (cmd.Length == 1) { mount = Mount.Create(); if (mount == null) { var ports = Mount.Ports(); if (ports.Length == 0) { Console.WriteLine("No serial ports"); } else { Console.WriteLine("More than one serial ports:"); Console.WriteLine(string.Join(", ", ports)); } } else { Console.WriteLine("One serial port, automatically connected to mount"); } } else if (cmd.Length == 2) { mount = new Mount(cmd[1]); } else { goto default; } break; case "solve": if (cmd.Length == 2) { //var task = PlateSolve.SolveFile(cmd[1]); Console.WriteLine("TODO"); } else { goto default; } break; default: Console.WriteLine($"Unknown command {string.Join(" ", cmd)}"); break; } }
private static void ReplCamera(string[] cmd, QhyCcd camera, ref CameraDisplay cameraDisplay) { switch (cmd[0]) { case "help": Console.WriteLine("open - runs display"); Console.WriteLine("save - saves image"); Console.WriteLine("save [n] - saves next n images"); Console.WriteLine("solve - plate-solve next image with ANSVR"); Console.WriteLine("solve [filename] - plate-solve image with ANSVR"); Console.WriteLine("controls - prints all controls"); Console.WriteLine("[control name] - prints single control"); Console.WriteLine("[control name] [value] - set control value"); break; case "open": cameraDisplay = new CameraDisplay(camera); cameraDisplay.Start(); break; case "save": if (cmd.Length == 1) { cameraDisplay.Save(1); } else if (cmd.Length == 2 && int.TryParse(cmd[1], out var numToSave)) { cameraDisplay.Save(numToSave); } else { goto default; } break; case "solve": if (cmd.Length == 1) { cameraDisplay.Solve(); } else if (cmd.Length == 2) { var task = PlateSolve.SolveFile(cmd[1]); Console.WriteLine("TODO"); } else { goto default; } break; case "controls": { foreach (var control in camera.Controls) { Console.WriteLine(control.ToString()); } } break; default: { var control = camera.Controls.SingleOrDefault(x => x.Name == cmd[0]); if (control != null && cmd.Length == 1) { Console.WriteLine(control.ToString()); break; } else if (control != null && cmd.Length == 2 && double.TryParse(cmd[1], out var value)) { control.Value = value; break; } Console.WriteLine($"Unknown command {string.Join(" ", cmd)}"); } break; } }