Initial commit
This commit is contained in:
31
srcs/RobotNet10/Commons/RobotNet10.Script/ILogger.cs
Normal file
31
srcs/RobotNet10/Commons/RobotNet10.Script/ILogger.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace RobotNet10.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Xuất thông tin ghi log cho các thành phần trong RobotNet.
|
||||
/// </summary>
|
||||
public interface ILogger
|
||||
{
|
||||
/// <summary>
|
||||
/// Xuất thông tin ghi log với mức độ thông tin.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
void LogInfo(string message);
|
||||
|
||||
/// <summary>
|
||||
/// Xuất thông tin ghi log với mức độ cảnh báo.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
void LogWarning(string message);
|
||||
|
||||
/// <summary>
|
||||
/// Xuất thông tin ghi log với mức độ lỗi.
|
||||
/// </summary>
|
||||
/// <param name="message"></param>
|
||||
void LogError(string message);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
string GetLog();
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace RobotNet10.Script.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for CC-Link IE connection operations.
|
||||
/// </summary>
|
||||
public interface ICcLinkIeConnection : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the IP address of the CC-Link IE device.
|
||||
/// </summary>
|
||||
string IpAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the station number.
|
||||
/// </summary>
|
||||
int StationNumber { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the connection is currently connected.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the CC-Link IE device.
|
||||
/// </summary>
|
||||
Task ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects from the CC-Link IE device.
|
||||
/// </summary>
|
||||
Task DisconnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Reads data from the CC-Link IE device.
|
||||
/// </summary>
|
||||
/// <param name="address">The memory address.</param>
|
||||
/// <param name="length">The number of words to read.</param>
|
||||
/// <returns>The read data as ushort array.</returns>
|
||||
Task<ushort[]> ReadAsync(int address, int length);
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to the CC-Link IE device.
|
||||
/// </summary>
|
||||
/// <param name="address">The memory address.</param>
|
||||
/// <param name="data">The data to write.</param>
|
||||
Task WriteAsync(int address, ushort[] data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
namespace RobotNet10.Script.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for HTTP connection operations.
|
||||
/// </summary>
|
||||
public interface IHttpConnection : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the base URL of the HTTP connection.
|
||||
/// </summary>
|
||||
string BaseUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the connection is currently connected.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the HTTP endpoint.
|
||||
/// </summary>
|
||||
Task ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects from the HTTP endpoint.
|
||||
/// </summary>
|
||||
Task DisconnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Sends a GET request to the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path relative to BaseUrl.</param>
|
||||
/// <param name="headers">Optional headers to include in the request.</param>
|
||||
/// <returns>The response content as string.</returns>
|
||||
Task<string> GetAsync(string path, Dictionary<string, string>? headers = null);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a POST request to the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path relative to BaseUrl.</param>
|
||||
/// <param name="content">The content to send.</param>
|
||||
/// <param name="contentType">The content type (default: application/json).</param>
|
||||
/// <param name="headers">Optional headers to include in the request.</param>
|
||||
/// <returns>The response content as string.</returns>
|
||||
Task<string> PostAsync(string path, string content, string contentType = "application/json", Dictionary<string, string>? headers = null);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a PUT request to the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path relative to BaseUrl.</param>
|
||||
/// <param name="content">The content to send.</param>
|
||||
/// <param name="contentType">The content type (default: application/json).</param>
|
||||
/// <param name="headers">Optional headers to include in the request.</param>
|
||||
/// <returns>The response content as string.</returns>
|
||||
Task<string> PutAsync(string path, string content, string contentType = "application/json", Dictionary<string, string>? headers = null);
|
||||
|
||||
/// <summary>
|
||||
/// Sends a DELETE request to the specified path.
|
||||
/// </summary>
|
||||
/// <param name="path">The path relative to BaseUrl.</param>
|
||||
/// <param name="headers">Optional headers to include in the request.</param>
|
||||
/// <returns>The response content as string.</returns>
|
||||
Task<string> DeleteAsync(string path, Dictionary<string, string>? headers = null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
namespace RobotNet10.Script.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for ModbusTCP connection operations.
|
||||
/// </summary>
|
||||
public interface IModbusTcpConnection : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the IP address of the ModbusTCP server.
|
||||
/// </summary>
|
||||
string IpAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the port of the ModbusTCP server.
|
||||
/// </summary>
|
||||
int Port { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the slave ID (unit identifier).
|
||||
/// </summary>
|
||||
byte SlaveId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the connection is currently connected.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the ModbusTCP server.
|
||||
/// </summary>
|
||||
Task ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects from the ModbusTCP server.
|
||||
/// </summary>
|
||||
Task DisconnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Reads holding registers.
|
||||
/// </summary>
|
||||
/// <param name="startAddress">The starting address.</param>
|
||||
/// <param name="numberOfPoints">The number of registers to read.</param>
|
||||
/// <returns>Array of register values.</returns>
|
||||
Task<ushort[]> ReadHoldingRegistersAsync(ushort startAddress, ushort numberOfPoints);
|
||||
|
||||
/// <summary>
|
||||
/// Reads input registers.
|
||||
/// </summary>
|
||||
/// <param name="startAddress">The starting address.</param>
|
||||
/// <param name="numberOfPoints">The number of registers to read.</param>
|
||||
/// <returns>Array of register values.</returns>
|
||||
Task<ushort[]> ReadInputRegistersAsync(ushort startAddress, ushort numberOfPoints);
|
||||
|
||||
/// <summary>
|
||||
/// Reads coils.
|
||||
/// </summary>
|
||||
/// <param name="startAddress">The starting address.</param>
|
||||
/// <param name="numberOfPoints">The number of coils to read.</param>
|
||||
/// <returns>Array of coil values.</returns>
|
||||
Task<bool[]> ReadCoilsAsync(ushort startAddress, ushort numberOfPoints);
|
||||
|
||||
/// <summary>
|
||||
/// Reads discrete inputs.
|
||||
/// </summary>
|
||||
/// <param name="startAddress">The starting address.</param>
|
||||
/// <param name="numberOfPoints">The number of inputs to read.</param>
|
||||
/// <returns>Array of input values.</returns>
|
||||
Task<bool[]> ReadDiscreteInputsAsync(ushort startAddress, ushort numberOfPoints);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a single coil.
|
||||
/// </summary>
|
||||
/// <param name="coilAddress">The coil address.</param>
|
||||
/// <param name="value">The value to write.</param>
|
||||
Task WriteSingleCoilAsync(ushort coilAddress, bool value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes multiple coils.
|
||||
/// </summary>
|
||||
/// <param name="startAddress">The starting address.</param>
|
||||
/// <param name="values">The values to write.</param>
|
||||
Task WriteMultipleCoilsAsync(ushort startAddress, bool[] values);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a single holding register.
|
||||
/// </summary>
|
||||
/// <param name="registerAddress">The register address.</param>
|
||||
/// <param name="value">The value to write.</param>
|
||||
Task WriteSingleRegisterAsync(ushort registerAddress, ushort value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes multiple holding registers.
|
||||
/// </summary>
|
||||
/// <param name="startAddress">The starting address.</param>
|
||||
/// <param name="values">The values to write.</param>
|
||||
Task WriteMultipleRegistersAsync(ushort startAddress, ushort[] values);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
namespace RobotNet10.Script.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for OPC UA connection operations.
|
||||
/// </summary>
|
||||
public interface IOpcUaConnection : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the endpoint URL of the OPC UA server.
|
||||
/// </summary>
|
||||
string EndpointUrl { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the connection is currently connected.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the OPC UA server.
|
||||
/// </summary>
|
||||
Task ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the OPC UA server with username and password.
|
||||
/// </summary>
|
||||
/// <param name="username">The username.</param>
|
||||
/// <param name="password">The password.</param>
|
||||
Task ConnectAsync(string username, string password);
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects from the OPC UA server.
|
||||
/// </summary>
|
||||
Task DisconnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Reads a node value by node ID.
|
||||
/// </summary>
|
||||
/// <param name="nodeId">The node ID string (e.g., "ns=2;s=MyVariable").</param>
|
||||
/// <returns>The read value as object.</returns>
|
||||
Task<object?> ReadNodeAsync(string nodeId);
|
||||
|
||||
/// <summary>
|
||||
/// Reads multiple node values by node IDs.
|
||||
/// </summary>
|
||||
/// <param name="nodeIds">Array of node ID strings.</param>
|
||||
/// <returns>Dictionary of node ID to value.</returns>
|
||||
Task<Dictionary<string, object?>> ReadNodesAsync(string[] nodeIds);
|
||||
|
||||
/// <summary>
|
||||
/// Writes a value to a node by node ID.
|
||||
/// </summary>
|
||||
/// <param name="nodeId">The node ID string.</param>
|
||||
/// <param name="value">The value to write.</param>
|
||||
Task WriteNodeAsync(string nodeId, object value);
|
||||
|
||||
/// <summary>
|
||||
/// Writes multiple values to nodes.
|
||||
/// </summary>
|
||||
/// <param name="values">Dictionary of node ID to value.</param>
|
||||
Task WriteNodesAsync(Dictionary<string, object> values);
|
||||
|
||||
/// <summary>
|
||||
/// Browses the node tree starting from the specified node.
|
||||
/// </summary>
|
||||
/// <param name="nodeId">The starting node ID (null for root).</param>
|
||||
/// <returns>Array of child node IDs.</returns>
|
||||
Task<string[]> BrowseNodesAsync(string? nodeId = null);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
namespace RobotNet10.Script.IO;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for ProfiNet connection operations.
|
||||
/// </summary>
|
||||
public interface IProfiNetConnection : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the IP address of the ProfiNet device.
|
||||
/// </summary>
|
||||
string IpAddress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the slot number.
|
||||
/// </summary>
|
||||
int Slot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the subslot number.
|
||||
/// </summary>
|
||||
int Subslot { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the connection is currently connected.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Connects to the ProfiNet device.
|
||||
/// </summary>
|
||||
Task ConnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Disconnects from the ProfiNet device.
|
||||
/// </summary>
|
||||
Task DisconnectAsync();
|
||||
|
||||
/// <summary>
|
||||
/// Reads data from the ProfiNet device.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to read from.</param>
|
||||
/// <param name="length">The number of bytes to read.</param>
|
||||
/// <returns>The read data as byte array.</returns>
|
||||
Task<byte[]> ReadAsync(int index, int length);
|
||||
|
||||
/// <summary>
|
||||
/// Writes data to the ProfiNet device.
|
||||
/// </summary>
|
||||
/// <param name="index">The index to write to.</param>
|
||||
/// <param name="data">The data to write.</param>
|
||||
Task WriteAsync(int index, byte[] data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace RobotNet10.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Khai báo một nhiệm vụ trong hệ thống RobotNet.
|
||||
/// </summary>
|
||||
/// <param name="totalScore"></param>
|
||||
/// <param name="isMultipleRun"></param>
|
||||
/// <param name="autoStart"></param>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public class MissionAttribute(int totalScore, bool isMultipleRun = true, bool autoStart = false) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Tổng điểm của nhiệm vụ.
|
||||
/// </summary>
|
||||
public int TotalScore { get; } = totalScore;
|
||||
|
||||
/// <summary>
|
||||
/// Cho phép nhiệm vụ này có thể chạy nhiều lần hay không.
|
||||
/// </summary>
|
||||
public bool IsMultipleRun { get; } = isMultipleRun;
|
||||
|
||||
/// <summary>
|
||||
/// Tự động khởi động nhiệm vụ khi MissionManager chuyển sang trạng thái Running.
|
||||
/// </summary>
|
||||
public bool AutoStart { get; } = autoStart;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace RobotNet10.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Trạng thái trả về mỗi step trong quá trình thực hiện nhiệm vụ.
|
||||
/// </summary>
|
||||
/// <param name="Score"></param>
|
||||
/// <param name="Message"></param>
|
||||
public record MissionStatus(int Score, string Message);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
20
srcs/RobotNet10/Commons/RobotNet10.Script/TaskAttribute.cs
Normal file
20
srcs/RobotNet10/Commons/RobotNet10.Script/TaskAttribute.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace RobotNet10.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Thuộc tính để đánh dấu một phương thức là một tác vụ định kỳ trong hệ thống RobotNet.
|
||||
/// </summary>
|
||||
/// <param name="interval"></param>
|
||||
/// <param name="autoStart"></param>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public class TaskAttribute(int interval, bool autoStart = true) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Thời gian định kỳ để thực hiện tác vụ, tính bằng giây.
|
||||
/// </summary>
|
||||
public int Interval { get; } = interval;
|
||||
|
||||
/// <summary>
|
||||
/// Cho phép tác vụ này tự động bắt đầu khi hệ thống khởi động hay không.
|
||||
/// </summary>
|
||||
public bool AutoStart { get; } = autoStart;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace RobotNet10.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Khai báo biến được phép đọc giá trị từ ngoài hệ thống RobotNet Script
|
||||
/// </summary>
|
||||
/// <param name="publicWrite"></param>
|
||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
|
||||
public class VariableAttribute(bool publicWrite = false) : Attribute
|
||||
{
|
||||
/// <summary>
|
||||
/// Khai báo biến được phép ghi giá trị từ ngoài hệ thống RobotNet Script
|
||||
/// </summary>
|
||||
public bool PublicWrite { get; } = publicWrite;
|
||||
}
|
||||
Reference in New Issue
Block a user