Skip to content

Commit 152127b

Browse files
committed
Optimize SerialPort selection
1 parent 3b8a6b1 commit 152127b

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

src/Nager.FineDustSensor.SensorControl/Form1.Designer.cs

+12-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Nager.FineDustSensor.SensorControl/Form1.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Logging;
22
using Nager.FineDustSensor.Sps30;
3+
using System.IO.Ports;
34

45
namespace Nager.FineDustSensor.SensorControl
56
{
@@ -25,6 +26,11 @@ public Form1()
2526
builder.AddFile("default.log", LogLevel.Trace, outputTemplate: "{Timestamp:HH:mm:ss.fff} {Level:u3} {SourceContext} {Message:lj}{NewLine}{Exception}");
2627
});
2728
}
29+
private void comboBoxSerialPort_DropDown(object sender, EventArgs e)
30+
{
31+
this.comboBoxSerialPort.Items.Clear();
32+
this.comboBoxSerialPort.Items.AddRange(SerialPort.GetPortNames());
33+
}
2834

2935
private void ActivateSensorControls()
3036
{
@@ -50,7 +56,7 @@ private void SwitchConnectDisconnect(bool isConnected)
5056

5157
private async void buttonConnect_Click(object sender, EventArgs e)
5258
{
53-
this._deviceCommunication = new SerialPortDeviceCommunication(this.textBoxSerialPort.Text, logger: this._loggerFactory.CreateLogger<SerialPortDeviceCommunication>());
59+
this._deviceCommunication = new SerialPortDeviceCommunication(this.comboBoxSerialPort.Text, logger: this._loggerFactory.CreateLogger<SerialPortDeviceCommunication>());
5460

5561
this._sps30Client = new Sps30Client(this._deviceCommunication, this._loggerFactory.CreateLogger<Sps30Client>());
5662
if (await this._deviceCommunication.ConnectAsync())

src/Nager.FineDustSensor.SensorControl/Form1.resx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<root>
33
<!--
4-
Microsoft ResX Schema
4+
Microsoft ResX Schema
55
66
Version 2.0
77
@@ -48,7 +48,7 @@
4848
value : The object must be serialized with
4949
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
5050
: and then encoded with base64 encoding.
51-
51+
5252
mimetype: application/x-microsoft.net.object.soap.base64
5353
value : The object must be serialized with
5454
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

0 commit comments

Comments
 (0)