Add List of zero-conf telnet connects to allow auto detection of MCConnect
This commit is contained in:
parent
592bdd5ca9
commit
1d38fa034c
10 changed files with 192 additions and 8 deletions
22
App.config
22
App.config
|
|
@ -1,21 +1,29 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<loadFromRemoteSources enabled="true"/>
|
||||
<loadFromRemoteSources enabled="true" />
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<probing privatePath="lib"/>
|
||||
<probing privatePath="lib" />
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
|
||||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Reactive.Core" publicKeyToken="94bc3704cddfc263" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Reactive.Linq" publicKeyToken="94bc3704cddfc263" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-3.0.3000.0" newVersion="3.0.3000.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
<system.net>
|
||||
<defaultProxy>
|
||||
<proxy bypassonlocal="false" usesystemdefault="true"/>
|
||||
<proxy bypassonlocal="false" usesystemdefault="true" />
|
||||
</defaultProxy>
|
||||
</system.net>
|
||||
</configuration>
|
||||
|
|
|
|||
|
|
@ -155,6 +155,7 @@
|
|||
<Compile Include="PrinterControls\PrinterConnections\PrinterSetup.cs" />
|
||||
<Compile Include="RootSystemWindow.cs" />
|
||||
<Compile Include="SetupWizard\DialogWindow.cs" />
|
||||
<Compile Include="SlicerConfiguration\UIFields\IpAddessField.cs" />
|
||||
<Compile Include="Utilities\InspectForm.cs" Condition="'$(Configuration)' == 'Debug'">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
@ -452,9 +453,25 @@
|
|||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Management" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Reactive.Core, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Reactive.Core.3.1.1\lib\net46\System.Reactive.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reactive.Interfaces, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Reactive.Interfaces.3.1.1\lib\net45\System.Reactive.Interfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reactive.Linq, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Reactive.Linq.3.1.1\lib\net46\System.Reactive.Linq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reactive.PlatformServices, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Reactive.PlatformServices.3.1.1\lib\net46\System.Reactive.PlatformServices.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reactive.Windows.Threading, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.Reactive.Windows.Threading.3.1.1\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>packages\System.ValueTuple.4.4.0\lib\net461\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Windows" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
|
|
@ -465,6 +482,10 @@
|
|||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="WindowsBase" />
|
||||
<Reference Include="Zeroconf, Version=2.9.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Zeroconf.2.9.0\lib\net45\Zeroconf.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
public const string has_sd_card_reader = nameof(has_sd_card_reader);
|
||||
public const string heat_extruder_before_homing = nameof(heat_extruder_before_homing);
|
||||
public const string include_firmware_updater = nameof(include_firmware_updater);
|
||||
public const string selector_ip_address = nameof(selector_ip_address);
|
||||
public const string ip_address = nameof(ip_address);
|
||||
public const string ip_port = nameof(ip_port);
|
||||
public const string layer_gcode = nameof(layer_gcode);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
public class SliceSettingData
|
||||
{
|
||||
[JsonConverter(typeof(StringEnumConverter))]
|
||||
public enum DataEditTypes { STRING, INT, INT_OR_MM, DOUBLE, POSITIVE_DOUBLE, OFFSET, DOUBLE_OR_PERCENT, VECTOR2, OFFSET2, CHECK_BOX, LIST, MULTI_LINE_TEXT, HARDWARE_PRESENT, COM_PORT };
|
||||
public enum DataEditTypes { STRING, INT, INT_OR_MM, DOUBLE, POSITIVE_DOUBLE, OFFSET, DOUBLE_OR_PERCENT, VECTOR2, OFFSET2, CHECK_BOX, LIST, MULTI_LINE_TEXT, HARDWARE_PRESENT, COM_PORT, IP_LIST };
|
||||
|
||||
public string SlicerConfigName { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -606,6 +606,9 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
uiField = new ExtruderOffsetField(settingsContext, settingData.SlicerConfigName);
|
||||
break;
|
||||
|
||||
case SliceSettingData.DataEditTypes.IP_LIST:
|
||||
uiField = new IpAddessField(printer);
|
||||
break;
|
||||
default:
|
||||
// Missing Setting
|
||||
settingsRow.AddContent(new TextWidget(String.Format("Missing the setting for '{0}'.", settingData.DataEditType.ToString()))
|
||||
|
|
|
|||
|
|
@ -136,6 +136,7 @@ namespace MatterHackers.MatterControl.SlicerConfiguration
|
|||
new VisibleButNotMappedToEngine("solid_shell"),
|
||||
new VisibleButNotMappedToEngine(SettingsKey.laser_speed_025),
|
||||
new VisibleButNotMappedToEngine(SettingsKey.laser_speed_100),
|
||||
new VisibleButNotMappedToEngine("selector_ip_address"),
|
||||
};
|
||||
|
||||
matterSliceSettingNames = new HashSet<string>(mappedSettings.Select(m => m.CanonicalSettingsName));
|
||||
|
|
|
|||
127
SlicerConfiguration/UIFields/IpAddessField.cs
Normal file
127
SlicerConfiguration/UIFields/IpAddessField.cs
Normal file
|
|
@ -0,0 +1,127 @@
|
|||
using MatterHackers.Agg;
|
||||
using MatterHackers.Agg.UI;
|
||||
using MatterHackers.Localizations;
|
||||
using MatterHackers.MatterControl.PrinterCommunication;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MatterHackers.SerialPortCommunication.FrostedSerial;
|
||||
using Zeroconf;
|
||||
|
||||
namespace MatterHackers.MatterControl.SlicerConfiguration
|
||||
{
|
||||
class IpAddessField : UIField
|
||||
{
|
||||
private DropDownList dropdownList;
|
||||
|
||||
private PrinterConfig printer;
|
||||
|
||||
public IpAddessField(PrinterConfig printer)
|
||||
{
|
||||
this.printer = printer;
|
||||
}
|
||||
|
||||
public override void Initialize(int tabIndex)
|
||||
{
|
||||
EventHandler unregisterEvents = null;
|
||||
|
||||
base.Initialize(tabIndex);
|
||||
bool canChangeComPort = !printer.Connection.PrinterIsConnected && printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect;
|
||||
dropdownList = new DropDownList("Manual".Localize(), maxHeight: 200)
|
||||
{
|
||||
ToolTipText = HelpText,
|
||||
Margin = new BorderDouble(),
|
||||
TabIndex = tabIndex,
|
||||
|
||||
Enabled = canChangeComPort,
|
||||
TextColor = canChangeComPort ? ActiveTheme.Instance.PrimaryTextColor : new Color(ActiveTheme.Instance.PrimaryTextColor, 150),
|
||||
BorderColor = canChangeComPort ? ActiveTheme.Instance.SecondaryTextColor : new Color(ActiveTheme.Instance.SecondaryTextColor, 150),
|
||||
|
||||
|
||||
};
|
||||
|
||||
dropdownList.Click += (s, e) =>
|
||||
{
|
||||
//this blows up without runonidle
|
||||
//RebuildMenuItems();
|
||||
};
|
||||
|
||||
RebuildMenuItems();
|
||||
|
||||
// Prevent droplist interaction when connected
|
||||
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) =>
|
||||
{
|
||||
canChangeComPort = !printer.Connection.PrinterIsConnected && printer.Connection.CommunicationState != CommunicationStates.AttemptingToConnect;
|
||||
dropdownList.Enabled = canChangeComPort;
|
||||
dropdownList.TextColor = canChangeComPort ? ActiveTheme.Instance.PrimaryTextColor : new Color(ActiveTheme.Instance.PrimaryTextColor, 150);
|
||||
dropdownList.BorderColor = canChangeComPort ? ActiveTheme.Instance.SecondaryTextColor : new Color(ActiveTheme.Instance.SecondaryTextColor, 150);
|
||||
}, ref unregisterEvents);
|
||||
|
||||
// Release event listener on close
|
||||
dropdownList.Closed += (s, e) =>
|
||||
{
|
||||
unregisterEvents?.Invoke(null, null);
|
||||
};
|
||||
|
||||
this.Content = dropdownList;
|
||||
}
|
||||
|
||||
protected override void OnValueChanged(FieldChangedEventArgs fieldChangedEventArgs)
|
||||
{
|
||||
dropdownList.SelectedLabel = this.Value;
|
||||
base.OnValueChanged(fieldChangedEventArgs);
|
||||
}
|
||||
|
||||
private void RebuildMenuItems()
|
||||
{
|
||||
IReadOnlyList<Zeroconf.IZeroconfHost> possibleHosts = ProbeForNetworkedTelenetConnections().Result;
|
||||
dropdownList.MenuItems.Clear();
|
||||
MenuItem defaultOption = dropdownList.AddItem("Manual", "127.0.0.1:23");
|
||||
defaultOption.Selected += (sender, e) =>
|
||||
{
|
||||
printer.Settings.SetValue(SettingsKey.selector_ip_address,defaultOption.Text);
|
||||
};
|
||||
foreach (Zeroconf.IZeroconfHost host in possibleHosts)
|
||||
{
|
||||
// Add each found telnet host to the dropdown list
|
||||
IService service;
|
||||
bool exists = host.Services.TryGetValue("_telnet._tcp.local.", out service);
|
||||
int port = exists ? service.Port:23;
|
||||
MenuItem newItem = dropdownList.AddItem(host.DisplayName, $"{host.IPAddress}:{port}"); //The port may be unnecessary
|
||||
// When the given menu item is selected, save its value back into settings
|
||||
newItem.Selected += (sender, e) =>
|
||||
{
|
||||
if (sender is MenuItem menuItem)
|
||||
{
|
||||
//this.SetValue(
|
||||
// menuItem.Text,
|
||||
// userInitiated: true);
|
||||
string[] ipAndPort = menuItem.Value.Split(':');
|
||||
printer.Settings.SetValue(SettingsKey.ip_address, ipAndPort[0]);
|
||||
printer.Settings.SetValue(SettingsKey.ip_port, ipAndPort[1]);
|
||||
printer.Settings.SetValue(SettingsKey.selector_ip_address, menuItem.Text);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void DefaultOption_Selected(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static async Task<IReadOnlyList<Zeroconf.IZeroconfHost>> ProbeForNetworkedTelenetConnections()
|
||||
{
|
||||
return await ZeroconfResolver.ResolveAsync("_telnet._tcp.local.");
|
||||
}
|
||||
|
||||
public static async Task<IReadOnlyList<Zeroconf.IZeroconfHost>> EnumerateAllServicesFromAllHosts()
|
||||
{
|
||||
ILookup<string, string> domains = await ZeroconfResolver.BrowseDomainsAsync();
|
||||
return await ZeroconfResolver.ResolveAsync(domains.Select(g => g.Key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,6 +15,7 @@ Simple
|
|||
auto_connect
|
||||
baud_rate
|
||||
com_port
|
||||
selector_ip_address
|
||||
ip_address
|
||||
ip_port
|
||||
Intermediate
|
||||
|
|
@ -81,6 +82,7 @@ Intermediate
|
|||
auto_connect
|
||||
baud_rate
|
||||
com_port
|
||||
selector_ip_address
|
||||
ip_address
|
||||
ip_port
|
||||
Advanced
|
||||
|
|
@ -266,6 +268,7 @@ Advanced
|
|||
auto_connect
|
||||
baud_rate
|
||||
com_port
|
||||
selector_ip_address
|
||||
ip_address
|
||||
ip_port
|
||||
Print Area
|
||||
|
|
|
|||
|
|
@ -1826,6 +1826,17 @@
|
|||
"RebuildGCodeOnChange": false,
|
||||
"ReloadUiWhenChanged": true
|
||||
},
|
||||
{
|
||||
"SlicerConfigName": "selector_ip_address",
|
||||
"PresentationName": "IP Finder",
|
||||
"HelpText": "List of IP's discovered on the network",
|
||||
"DataEditType": "IP_LIST",
|
||||
"ShowAsOverride": false,
|
||||
"ShowIfSet": "enable_network_printing",
|
||||
"DefaultValue": "Manual",
|
||||
"RebuildGCodeOnChange": false,
|
||||
"ReloadUiWhenChanged": true
|
||||
},
|
||||
{
|
||||
"SlicerConfigName": "ip_address",
|
||||
"PresentationName": "IP Address",
|
||||
|
|
@ -1833,6 +1844,7 @@
|
|||
"DataEditType": "STRING",
|
||||
"ShowAsOverride": false,
|
||||
"ShowIfSet": "enable_network_printing",
|
||||
"EnableIfSet": "selector_ip_address=Manual",
|
||||
"DefaultValue": "127.0.0.1",
|
||||
"RebuildGCodeOnChange": false
|
||||
},
|
||||
|
|
@ -1843,6 +1855,7 @@
|
|||
"DataEditType": "INT",
|
||||
"ShowAsOverride": false,
|
||||
"ShowIfSet": "enable_network_printing",
|
||||
"EnableIfSet": "selector_ip_address=Manual",
|
||||
"DefaultValue": "23",
|
||||
"RebuildGCodeOnChange": false
|
||||
},
|
||||
|
|
|
|||
|
|
@ -2,5 +2,12 @@
|
|||
<packages>
|
||||
<package id="Mindscape.Raygun4Net" version="5.5.2" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
|
||||
<package id="System.Reactive" version="3.1.1" targetFramework="net461" />
|
||||
<package id="System.Reactive.Core" version="3.1.1" targetFramework="net461" />
|
||||
<package id="System.Reactive.Interfaces" version="3.1.1" targetFramework="net461" />
|
||||
<package id="System.Reactive.Linq" version="3.1.1" targetFramework="net461" />
|
||||
<package id="System.Reactive.PlatformServices" version="3.1.1" targetFramework="net461" />
|
||||
<package id="System.Reactive.Windows.Threading" version="3.1.1" targetFramework="net461" />
|
||||
<package id="System.ValueTuple" version="4.4.0" targetFramework="net461" />
|
||||
<package id="Zeroconf" version="2.9.0" targetFramework="net461" />
|
||||
</packages>
|
||||
Loading…
Add table
Add a link
Reference in a new issue