12 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-17T15:39:44.338256+00:00 | zai-org/GLM-5-FP8 | 1 | f84cd76ebff4b497 |
Documentation: DTS.Common.ICommunication
1. Purpose
This module provides the core communication infrastructure for interacting with DAS (Data Acquisition System) hardware. It defines the abstract Communication<T> base class that implements asynchronous connect/disconnect operations, command execution with timeout handling, and a continuous receive loop for hardware communication. The module also defines IDASConnectedDevice for describing devices attached to a DAS (e.g., SLICE6 units on a SLICE6DB), and Communication_DASInfo for encapsulating DAS metadata such as serial numbers, firmware versions, and connected device information.
2. Public Interface
IDASConnectedDevice (interface)
Namespace: DTS.DASLib.Communication
Describes a device connected to a DAS.
| Property | Type | Description |
|---|---|---|
DeviceType |
HardwareTypes |
The device type of the connected device. |
Port |
int |
The port on the DAS which the device is on (0-based). |
SpotOnPort |
int |
The spot on the chain or port the device is on (0-based). |
PhysicalAddress |
PhysicalAddress |
MAC Address or physical address. |
IPAddress |
string |
The IP address of the device. |
SerialNumber |
string |
The serial number of the device. |
Location |
string |
The location of the device. |
Version |
string |
The version of the device. |
CanceledException (class)
Namespace: DTS.Common.ICommunication
Base: ApplicationException
Marker exception thrown when operations are canceled.
Communication_DASInfo (class)
Namespace: DTS.Common.ICommunication
Implements: ICommunication_DASInfo
Encapsulates metadata about a DAS device.
| Property | Type | Description |
|---|---|---|
FirstUseDate |
DateTime? |
Date of first use; null indicates hardware not used since calibration. Only valid when IsFirstUseDateSupported is true. |
IsFirstUseDateSupported |
bool |
Indicates hardware supports first use dates. |
IsStreamingSupported |
bool |
Indicates whether streaming is supported. |
ConnectedDevices |
IDASConnectedDevice[] |
Devices connected to the DAS (currently only used by SLICE6DB). |
SerialNumbers |
string[] |
Array of serial numbers. |
FirmwareVersions |
string[] |
Array of firmware versions. |
Methods:
-
void SetConnectedDevices(IDASConnectedDevice[] devices)— Sets theConnectedDevicesarray. -
string StackSerialNumber(int devid)— Returns a stacked serial number string. Returns"N/A"ifSerialNumbersis null or empty. ReturnsSerialNumbers[0] + "::" + SerialNumbers[devid]ifdevidis non-zero and within bounds; otherwise returnsSerialNumbers[0].
Constructors:
Communication_DASInfo()— Default constructor.Communication_DASInfo(string[] serials, string[] fwnums)— Constructs with cloned copies of serial and firmware arrays.
Communication<T> (abstract class)
Namespace: DTS.Common.ICommunication
Implements: Interface.DASFactory.ICommunication
Generic constraint: where T : IConnection, new()
Abstract base class for hardware communication.
Properties:
| Property | Type | Access | Description |
|---|---|---|---|
ErrorInSetup |
bool |
get/set | Indicates an error occurred during setup. |
ConnectString |
string |
get | Returns sock.ConnectString. |
Connected |
bool |
get | Returns sock.Connected. |
DASInfo |
ICommunication_DASInfo |
get/set | DAS metadata. |
Transport |
IConnection |
get/set | Gets sock; setter throws NotSupportedException. |
ReceiveBufferSize |
int |
get/set | Receive buffer size; defaults to 65536. |
SerialNumber |
string |
get/set | Device serial number. |
FirmwareVersion |
string |
get/set | Firmware version; setter invokes FirmwareVersionUpdated(). |
ProtocolVersion |
byte |
get/set | Protocol version. |
MinimumProtocols |
Dictionary<DFConstantsAndEnums.ProtocolLimitedCommands, byte> |
get/set | Minimum protocol versions for commands. |
FlushTimeoutMilliSec |
int |
get/set | Flush timeout; defaults to 5. |
ExecuteIsBusy |
bool |
get/set | Thread-safe execution lock indicator. |
CancelEvent |
ManualResetEvent |
get | Event signaling cancel state. |
Events:
EventHandler OnDisconnected— Raised when the connection is disconnected.
Methods:
-
int CompareTo(Interface.DASFactory.ICommunication dev)— ComparesConnectStringvalues (ordinal, case-insensitive). -
int CompareTo(string conStr)— ComparesConnectStringto provided string (ordinal, case-insensitive). -
abstract void InitMinProto()— Must be implemented to initializeMinimumProtocols. -
bool IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands command)— ReturnstrueifProtocolVersion >= GetMinProto(command). -
byte GetMinProto(DFConstantsAndEnums.ProtocolLimitedCommands command)— Returns minimum protocol for command, or0xFFif not found. ThrowsNotSupportedExceptionifMinimumProtocolsis null. -
void Connect(string connectString, CommunicationCallback callback, object callbackObject, int callbackTimeout, string hostIPAddress)— Initiates asynchronous connection. Throws if socket is null or already connected. -
void Disconnect(bool reuseSocket, CommunicationCallback callback, object callbackObject, int callbackTimeout)— Initiates asynchronous disconnect. Throws if socket is null. -
void Cancel()— Sets cancel state with 500ms sleep on clear. -
void ForceCancel()— Sets cancel state with 250ms sleep on clear. -
bool IsCanceled()— Returns current cancel state. -
void ClearCancel()— Clears cancel state after sleeping. -
void Flush(int timeoutMs)— FlushesSockDataBufferuntil no data arrives within timeout. -
byte[] SyncExecute(byte[] byteData, int cbTimeout)— ThrowsNotSupportedException. -
void Execute(byte[] byteData, CommunicationCallback cb, object cbObject, int cbTimeout)— Sends data and processes responses asynchronously. ThrowsCanceledExceptionif canceled; throwsNotConnectedExceptionif not connected. -
void PseudoExecute(byte[] byteData, CommunicationCallback cb, object cbObject, int cbTimeout)— For commands that only receive data without sending. ThrowsCanceledExceptionif canceled; throwsNotConnectedExceptionif not connected. -
void SetupReader()— Initializes the asynchronous receive loop. -
void Dispose()— IDisposable implementation.
CommunicationReport (class)
Namespace: DTS.Common.ICommunication
Implements: ICommunicationReport
Encapsulates the result of a communication operation.
| Property | Type | Description |
|---|---|---|
UserState |
object |
User-provided state object. |
Result |
CommunicationResult |
Result of the operation. |
Data |
byte[] |
Received data (for read operations). |
Constructor:
CommunicationReport(object state, CommunicationResult res)
Communication<T>.ActionData (abstract class)
Namespace: DTS.Common.ICommunication
Base class for tracking asynchronous operations with timeout handling.
| Property | Type | Description |
|---|---|---|
UserTimeout |
int |
Timeout in milliseconds. |
TimerExpired |
bool |
Indicates if the timer fired. |
Methods:
void StartTimer()— Starts the timeout timer.void KillTimer()— Stops and disposes the timer.bool ReportCanceled()— Invokes callback withCommunicationResult.Canceled.abstract bool ReportFailure()— Must implement failure reporting.abstract bool ReportSuccess()— Must implement success reporting.protected abstract CommunicationResult GetTimeoutResult()— Must return the timeout-specific result.
Communication<T>.ExecuteActionData (class)
Namespace: DTS.Common.ICommunication
Extends ActionData for execute operations.
Additional Methods:
bool ReportReadSuccess(byte[] data)— Reports successful read with data.bool ReportReadTimeout()— Reports read timeout.bool ReportReadDisconnected()— Reports disconnection during read.
Communication<T>.PseudoAsyncResult (class)
Namespace: DTS.Common.ICommunication
Implements: IAsyncResult
Wraps ExecuteActionData for pseudo-execute operations.
| Property | Type | Description |
|---|---|---|
IsCompleted |
bool |
Always true. |
AsyncWaitHandle |
WaitHandle |
Throws NotImplementedException. |
AsyncState |
object |
Returns the wrapped ExecuteActionData. |
CompletedSynchronously |
bool |
Always true. |
3. Invariants
-
Connection State Guards:
Connect()throws ifsockis null or already connected.Disconnect()throws ifsockis null. -
ExecuteIsBusy Thread Safety: The
ExecuteIsBusyproperty uses a lock (_executeBusyMtLock) and asserts on re-entry or extra unlock attempts. -
MinimumProtocols Initialization:
GetMinProto()throwsNotSupportedExceptionifMinimumProtocolsis null. Derived classes must implementInitMinProto()to populate this dictionary. -
Transport Immutability: The
Transportproperty setter always throwsNotSupportedException; the transport cannot be replaced after construction. -
Buffer Flushing Before Execute:
Execute()callsCheckAndFlushBuffer()to ensureSockDataBufferis empty before sending. -
Cancel State Consistency:
ClearCancel()only performs sleep and reset if_commandsAreCanceledistrue. -
SerialNumbers Bounds Check:
StackSerialNumber(int devid)returns"N/A"for null/empty arrays andSerialNumbers[0]for out-of-boundsdevidvalues.
4. Dependencies
This module depends on:
DTS.Common.Enums.Hardware—HardwareTypesenum.DTS.Common.Enums.Communication—CommunicationConstantsAndEnums,CommunicationResult.DTS.Common.Enums.DASFactory—DFConstantsAndEnums.DTS.Common.Interface.Communication—ICommunication_DASInfo,CommunicationCallback(delegate type inferred).DTS.Common.Interface.Connection—IConnection.DTS.Common.Classes.Connection— (referenced but specific types not visible in source).DTS.Common.Utilities.Logging—APILogger.DTS.Common.Utilities—SecureQueue<T>.DTS.Common.Utils—WaitWithCondition.System.Net.NetworkInformation—PhysicalAddress.System.Net.Sockets—SocketException.System.Threading—ManualResetEvent,Timer,Timeout.System.Threading.Tasks—Task.
Consumers of this module:
- Not determinable from the provided source alone. The abstract
Communication<T>class is designed to be extended by concrete implementations.
5. Gotchas
-
SyncExecute Not Supported: The
SyncExecute()method throwsNotSupportedExceptionwith a message referencingDTS.DASLib.Communication.Communication, suggesting a namespace mismatch or historical artifact. -
PseudoAsyncResult.AsyncWaitHandle Throws: Accessing
AsyncWaitHandleonPseudoAsyncResultthrowsNotImplementedException, which could surprise callers expecting a functionalIAsyncResult. -
Thread ID Check in Receive Callbacks: Both
ProcessReceivedData()andSRRecvCallback()check thatThread.CurrentThread.ManagedThreadIdremains consistent before and afterWaitWithCondition.Wait(). If it changes, the method logs and returns without completing the operation