Initial commit

This commit is contained in:
2026-07-13 09:25:40 +07:00
parent c08ff54676
commit bccfb156d7
1938 changed files with 641646 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
namespace Sick.SafetyScanners.Cola2.Commands;
/// <summary>
/// Base interface for all COLA2 commands
/// </summary>
public interface ICola2Command
{
/// <summary>
/// Command type (e.g., 'R' for Read, 'W' for Write, 'O' for Method)
/// </summary>
byte CommandType { get; }
/// <summary>
/// Command mode (e.g., 'I' for Index, 'N' for Name)
/// </summary>
byte CommandMode { get; }
/// <summary>
/// Session ID (set by Cola2Session)
/// </summary>
uint SessionId { get; set; }
/// <summary>
/// Request ID (set by Cola2Session)
/// </summary>
ushort RequestId { get; set; }
/// <summary>
/// Indicates if the command was successfully executed
/// </summary>
bool WasSuccessful { get; }
/// <summary>
/// Gets the data vector for the command payload
/// </summary>
ReadOnlyMemory<byte> GetDataVector();
/// <summary>
/// Processes the reply from the sensor
/// </summary>
/// <param name="replyData">The reply data from the sensor</param>
bool ProcessReply(ReadOnlyMemory<byte> replyData, byte replyCommandType, byte replyCommandMode);
/// <summary>
/// Indicates if the command can be executed without a session ID
/// </summary>
bool CanBeExecutedWithoutSessionId { get; }
}

View File

@@ -0,0 +1,43 @@
using Sick.SafetyScanners.Cola2.Commands;
using Sick.SafetyScanners.Types;
namespace Sick.SafetyScanners.Interfaces;
/// <summary>
/// Interface cho COLA2 session management
/// </summary>
public interface ICola2Session : IDisposable
{
/// <summary>
/// Gets the current session ID, if available
/// </summary>
uint? SessionId { get; }
/// <summary>
/// Indicates whether a COLA2 session is currently opened
/// </summary>
bool IsOpen { get; }
/// <summary>
/// Opens a COLA2 session
/// </summary>
void Open();
/// <summary>
/// Closes the current COLA2 session
/// </summary>
void Close();
/// <summary>
/// Sends a COLA2 command to the sensor and waits for response
/// </summary>
/// <param name="command">The command to send</param>
/// <param name="timeout">The timeout for the operation</param>
void SendCommand(ICola2Command command, TimeDuration? timeout = null);
/// <summary>
/// Gets the next request ID (thread-safe, auto-increments)
/// </summary>
ushort GetNextRequestId();
}

View File

@@ -0,0 +1,50 @@
using Sick.SafetyScanners.DataStructures;
using Sick.SafetyScanners.Types;
namespace Sick.SafetyScanners.Interfaces;
/// <summary>
/// Interface cho TCP client communication
/// </summary>
public interface ITcpClient : IDisposable
{
/// <summary>
/// Server IP address
/// </summary>
IpAddress ServerIp { get; }
/// <summary>
/// Server port
/// </summary>
Port ServerPort { get; }
/// <summary>
/// Indicates whether the TCP socket is currently connected
/// </summary>
bool IsConnected { get; }
/// <summary>
/// Establishes a connection to the sensor
/// </summary>
/// <param name="timeout">Timeout for connection</param>
void Connect(TimeDuration? timeout = null);
/// <summary>
/// Disconnects from the sensor
/// </summary>
void Disconnect();
/// <summary>
/// Sends data to the sensor
/// </summary>
/// <param name="data">Data to send</param>
void Send(ReadOnlyMemory<byte> data);
/// <summary>
/// Receives data from the sensor
/// </summary>
/// <param name="timeout">Timeout for receive operation</param>
/// <returns>Received packet buffer</returns>
PacketBuffer Receive(TimeDuration? timeout = null);
}

View File

@@ -0,0 +1,42 @@
using Sick.SafetyScanners.DataStructures;
using Sick.SafetyScanners.Types;
namespace Sick.SafetyScanners.Interfaces;
/// <summary>
/// Interface for UDP receiver (not a connection - UDP is connectionless)
/// Used for receiving scan data packets from SICK Safety Scanner via UDP (push mode)
/// Note: This is NOT a "connection" - it's just a UDP socket receiver that binds to a local port
/// and waits for packets from the scanner
/// </summary>
public interface IUdpClient : IDisposable
{
/// <summary>
/// Indicates whether the UDP socket is open (ready to receive)
/// Note: UDP is connectionless, so this just checks if socket is bound/open
/// </summary>
bool IsConnected { get; }
/// <summary>
/// Gets the local port number assigned to this client
/// Returns null if socket is not bound yet
/// </summary>
Port? LocalPort { get; }
/// <summary>
/// Indicates whether data is available in the receiving buffer
/// </summary>
bool IsDataAvailable { get; }
/// <summary>
/// Starts receiving UDP packets on a dedicated high-priority thread
/// </summary>
/// <param name="packetHandler">Callback function to handle received packets</param>
void StartReceiving(Action<PacketBuffer> packetHandler);
/// <summary>
/// Stops the receiving thread
/// </summary>
void Stop();
}