vRIO auto-opens COM11 at startup when present
The usual port (device end of the COM1 pair) is selected and opened automatically at launch. Missing or busy just logs to the wire log -- no modal at startup -- and leaves the manual picker in charge. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,12 +8,21 @@ namespace VRio.App;
|
||||
/// <summary>
|
||||
/// vRIO main window: the interactive cockpit panel on the left (the same
|
||||
/// functional map RIOJoy's profile editor shows) and a control strip on the
|
||||
/// right — COM port, device settings, and a live wire log. Open the COM port,
|
||||
/// point RIOJoy at the other end of the null-modem pair, and every click here
|
||||
/// arrives at RIOJoy exactly as if the physical cockpit sent it.
|
||||
/// right — COM port, device settings, and a live wire log. At startup the
|
||||
/// usual port (<see cref="PreferredPort"/>) is opened automatically when it's
|
||||
/// available; otherwise open a COM port by hand. Point RIOJoy at the other
|
||||
/// end of the null-modem pair, and every click here arrives at RIOJoy exactly
|
||||
/// as if the physical cockpit sent it.
|
||||
/// </summary>
|
||||
internal sealed class MainForm : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// vRIO's usual port: the device end of the COM1⇄COM11 com0com pair.
|
||||
/// Auto-opened at startup when present and free; the picker still allows
|
||||
/// any other port.
|
||||
/// </summary>
|
||||
private const string PreferredPort = "COM11";
|
||||
|
||||
private readonly VRioDevice _device = new();
|
||||
private readonly VRioSerialService _service;
|
||||
private readonly PanelCanvas _canvas = new();
|
||||
@@ -248,6 +257,7 @@ internal sealed class MainForm : Form
|
||||
UpdateStatus();
|
||||
PrependLog("vRIO ready. Open a COM port, then point RIOJoy at the other end of the pair.");
|
||||
LoadBindings();
|
||||
AutoOpenPreferredPort();
|
||||
}
|
||||
|
||||
private Panel BuildControlStrip()
|
||||
@@ -307,6 +317,32 @@ internal sealed class MainForm : Form
|
||||
_portBox.SelectedIndex = idx >= 0 ? idx : 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Startup convenience: if <see cref="PreferredPort"/> exists, select it
|
||||
/// and try to open it. Failures (port missing, or busy because another
|
||||
/// vRIO/app holds it) just log — no modal box at launch — and leave the
|
||||
/// manual picker in charge.
|
||||
/// </summary>
|
||||
private void AutoOpenPreferredPort()
|
||||
{
|
||||
int idx = _portBox.Items.IndexOf(PreferredPort);
|
||||
if (idx < 0)
|
||||
{
|
||||
PrependLog($"{PreferredPort} not present — pick a port and open it manually.");
|
||||
return;
|
||||
}
|
||||
|
||||
_portBox.SelectedIndex = idx;
|
||||
try
|
||||
{
|
||||
_service.Open(PreferredPort);
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidOperationException or ArgumentException)
|
||||
{
|
||||
PrependLog($"{PreferredPort} is present but could not be opened ({ex.Message.TrimEnd('.')}) — open it manually once it frees up.");
|
||||
}
|
||||
}
|
||||
|
||||
private void ToggleOpen()
|
||||
{
|
||||
if (_service.IsOpen)
|
||||
|
||||
Reference in New Issue
Block a user