From a60b9b3e4b1cfd8e67caccfd9728e046a8bb6174 Mon Sep 17 00:00:00 2001 From: TTLC198 <41226242+TTLC198@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:50:33 +0300 Subject: [PATCH] Fixed folder for classes interacting with USB --- HSMonitor/Utils/Serial/Serial.cs | 85 ------------------- .../Utils/{ => Usb}/Serial/UpdateVisitor.cs | 0 2 files changed, 85 deletions(-) delete mode 100644 HSMonitor/Utils/Serial/Serial.cs rename HSMonitor/Utils/{ => Usb}/Serial/UpdateVisitor.cs (100%) diff --git a/HSMonitor/Utils/Serial/Serial.cs b/HSMonitor/Utils/Serial/Serial.cs deleted file mode 100644 index 504bf43..0000000 --- a/HSMonitor/Utils/Serial/Serial.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.IO.Ports; -using HSMonitor.Services; - -namespace HSMonitor.Utils.Serial; - -public class Serial : IDisposable -{ - private readonly SerialPort _serialPort; - private readonly SettingsService _settingsService; - - public Serial(SettingsService settingsService) - { - _settingsService = settingsService; - if (_settingsService is {Settings: not null}) - _serialPort = new SerialPort( - string.IsNullOrEmpty(_settingsService.Settings.LastSelectedPort) - ? "COM1" - : _settingsService.Settings.LastSelectedPort, - _settingsService.Settings.LastSelectedBaudRate, - Parity.None, - 8, - StopBits.One); - else - _serialPort = new SerialPort(); - } - - public bool CheckAccess() - { - try - { - return Open(); - } - catch - { - return false; - } - } - - private bool Open() - { - if (_serialPort.IsOpen) - return true; - - try - { - _serialPort.PortName = _settingsService.Settings.LastSelectedPort ?? "COM1"; - _serialPort.Open(); - } - catch - { - _serialPort.Close(); - throw; - } - - return _serialPort.IsOpen; - } - - public void Close() - { - if (!_serialPort.IsOpen) return; - _serialPort.Close(); - } - - public void Write(byte[] data) - { - if (!_serialPort.IsOpen) return; - try - { - _serialPort.Write(data, 0, data.Length); - } - catch - { - _serialPort.Close(); - throw; - } - } - - public void Dispose() - { - _serialPort.Close(); - _serialPort.Dispose(); - } - -} \ No newline at end of file diff --git a/HSMonitor/Utils/Serial/UpdateVisitor.cs b/HSMonitor/Utils/Usb/Serial/UpdateVisitor.cs similarity index 100% rename from HSMonitor/Utils/Serial/UpdateVisitor.cs rename to HSMonitor/Utils/Usb/Serial/UpdateVisitor.cs