Initial commit

This commit is contained in:
2026-07-03 16:31:37 +07:00
commit 899c7c637d
1939 changed files with 641750 additions and 0 deletions

View File

@@ -0,0 +1,103 @@
using RobotNet10.Script.IO;
using System.Net.Sockets;
namespace RobotNet10.ScriptEngine.IO;
/// <summary>
/// Implementation of CC-Link IE connection.
/// Note: This is a basic implementation. Full CC-Link IE support may require additional libraries.
/// </summary>
public class CcLinkIeConnection : ICcLinkIeConnection
{
private TcpClient? _tcpClient;
private NetworkStream? _stream;
private bool _disposed;
public string IpAddress { get; }
public int StationNumber { get; }
public bool IsConnected { get; private set; }
public CcLinkIeConnection(string ipAddress, int stationNumber = 1)
{
IpAddress = ipAddress;
StationNumber = stationNumber;
IsConnected = false;
}
public async Task ConnectAsync()
{
if (IsConnected)
return;
try
{
_tcpClient = new TcpClient();
await _tcpClient.ConnectAsync(IpAddress, 5007); // Standard CC-Link IE port
_stream = _tcpClient.GetStream();
IsConnected = true;
// TODO: Implement CC-Link IE handshake protocol
// This requires implementing the CC-Link IE protocol stack
}
catch
{
Disconnect();
throw;
}
}
public Task DisconnectAsync()
{
Disconnect();
return Task.CompletedTask;
}
private void Disconnect()
{
IsConnected = false;
_stream?.Close();
_stream = null;
_tcpClient?.Close();
_tcpClient?.Dispose();
_tcpClient = null;
}
public async Task<ushort[]> ReadAsync(int address, int length)
{
EnsureConnected();
// TODO: Implement CC-Link IE read operation
// This requires implementing the CC-Link IE protocol
await Task.CompletedTask;
throw new NotImplementedException("CC-Link IE read operation is not yet fully implemented. Full CC-Link IE support requires additional protocol implementation.");
}
public async Task WriteAsync(int address, ushort[] data)
{
EnsureConnected();
// TODO: Implement CC-Link IE write operation
// This requires implementing the CC-Link IE protocol
await Task.CompletedTask;
throw new NotImplementedException("CC-Link IE write operation is not yet fully implemented. Full CC-Link IE support requires additional protocol implementation.");
}
private void EnsureConnected()
{
if (!IsConnected || _stream == null)
{
throw new InvalidOperationException("CC-Link IE connection is not connected. Call ConnectAsync() first.");
}
}
public void Dispose()
{
if (!_disposed)
{
Disconnect();
_disposed = true;
}
GC.SuppressFinalize(this);
}
}