Skip to content

Commit

Permalink
Add settings save and load functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
NiceCircuits committed Nov 23, 2015
1 parent 515d533 commit 28fa81f
Show file tree
Hide file tree
Showing 11 changed files with 168 additions and 42 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DualTerminal/obj
/DualTerminal/bin/Debug
/DualTerminal/bin/Release/DualTerminal.pdb
Binary file modified DualTerminal.suo
Binary file not shown.
4 changes: 3 additions & 1 deletion DualTerminal/DualTerminal.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
Expand All @@ -25,7 +26,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
Expand Down Expand Up @@ -69,6 +69,7 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
Expand All @@ -82,6 +83,7 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
Expand Down
52 changes: 26 additions & 26 deletions DualTerminal/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 18 additions & 9 deletions DualTerminal/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ public Form1()
InitializeComponent();
toolStripComboBoxBaud.SelectedIndex = 4;
int nPorts = refreshPorts();
if (nPorts >= 2)
{
toolStripComboBoxPort1.SelectedIndex = 0;
toolStripComboBoxPort2.SelectedIndex = 1;
}
//if (nPorts >= 2)
//{
// toolStripComboBoxPort1.SelectedIndex = 0;
// toolStripComboBoxPort2.SelectedIndex = 1;
//}
toolStripComboBoxPort1.Text = Properties.Settings.Default.port1;
toolStripComboBoxPort2.Text = Properties.Settings.Default.port2;
toolStripComboBoxBaud.Text = Properties.Settings.Default.baudrate.ToString();
}

// Append text of the given color.
Expand Down Expand Up @@ -93,10 +96,10 @@ private void openToolStripMenuItem_Click(object sender=null, EventArgs e=null)
{
try
{
serialPort1.PortName = toolStripComboBoxPort1.SelectedItem.ToString();
serialPort2.PortName = toolStripComboBoxPort2.SelectedItem.ToString();
serialPort1.BaudRate = Int32.Parse(toolStripComboBoxBaud.SelectedItem.ToString());
serialPort2.BaudRate = Int32.Parse(toolStripComboBoxBaud.SelectedItem.ToString());
serialPort1.PortName = toolStripComboBoxPort1.Text;
serialPort2.PortName = toolStripComboBoxPort2.Text;
serialPort1.BaudRate = Int32.Parse(toolStripComboBoxBaud.Text);
serialPort2.BaudRate = Int32.Parse(toolStripComboBoxBaud.Text);
serialPort1.Open();
serialPort2.Open();
openToolStripMenuItem.Enabled = false;
Expand Down Expand Up @@ -130,6 +133,10 @@ private void serialPort1_DataReceived(object sender, SerialDataReceivedEventArgs
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
closeToolStripMenuItem_Click();
Properties.Settings.Default.port1 = toolStripComboBoxPort1.Text;
Properties.Settings.Default.port2 = toolStripComboBoxPort2.Text;
Properties.Settings.Default.baudrate = Int32.Parse(toolStripComboBoxBaud.Text);
Properties.Settings.Default.Save();
}

private void serialPort2_DataReceived(object sender, SerialDataReceivedEventArgs e)
Expand All @@ -141,5 +148,7 @@ private void clearToolStripMenuItem_Click(object sender, EventArgs e)
{
richTextBox1.Clear();
}


}
}
36 changes: 36 additions & 0 deletions DualTerminal/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 14 additions & 6 deletions DualTerminal/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DualTerminal.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="port1" Type="System.String" Scope="User">
<Value Profile="(Default)">COM1</Value>
</Setting>
<Setting Name="port2" Type="System.String" Scope="User">
<Value Profile="(Default)">COM2</Value>
</Setting>
<Setting Name="baudrate" Type="System.Int32" Scope="User">
<Value Profile="(Default)">9600</Value>
</Setting>
</Settings>
</SettingsFile>
28 changes: 28 additions & 0 deletions DualTerminal/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace DualTerminal.Properties {


// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {

public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}

private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}

private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}
21 changes: 21 additions & 0 deletions DualTerminal/app.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DualTerminal.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<DualTerminal.Properties.Settings>
<setting name="port1" serializeAs="String">
<value>COM1</value>
</setting>
<setting name="port2" serializeAs="String">
<value>COM2</value>
</setting>
<setting name="baudrate" serializeAs="String">
<value>9600</value>
</setting>
</DualTerminal.Properties.Settings>
</userSettings>
</configuration>
Binary file modified DualTerminal/bin/Release/DualTerminal.exe
Binary file not shown.
21 changes: 21 additions & 0 deletions DualTerminal/bin/Release/DualTerminal.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="DualTerminal.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<userSettings>
<DualTerminal.Properties.Settings>
<setting name="port1" serializeAs="String">
<value>COM1</value>
</setting>
<setting name="port2" serializeAs="String">
<value>COM2</value>
</setting>
<setting name="baudrate" serializeAs="String">
<value>9600</value>
</setting>
</DualTerminal.Properties.Settings>
</userSettings>
</configuration>

0 comments on commit 28fa81f

Please sign in to comment.