Files
DP44/docs/ai/Common/DTS.Common.IConnection/SerialConnection.md
2026-04-17 14:55:32 -04:00

43 lines
2.5 KiB
Markdown

---
source_files:
- Common/DTS.Common.IConnection/SerialConnection/SerialConnection.cs
generated_at: "2026-04-17T15:43:20.559385+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "b99650f076547574"
---
# Documentation: SerialConnection
## 1. Purpose
`SerialConnection` is an implementation of the `IConnection` interface that wraps `System.IO.Ports.SerialPort` to provide serial port communication capabilities. It exists to allow serial-based devices to be used within a connection abstraction layer that appears designed primarily around socket-based communication patterns (evidenced by the APM-style `Begin*`/`End*` methods and `SocketFlags` property). This class enables the system to treat serial connections uniformly alongside other connection types.
## 2. Public Interface
### Properties
| Signature | Description |
|-----------|-------------|
| `bool IsSoftDisconnected { get; }` | Returns `true` if the unit is soft disconnected. Initialized to `false`. |
| `bool Connected { get; }` | Always returns `false`. Read-only property. |
| `string ConnectString => _PortName` | Returns the port name. |
| `System.Net.Sockets.SocketFlags Flags { get; set; }` | Socket flags property (inherited from interface, not used for serial). |
| `event EventHandler OnDisconnected` | Event for disconnection notification. |
### Methods
| Signature | Description |
|-----------|-------------|
| `void SoftConnect()` | Empty implementation. Comment indicates soft disconnect is not implemented for serial. |
| `void SoftDisconnect()` | Empty implementation. Comment indicates soft disconnect is not implemented for serial. |
| `void Create(string connectString, string hostIPAddress)` | Does nothing. Parameters are ignored. |
| `void Create(string PortName)` | Creates a new `SerialPort` instance with the provided port name and stores the name in `_PortName`. |
| `string GetConnectionData()` | Returns empty string. |
| `double GetCurrentDownloadRate()` | Returns `0D`. |
| `double GetCurrentUploadRate()` | Returns `0D`. |
| `void Dispose()` | Implements `IDisposable`. Calls `Dispose(true)` and suppresses finalization. |
| `IAsyncResult BeginConnect(AsyncCallback cb, object state)` | Opens the serial port. Returns `null`. Throws if `Port` is null or `_PortName` is empty. |
| `void EndConnect(IAsyncResult ar)` | Throws if `Port` is null. No other action. |
| `IAsyncResult BeginDisconnect(bool reuseSocket, AsyncCallback cb, Object state)` | Returns `null`. Throws if `Port` is null. |
| `void EndDisconnect