13 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T14:07:22.447976+00:00 | zai-org/GLM-5-FP8 | 1 | b573bb7d2f5d27d0 |
Documentation: DTS.Common.ICommunication
1. Purpose
This module provides the core communication infrastructure for interacting with DAS (Data Acquisition System) hardware devices. It defines the contract for connected devices via IDASConnectedDevice, encapsulates device metadata through Communication_DASInfo, and implements an asynchronous, callback-driven communication layer via the abstract Communication<T> class. The module handles connection lifecycle management, command execution with timeout handling, cancellation support, and protocol version negotiation for hardware commands.
2. Public Interface
IDASConnectedDevice (Interface)
Namespace: DTS.DASLib.Communication
Describes a device connected to a DAS (e.g., S6 connected to S6DB).
| 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
A marker exception class extending ApplicationException to signal operation cancellation.
Communication_DASInfo (Class)
Namespace: DTS.Common.ICommunication
Implements: ICommunication_DASInfo
Encapsulates metadata about a DAS device.
Properties:
| Property | Type | Default | Description |
|---|---|---|---|
FirstUseDate |
DateTime? |
null |
Date of first use; null indicates hardware not used since calibration. Only valid when IsFirstUseDateSupported is true |
IsFirstUseDateSupported |
bool |
false |
Indicates hardware supports first use dates |
IsStreamingSupported |
bool |
false |
Indicates whether streaming is supported |
ConnectedDevices |
IDASConnectedDevice[] |
empty array | 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 theConnectedDevicesarraystring StackSerialNumber(int devid)— Returns a stacked serial number string. Returns "N/A" ifSerialNumbersis null/empty; returnsSerialNumbers[0]::SerialNumbers[devid]ifdevidis non-zero and valid; otherwise returnsSerialNumbers[0]
Constructors:
Communication_DASInfo()— Default constructorCommunication_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, IDisposable
Constraint: where T : IConnection, new()
Abstract base class for hardware communication, providing connection management, command execution, and cancellation support.
Properties:
| Property | Type | Description |
|---|---|---|
ErrorInSetup |
bool |
Indicates an error occurred during setup |
ConnectString |
string |
Connection string from underlying socket |
Connected |
bool |
Whether the socket is connected |
DASInfo |
ICommunication_DASInfo |
DAS device information |
Transport |
IConnection |
Underlying connection transport (setter throws NotSupportedException) |
ReceiveBufferSize |
int |
Receive buffer size; default is 65536 (2^16) |
SerialNumber |
string |
Device serial number |
FirmwareVersion |
string |
Device firmware version; setter triggers FirmwareVersionUpdated() |
ProtocolVersion |
byte |
Protocol version for command support checks |
MinimumProtocols |
Dictionary<DFConstantsAndEnums.ProtocolLimitedCommands, byte> |
Maps commands to minimum required protocol versions |
FlushTimeoutMilliSec |
int |
Timeout for flush operations; default is 5ms |
ExecuteIsBusy |
bool |
Thread-safe flag indicating execution lock state |
CancelEvent |
ManualResetEvent |
Event signaling cancellation has occurred |
Events:
EventHandler OnDisconnected— Raised when the underlying socket disconnects
Public Methods:
int CompareTo(Interface.DASFactory.ICommunication dev)— Compares connection strings (case-insensitive, ordinal)int CompareTo(string conStr)— Compares connection string to provided stringabstract void InitMinProto()— Must be implemented to populateMinimumProtocolsbool IsCommandSupported(DFConstantsAndEnums.ProtocolLimitedCommands command)— ReturnstrueifProtocolVersion >= GetMinProto(command)byte GetMinProto(DFConstantsAndEnums.ProtocolLimitedCommands command)— Returns minimum protocol version for command; returns0xFFif not found; throwsNotSupportedExceptionifMinimumProtocolsis nullvoid Flush(int timeoutMs)— Flushes the socket data buffer until empty or timeoutbyte[] SyncExecute(byte[] byteData, int cbTimeout)— ThrowsNotSupportedException(not implemented)void Connect(string connectString, CommunicationCallback callback, object callbackObject, int callbackTimeout, string hostIPAddress)— Initiates asynchronous connectionvoid Disconnect(bool reuseSocket, CommunicationCallback callback, object callbackObject, int callbackTimeout)— Initiates asynchronous disconnectvoid Cancel()— Sets cancel state with 500ms sleep delay on clearvoid ForceCancel()— Sets cancel state with 250ms sleep delay on clearbool IsCanceled()— Returns current cancel statevoid ClearCancel()— Clears cancel state after sleepingvoid Execute(byte[] byteData, CommunicationCallback cb, object cbObject, int cbTimeout)— Sends data and processes responses asynchronouslyvoid PseudoExecute(byte[] byteData, CommunicationCallback cb, object cbObject, int cbTimeout)— For commands that only receive data (no send); does not clear buffervoid SetupReader()— Initializes the asynchronous receive loopvoid Close(int timeout)— Empty implementation (no-op)void Dispose()— ImplementsIDisposable
Protected Methods:
void Lock()— Empty implementationvoid Release()— Empty implementationvirtual void FirmwareVersionUpdated()— Called whenFirmwareVersionis set
CommunicationReport (Class)
Namespace: DTS.Common.ICommunication
Implements: ICommunicationReport
Carries the result of an asynchronous communication operation.
| Property | Type | Description |
|---|---|---|
UserState |
object |
User-provided state object |
Result |
CommunicationResult |
Result enum value |
Data |
byte[] |
Received data (for read operations) |
Constructor: CommunicationReport(object state, CommunicationResult res)
Communication<T>.ActionData (Abstract Nested Class)
Base class for tracking asynchronous operations with timeout handling.
| Property | Description |
|---|---|
UserCallback |
CommunicationCallback delegate |
UserCallbackObject |
User-provided state object |
UserTimeout |
Timeout in milliseconds |
TimerExpired |
Whether the timeout timer fired |
Methods:
void StartTimer()— Starts the timeout timervoid KillTimer()— Stops and disposes the timerbool ReportCanceled()— Invokes callback withCommunicationResult.Canceledabstract bool ReportFailure()— Must implement failure reportingabstract bool ReportSuccess()— Must implement success reportingabstract CommunicationResult GetTimeoutResult()— Must return the timeout-specific result
Communication<T>.ExecuteActionData (Nested Class)
Extends ActionData for execute operations.
Additional Methods:
bool ReportReadSuccess(byte[] data)— Reports successful read with databool ReportReadTimeout()— Reports read timeoutbool ReportReadDisconnected()— Reports disconnection during read
Communication<T>.PseudoAsyncResult (Nested Class)
Implements IAsyncResult for PseudoExecute operations.
| Property | Value |
|---|---|
IsCompleted |
Always true |
AsyncState |
The ExecuteActionData instance |
CompletedSynchronously |
Always true |
AsyncWaitHandle |
Throws NotImplementedException |
3. Invariants
-
Connection State Consistency:
sockis instantiated in the constructor and cannot be replaced viaTransportsetter (throwsNotSupportedException). -
Execute Locking:
ExecuteIsBusymust befalsebefore setting totrue, andtruebefore setting tofalse. Debug assertions enforce this—violations indicate re-entry or extra unlock bugs. -
Port/Spot Indexing:
PortandSpotOnPortonIDASConnectedDeviceare 0-based indices. -
FirstUseDate Validity:
FirstUseDateis only meaningful whenIsFirstUseDateSupportedistrue. -
MinimumProtocols Initialization:
MinimumProtocolsmust be populated byInitMinProto()before callingGetMinProto()orIsCommandSupported(), otherwiseNotSupportedExceptionis thrown. -
Callback Non-Null Assertion:
ActionDataconstructor asserts that the callback parameter is non-null. -
Thread ID Consistency: In
ProcessReceivedDataandSRRecvCallback, if the thread ID changes duringWaitWithCondition.Wait, the method exits early without processing.
4. Dependencies
This module depends on:
DTS.Common.Enums.Hardware—HardwareTypesenumDTS.Common.Enums.Communication—CommunicationResult,CommunicationConstantsAndEnumsDTS.Common.Enums.DASFactory—DFConstantsAndEnumsDTS.Common.Interface.Communication—ICommunication_DASInfo,CommunicationCallbackdelegateDTS.Common.Interface.Connection—IConnectionDTS.Common.Classes.Connection— (referenced but contents not in source)DTS.Common.Utilities.Logging—APILoggerDTS.Common.Utilities—SecureQueue<T>DTS.Common.Utils—WaitWithConditionSystem.Net.NetworkInformation—PhysicalAddressSystem.Net.Sockets—SocketExceptionSystem.Threading—ManualResetEvent,Timer,TimeoutSystem.Threading.Tasks—Task
What depends on this module:
- Implementations of
IConnection(generic constraintT) - Concrete DAS communication implementations that extend
Communication<T> - Consumers of
IDASConnectedDevicefor device enumeration - Consumers of
ICommunication_DASInfofor device metadata
5. Gotchas
-
SyncExecute Not Implemented: Calling
SyncExecute()throwsNotSupportedException. UseExecute()with callbacks instead. -
Lock/Release Are No-ops:
Lock()andRelease()methods have empty implementations. Any synchronization relying on these is not actually protected. -
Close() Does Nothing:
Close(int timeout)has an empty body and performs no cleanup. -
Cancel Sleep Delays:
ClearCancel()sleeps for either 500ms (afterCancel()) or 250ms (afterForceCancel()) before clearing the cancel state. This can introduce unexpected latency. -
Transport Setter Always Throws: Setting
TransportthrowsNotSupportedException—the socket cannot be replaced after construction. -
PseudoExecute Buffer Behavior: Unlike
Execute(),PseudoExecute()does not flush the buffer before operation and picks up from wherever the previousPseudoExecuteleft off. -
StackSerialNumber Edge Cases: Returns "N/A" for empty/null
SerialNumbers, but returnsSerialNumbers[0]fordevidvalues outside valid range (except 0). This may mask indexing errors. -
ActionData Timer Race: The timer callback and
KillTimer()both check_timerFiredunder a lock, but if the timer fires just before disposal, the callback will still execute. -
ReceiveCallback Disconnection Handling: When
sock.EndReceivereturns 0 bytes,_receiveCallbackRunningis set tofalseandOnDisconnectedis invoked, but the socket state is not explicitly cleaned up. -
Extra Communication Logging: Conditional logging via
DFConstantsAndEnums.ExtraCommunicationLoggingmay impact performance if enabled in production.