first commit -push
This commit is contained in:
415
RobotNet.Script/ICcLinkIeBasicClient.cs
Normal file
415
RobotNet.Script/ICcLinkIeBasicClient.cs
Normal file
@@ -0,0 +1,415 @@
|
||||
namespace RobotNet.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Client CC‑Link IE Basic (SLMP over TCP/UDP) dùng để kết nối PC ↔ PLC Mitsubishi qua Ethernet thường,
|
||||
/// hỗ trợ đọc/ghi device, polling chu kỳ và gửi lệnh SLMP thô.
|
||||
/// </summary>
|
||||
public interface ICcLinkIeBasicClient : IAsyncDisposable, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Trạng thái đã kết nối phiên transport (TCP/UDP) tới PLC hay chưa.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Số lần thử gửi lại khi lỗi tạm thời/timeout.
|
||||
/// </summary>
|
||||
int RetryCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ngắt kết nối transport và giải phóng tài nguyên liên quan.
|
||||
/// </summary>
|
||||
/// <param name="ct">Token hủy bất đồng bộ.</param>
|
||||
Task DisconnectAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc mảng bit (X/Y/M/L/S/B...) từ PLC.
|
||||
/// </summary>
|
||||
/// <param name="device">Loại device code.</param>
|
||||
/// <param name="startAddress">Địa chỉ bắt đầu.</param>
|
||||
/// <param name="count">Số bit cần đọc.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>Mảng giá trị bit.</returns>
|
||||
Task<bool[]> ReadBitsAsync(DeviceCode device, int startAddress, int count, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi mảng bit (X/Y/M/L/S/B...) vào PLC.
|
||||
/// </summary>
|
||||
/// <param name="device">Loại device code.</param>
|
||||
/// <param name="startAddress">Địa chỉ bắt đầu.</param>
|
||||
/// <param name="values">Dãy giá trị bit cần ghi.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
Task WriteBitsAsync(DeviceCode device, int startAddress, ReadOnlyMemory<bool> values, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc mảng word (D/W/R/ZR/B...) từ PLC.
|
||||
/// </summary>
|
||||
/// <param name="device">Loại device code.</param>
|
||||
/// <param name="startAddress">Địa chỉ bắt đầu (đơn vị word).</param>
|
||||
/// <param name="wordCount">Số word cần đọc.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>Mảng word (UInt16).</returns>
|
||||
Task<ushort[]> ReadWordsAsync(DeviceCode device, int startAddress, int wordCount, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi mảng word (D/W/R/ZR/B...) vào PLC.
|
||||
/// </summary>
|
||||
/// <param name="device">Loại device code.</param>
|
||||
/// <param name="startAddress">Địa chỉ bắt đầu (đơn vị word).</param>
|
||||
/// <param name="words">Dãy word cần ghi.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
Task WriteWordsAsync(DeviceCode device, int startAddress, ReadOnlyMemory<ushort> words, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc mảng double‑word (UInt32) từ PLC (áp dụng cho vùng hỗ trợ dword).
|
||||
/// </summary>
|
||||
/// <param name="device">Loại device code.</param>
|
||||
/// <param name="startAddress">Địa chỉ bắt đầu (đơn vị dword).</param>
|
||||
/// <param name="dwordCount">Số dword cần đọc.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>Mảng dword (UInt32).</returns>
|
||||
Task<uint[]> ReadDWordsAsync(DeviceCode device, int startAddress, int dwordCount, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi mảng double‑word (UInt32) vào PLC (áp dụng cho vùng hỗ trợ dword).
|
||||
/// </summary>
|
||||
/// <param name="device">Loại device code.</param>
|
||||
/// <param name="startAddress">Địa chỉ bắt đầu (đơn vị dword).</param>
|
||||
/// <param name="dwords">Dãy dword cần ghi.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
Task WriteDWordsAsync(DeviceCode device, int startAddress, ReadOnlyMemory<uint> dwords, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc ngẫu nhiên nhiều điểm word rời rạc (mixed areas) trong một lần.
|
||||
/// </summary>
|
||||
/// <param name="points">Danh sách (device, address) cần đọc.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>Mảng word theo thứ tự điểm yêu cầu.</returns>
|
||||
Task<ushort[]> ReadRandomWordsAsync((DeviceCode Device, int Address)[] points, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi ngẫu nhiên nhiều điểm word rời rạc (mixed areas) trong một lần.
|
||||
/// </summary>
|
||||
/// <param name="points">Danh sách (device, address) cần ghi.</param>
|
||||
/// <param name="values">Giá trị word theo thứ tự điểm.</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
Task WriteRandomWordsAsync((DeviceCode Device, int Address)[] points, ReadOnlyMemory<ushort> values, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Sự kiện bắn ra sau mỗi chu kỳ polling hoàn tất.
|
||||
/// </summary>
|
||||
event EventHandler<PollUpdatedEventArgs>? Polled;
|
||||
|
||||
/// <summary>
|
||||
/// Bắt đầu polling chu kỳ một hoặc nhiều vùng device.
|
||||
/// </summary>
|
||||
/// <param name="options">Tùy chọn polling (chu kỳ, vùng, giới hạn kích thước).</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
void StartPolling(PollOptions options, CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Dừng polling chu kỳ.
|
||||
/// </summary>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
Task StopPollingAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Lấy trạng thái liên kết/SLMP gần nhất (end code, thống kê thời gian phản hồi...).
|
||||
/// </summary>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>Thông tin trạng thái IE Basic.</returns>
|
||||
Task<IeBasicStatus> GetStatusAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Kiểm tra liên lạc PLC (ví dụ node monitor) ở mức nhanh/gọn.
|
||||
/// </summary>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>true nếu phản hồi hợp lệ, ngược lại false.</returns>
|
||||
Task<bool> PingAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Truy vấn thông tin nhận dạng module/CPU (nếu PLC cho phép).
|
||||
/// </summary>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>Thông tin định danh CPU/module.</returns>
|
||||
Task<ModuleIdentity> IdentifyAsync(CancellationToken ct = default);
|
||||
|
||||
/// <summary>
|
||||
/// Gửi lệnh SLMP thô (mở rộng/đặc thù) và nhận phản hồi.
|
||||
/// </summary>
|
||||
/// <param name="command">Mã lệnh SLMP.</param>
|
||||
/// <param name="payload">Payload SLMP theo định dạng frame chọn (3E/4E).</param>
|
||||
/// <param name="ct">Token hủy.</param>
|
||||
/// <returns>Phản hồi SLMP gồm end code và payload.</returns>
|
||||
Task<SlmpResponse> SendSlmpAsync(SlmpCommand command, ReadOnlyMemory<byte> payload, CancellationToken ct = default);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loại transport cho CC‑Link IE Basic (UDP hoặc TCP).
|
||||
/// </summary>
|
||||
public enum IeBasicTransport
|
||||
{
|
||||
/// <summary>Giao tiếp qua UDP (thường dùng cho IE Basic).</summary>
|
||||
Udp,
|
||||
|
||||
/// <summary>Giao tiếp qua TCP.</summary>
|
||||
Tcp
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Định dạng frame SLMP.
|
||||
/// </summary>
|
||||
public enum SlmpFrameFormat
|
||||
{
|
||||
/// <summary>Khung 3E (Format 3E).</summary>
|
||||
Format3E,
|
||||
|
||||
/// <summary>Khung 4E (Format 4E).</summary>
|
||||
Format4E
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Device code (vùng thiết bị) cấp ứng dụng.
|
||||
/// </summary>
|
||||
public enum DeviceCode
|
||||
{
|
||||
/// <summary>Input (bit).</summary>
|
||||
X,
|
||||
/// <summary>Output (bit).</summary>
|
||||
Y,
|
||||
/// <summary>Internal relay (bit).</summary>
|
||||
M,
|
||||
/// <summary>Latch relay (bit).</summary>
|
||||
L,
|
||||
/// <summary>Link relay (bit/word tùy CPU).</summary>
|
||||
B,
|
||||
/// <summary>Step relay (bit).</summary>
|
||||
S,
|
||||
/// <summary>Data register (word).</summary>
|
||||
D,
|
||||
/// <summary>Link register (word).</summary>
|
||||
W,
|
||||
/// <summary>File register (word).</summary>
|
||||
R,
|
||||
/// <summary>Extended file register (word).</summary>
|
||||
ZR
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tham số logic phía local (PC/sender) khi gửi SLMP.
|
||||
/// </summary>
|
||||
/// <param name="NetworkNo">Số mạng logic.</param>
|
||||
/// <param name="ModuleIoNo">Địa chỉ I/O module logic (thường 0x03FF).</param>
|
||||
/// <param name="MultidropNo">Số đa điểm (nếu dùng).</param>
|
||||
/// <param name="StationNo">Số trạm logic.</param>
|
||||
public readonly record struct IeBasicLocal(
|
||||
byte NetworkNo,
|
||||
ushort ModuleIoNo,
|
||||
byte MultidropNo,
|
||||
byte StationNo
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Cấu hình đầu xa: địa chỉ IP/Port và tham số logic đích cho SLMP.
|
||||
/// </summary>
|
||||
/// <param name="Host">Địa chỉ IP hoặc hostname PLC/module.</param>
|
||||
/// <param name="Port">Cổng SLMP (ví dụ 5007).</param>
|
||||
/// <param name="NetworkNo">Số mạng logic đích.</param>
|
||||
/// <param name="ModuleIoNo">Địa chỉ I/O module logic đích.</param>
|
||||
/// <param name="MultidropNo">Số đa điểm (nếu dùng).</param>
|
||||
/// <param name="StationNo">Số trạm logic đích.</param>
|
||||
public readonly record struct IeBasicRemote(
|
||||
string Host,
|
||||
int Port,
|
||||
byte NetworkNo,
|
||||
ushort ModuleIoNo,
|
||||
byte MultidropNo,
|
||||
byte StationNo
|
||||
);
|
||||
|
||||
/// <summary>
|
||||
/// Tùy chọn khởi tạo/kết nối IE Basic client.
|
||||
/// </summary>
|
||||
public sealed record IeBasicClientOptions(
|
||||
string Host,
|
||||
int Port,
|
||||
byte NetworkNo,
|
||||
ushort ModuleIoNo,
|
||||
byte MultidropNo,
|
||||
byte StationNo
|
||||
)
|
||||
{
|
||||
/// <summary>Transport: UDP hoặc TCP.</summary>
|
||||
public IeBasicTransport Transport { get; init; } = IeBasicTransport.Udp;
|
||||
|
||||
/// <summary>Định dạng frame SLMP (3E/4E).</summary>
|
||||
public SlmpFrameFormat FrameFormat { get; init; } = SlmpFrameFormat.Format3E;
|
||||
|
||||
/// <summary>Tham số logic phía local.</summary>
|
||||
public IeBasicLocal Local { get; init; } =
|
||||
new IeBasicLocal(0, 0x03FF, 0, 0);
|
||||
|
||||
/// <summary>Timeout cho mỗi yêu cầu.</summary>
|
||||
public TimeSpan Timeout { get; init; } = TimeSpan.FromMilliseconds(1000);
|
||||
|
||||
/// <summary>Số lần retry khi lỗi tạm thời.</summary>
|
||||
public int RetryCount { get; init; } = 2;
|
||||
|
||||
/// <summary>Tự động reconnect nếu mất liên kết.</summary>
|
||||
public bool AutoReconnect { get; init; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Quy ước ghép cặp word trong DWord/Float (true: little‑endian word order).
|
||||
/// </summary>
|
||||
public bool LittleEndianWordOrder { get; init; } = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tùy chọn cho polling chu kỳ các vùng device.
|
||||
/// </summary>
|
||||
public sealed record PollOptions
|
||||
{
|
||||
/// <summary>Khoảng thời gian giữa hai lần poll.</summary>
|
||||
public TimeSpan Interval { get; init; } = TimeSpan.FromMilliseconds(20);
|
||||
|
||||
/// <summary>Danh sách vùng cần poll (device, địa chỉ bắt đầu, số lượng).</summary>
|
||||
public (DeviceCode Device, int Start, int Count)[] Areas { get; init; } = [];
|
||||
|
||||
/// <summary>Giới hạn số word tối đa mỗi chu kỳ (để tránh gói quá lớn).</summary>
|
||||
public int MaxWordsPerCycle { get; init; } = 256;
|
||||
|
||||
/// <summary>Gom vùng theo từng loại device để tối ưu số gói.</summary>
|
||||
public bool AlignAreasByDevice { get; init; } = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dữ liệu trả về sau mỗi chu kỳ polling.
|
||||
/// </summary>
|
||||
public sealed class PollUpdatedEventArgs : EventArgs
|
||||
{
|
||||
/// <summary>Thời điểm khung dữ liệu được cập nhật.</summary>
|
||||
public DateTimeOffset Timestamp { get; init; }
|
||||
|
||||
/// <summary>Mảng bit (nếu có vùng bit được cấu hình).</summary>
|
||||
public ReadOnlyMemory<bool>? Bits { get; init; }
|
||||
|
||||
/// <summary>Mảng word (nếu có vùng word được cấu hình).</summary>
|
||||
public ReadOnlyMemory<ushort>? Words { get; init; }
|
||||
|
||||
/// <summary>Mảng dword (nếu có vùng dword được cấu hình).</summary>
|
||||
public ReadOnlyMemory<uint>? DWords { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Trạng thái liên kết/SLMP để chẩn đoán và theo dõi.
|
||||
/// </summary>
|
||||
public sealed record IeBasicStatus
|
||||
{
|
||||
/// <summary>Liên kết hiện “đang lên” (có phản hồi) hay không.</summary>
|
||||
public bool LinkUp { get; init; }
|
||||
|
||||
/// <summary>Số lỗi liên tiếp gần nhất.</summary>
|
||||
public int ConsecutiveErrors { get; init; }
|
||||
|
||||
/// <summary>End code SLMP của lỗi gần nhất (nếu có).</summary>
|
||||
public SlmpEndCode? LastEndCode { get; init; }
|
||||
|
||||
/// <summary>Mô tả lỗi gần nhất (nếu có).</summary>
|
||||
public string? LastErrorText { get; init; }
|
||||
|
||||
/// <summary>Thời gian phản hồi trung bình ước tính.</summary>
|
||||
public TimeSpan? AvgRtt { get; init; }
|
||||
|
||||
/// <summary>Thời gian phản hồi lớn nhất quan sát.</summary>
|
||||
public TimeSpan? MaxRtt { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thông tin nhận dạng CPU/module (nếu PLC cho phép truy vấn).
|
||||
/// </summary>
|
||||
public sealed record ModuleIdentity
|
||||
{
|
||||
/// <summary>Dòng CPU (ví dụ iQ‑R, iQ‑F).</summary>
|
||||
public string? CpuSeries { get; init; }
|
||||
|
||||
/// <summary>Model cụ thể (ví dụ R04ENCPU).</summary>
|
||||
public string? CpuModel { get; init; }
|
||||
|
||||
/// <summary>Phiên bản firmware.</summary>
|
||||
public string? Firmware { get; init; }
|
||||
|
||||
/// <summary>Nhà sản xuất (thường là Mitsubishi Electric).</summary>
|
||||
public string? Vendor { get; init; }
|
||||
|
||||
/// <summary>Thông tin bổ sung khác (nếu có).</summary>
|
||||
public string? AdditionalInfo { get; init; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mã lệnh SLMP rút gọn (có thể mở rộng khi hiện thực adapter).
|
||||
/// </summary>
|
||||
public enum SlmpCommand : ushort
|
||||
{
|
||||
/// <summary>Đọc device theo dải liên tục (bit/word).</summary>
|
||||
ReadDevice = 0x0401,
|
||||
|
||||
/// <summary>Ghi device theo dải liên tục (bit/word).</summary>
|
||||
WriteDevice = 0x1401,
|
||||
|
||||
/// <summary>Đọc ngẫu nhiên nhiều điểm.</summary>
|
||||
ReadRandom = 0x0403,
|
||||
|
||||
/// <summary>Ghi ngẫu nhiên nhiều điểm.</summary>
|
||||
WriteRandom = 0x1402,
|
||||
|
||||
/// <summary>Node monitor / kiểm tra liên lạc.</summary>
|
||||
NodeMonitor = 0x0619,
|
||||
|
||||
/// <summary>Truy vấn thông tin thiết bị/PLC.</summary>
|
||||
DeviceInfo = 0x0601
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mã end code SLMP (hoàn thành/thất bại), gồm cả mã nội bộ ánh xạ lỗi transport/timeout.
|
||||
/// </summary>
|
||||
public enum SlmpEndCode : ushort
|
||||
{
|
||||
/// <summary>Hoàn thành thành công.</summary>
|
||||
Completed = 0x0000,
|
||||
|
||||
/// <summary>Lệnh không hợp lệ.</summary>
|
||||
InvalidCommand = 0xC059,
|
||||
|
||||
/// <summary>Truy cập bị từ chối.</summary>
|
||||
AccessDenied = 0xC056,
|
||||
|
||||
/// <summary>Lỗi phạm vi device.</summary>
|
||||
DeviceRangeError = 0xC051,
|
||||
|
||||
/// <summary>Thiết bị bận.</summary>
|
||||
Busy = 0xCEE0,
|
||||
|
||||
/// <summary>Quá thời gian chờ (gán nội bộ).</summary>
|
||||
Timeout = 0xFFFF,
|
||||
|
||||
/// <summary>Lỗi transport/socket (gán nội bộ).</summary>
|
||||
TransportError = 0xFFFE,
|
||||
|
||||
/// <summary>Lỗi không xác định (gán nội bộ).</summary>
|
||||
Unknown = 0xFFFD
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Phản hồi SLMP thô trả về từ <see cref="ICcLinkIeBasicClient.SendSlmpAsync"/>.
|
||||
/// </summary>
|
||||
public sealed record SlmpResponse
|
||||
{
|
||||
/// <summary>End code của phản hồi.</summary>
|
||||
public SlmpEndCode EndCode { get; init; }
|
||||
|
||||
/// <summary>Payload nhị phân trả về (theo frame 3E/4E).</summary>
|
||||
public ReadOnlyMemory<byte> Payload { get; init; }
|
||||
|
||||
/// <summary>Thời điểm nhận gói.</summary>
|
||||
public DateTimeOffset Timestamp { get; init; }
|
||||
}
|
||||
23
RobotNet.Script/IConnectionManager.cs
Normal file
23
RobotNet.Script/IConnectionManager.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace RobotNet.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Quản lý kết nối với device khác.
|
||||
/// </summary>
|
||||
public interface IConnectionManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Tạo kết nối Modbus TCP đến một thiết bị với địa chỉ IP, cổng và ID đơn vị cụ thể.
|
||||
/// </summary>
|
||||
/// <param name="ipAddress"></param>
|
||||
/// <param name="port"></param>
|
||||
/// <param name="unitId"></param>
|
||||
/// <returns></returns>
|
||||
Task<IModbusTcpClient> ConnectModbusTcp(string ipAddress, int port, byte unitId);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="option"></param>
|
||||
/// <returns></returns>
|
||||
Task<ICcLinkIeBasicClient> ConnectCcLink(IeBasicClientOptions option);
|
||||
}
|
||||
25
RobotNet.Script/ILogger.cs
Normal file
25
RobotNet.Script/ILogger.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace RobotNet.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);
|
||||
}
|
||||
154
RobotNet.Script/IMapManager.cs
Normal file
154
RobotNet.Script/IMapManager.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using RobotNet.Script.Expressions;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace RobotNet.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Service quản lý các phần tử trong bản đồ.
|
||||
/// </summary>
|
||||
public interface IMapManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Trả về phần tử theo tên trong bản đồ.
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
Task<IElement> GetElement(string map, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a node from the specified map by its name.
|
||||
/// </summary>
|
||||
/// <remarks>This method performs an asynchronous operation to locate a node within the specified map.
|
||||
/// Ensure that the map and name parameters are valid and non-empty before calling this method.</remarks>
|
||||
/// <param name="map">The identifier of the map from which to retrieve the node. Cannot be null or empty.</param>
|
||||
/// <param name="name">The name of the node to retrieve. Cannot be null or empty.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result contains the node matching the specified name
|
||||
/// within the given map, or <see langword="null"/> if no such node exists.</returns>
|
||||
Task<INode> GetNode(string map, string name);
|
||||
|
||||
/// <summary>
|
||||
/// Tìm kiếm các phần tử trong bản đồ theo biểu thức.
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
Task<IElement[]> FindElements(string map, string model);
|
||||
|
||||
/// <summary>
|
||||
/// Tìm kiếm các phần tử trong bản đồ theo biểu thức.
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="expr"></param>
|
||||
/// <returns></returns>
|
||||
Task<IElement[]> FindElements(string map, string model, Expression<Func<Expressions.ElementProperties, bool>> expr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Thông tin về một nút trong bản đồ.
|
||||
/// </summary>
|
||||
public interface INode
|
||||
{
|
||||
/// <summary>
|
||||
/// Id của nút.
|
||||
/// </summary>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Id của map chứa nút này.
|
||||
/// </summary>
|
||||
Guid MapId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tên của nút
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tọa độ trục hoành của nút trong không gian 2D.
|
||||
/// </summary>
|
||||
double X { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tọa độ trục tung của nút trong không gian 2D.
|
||||
/// </summary>
|
||||
double Y { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Hướng của nút trong không gian 2D, tính bằng độ.
|
||||
/// </summary>
|
||||
double Theta { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Quản lý thông tin của một phần tử trong bản đồ.
|
||||
/// </summary>
|
||||
public interface IElement
|
||||
{
|
||||
/// <summary>
|
||||
/// Id của phần tử.
|
||||
/// </summary>
|
||||
Guid Id { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Id model của phần tử này.
|
||||
/// </summary>
|
||||
Guid ModelId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tên của model mà phần tử này thuộc về.
|
||||
/// </summary>
|
||||
string ModelName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Id của nút mà phần tử này thuộc về.
|
||||
/// </summary>
|
||||
Guid NodeId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tên của phần tử.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tạo độ trục hoành tương dối của phần từ so với nút mà nó thuộc về.
|
||||
/// </summary>
|
||||
double OffsetX { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tọa độ trục tung tương đối của phần từ so với nút mà nó thuộc về.
|
||||
/// </summary>
|
||||
double OffsetY { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tên của nút mà phần tử này thuộc về.
|
||||
/// </summary>
|
||||
string NodeName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tọa độ trục hoành của nút trong không gian 2D.
|
||||
/// </summary>
|
||||
double X { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Tọa độ trục tung của nút trong không gian 2D.
|
||||
/// </summary>
|
||||
double Y { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Hướng của phần tử trong không gian 2D, tính bằng độ.
|
||||
/// </summary>
|
||||
double Theta { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Các thuộc tính của phần tử, bao gồm các thuộc tính bool, double, int và string.
|
||||
/// </summary>
|
||||
ElementProperties Properties { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Lưu các thay đổi của thuộc tính phần tử vào cơ sở dữ liệu
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task SaveChangesAsync();
|
||||
}
|
||||
92
RobotNet.Script/IModbusTcpClient.cs
Normal file
92
RobotNet.Script/IModbusTcpClient.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
namespace RobotNet.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Quản ký kết nối Modbus TCP tới 1 thiết bị.
|
||||
/// </summary>
|
||||
public interface IModbusTcpClient : IAsyncDisposable, IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// Trạng thái kết nối hiện tại với thiết bị Modbus TCP.
|
||||
/// </summary>
|
||||
bool IsConnected { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Đọc các đầu vào rời rạc (Discrete Inputs) từ thiết bị Modbus TCP với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="quantity"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool[]> ReadDiscreteInputsAsync(UInt16 startingAddress, UInt16 quantity, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc các cuộn dây (Coils) từ thiết bị Modbus TCP.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="quantity"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool[]> ReadCoilsAsync(UInt16 startingAddress, UInt16 quantity, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc các thanh ghi giữ (Holding Registers) từ thiết bị Modbus TCP với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="quantity"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<ushort[]> ReadHoldingRegistersAsync(UInt16 startingAddress, UInt16 quantity, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc các thanh ghi đầu vào (Input Registers) từ thiết bị Modbus TCP với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="quantity"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<ushort[]> ReadInputRegistersAsync(UInt16 startingAddress, UInt16 quantity, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi viết một cuộn dây (Coil) đơn lẻ đến thiết bị Modbus TCP với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
Task WriteSingleCoilAsync(UInt16 startingAddress, bool value, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi viết một thanh ghi đơn lẻ đến thiết bị Modbus TCP với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
Task WriteSingleRegisterAsync(UInt16 startingAddress, UInt16 value, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi viết nhiều cuộn dây (Coils) đến thiết bị Modbus TCP với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="values"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
Task WriteMultipleCoilsAsync(UInt16 startingAddress, bool[] values, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi viết nhiều thanh ghi (Holding Registers) đến thiết bị Modbus TCP với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="startingAddress"></param>
|
||||
/// <param name="values"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
Task WriteMultipleRegistersAsync(UInt16 startingAddress, UInt16[] values, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// Đọc và ghi viết nhiều thanh ghi (Holding Registers) trong một lần gọi với hỗ trợ hủy bỏ.
|
||||
/// </summary>
|
||||
/// <param name="readStart"></param>
|
||||
/// <param name="readCount"></param>
|
||||
/// <param name="writeStart"></param>
|
||||
/// <param name="writeValues"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<ushort[]> ReadWriteMultipleRegistersAsync(ushort readStart, ushort readCount, ushort writeStart, IReadOnlyList<ushort> writeValues, CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
232
RobotNet.Script/IRobot.cs
Normal file
232
RobotNet.Script/IRobot.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
using RobotNet.Script.Expressions;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace RobotNet.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Service điểu khiển robot trong hệ thống RobotNet.
|
||||
/// </summary>
|
||||
public interface IRobot
|
||||
{
|
||||
/// <summary>
|
||||
/// Di chuyển robot đến một nút trong bản đồ với action kết thúc.
|
||||
/// </summary>
|
||||
/// <param name="nodeName"></param>
|
||||
/// <param name="actions"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> Move(string nodeName, IDictionary<string, IEnumerable<RobotAction>> actions, CancellationToken cancellationToken);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Di chuyển robot đến một nút trong bản đồ với action kết thúc.
|
||||
/// </summary>
|
||||
/// <param name="nodeName"></param>
|
||||
/// <param name="actions"></param>
|
||||
/// <param name="lastAngle"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> Move(string nodeName, IDictionary<string, IEnumerable<RobotAction>> actions, double lastAngle, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Di chuyển robot đến một nút trong bản đồ với action kết thúc.
|
||||
/// </summary>
|
||||
/// <param name="nodeName"></param>
|
||||
/// <param name="lastActions"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> Move(string nodeName, IEnumerable<RobotAction> lastActions, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Di chuyển robot đến một nút trong bản đồ với action kết thúc.
|
||||
/// </summary>
|
||||
/// <param name="nodeName"></param>
|
||||
/// <param name="lastActions"></param>
|
||||
/// <param name="lastAngle"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> Move(string nodeName, IEnumerable<RobotAction> lastActions, double lastAngle, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Di chuyển robot đến một nút trong bản đồ mà không cần action kết thúc.
|
||||
/// </summary>
|
||||
/// <param name="nodeName"></param>
|
||||
/// <param name="lastAngle"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> Move(string nodeName, double lastAngle, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Di chuyển robot đến một nút trong bản đồ mà không cần action kết thúc.
|
||||
/// </summary>
|
||||
/// <param name="nodeName"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> Move(string nodeName, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Hủy bỏ hành động di chuyển hiện tại của robot, nếu có.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task AbortMovement();
|
||||
|
||||
/// <summary>
|
||||
/// Thực hiện một hành động ngay lập tức trên robot mà không cần chờ đợi.
|
||||
/// </summary>
|
||||
/// <param name="action"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> Execute(RobotAction action, CancellationToken cancellationToken);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Lấy trạng thái của robot
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<RobotState> GetState();
|
||||
|
||||
/// <summary>
|
||||
/// Waits for the system to reach a ready state.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">A token to monitor for cancellation requests. If the token is canceled, the operation will be aborted.</param>
|
||||
/// <returns>A task that represents the asynchronous operation. The task result is <see langword="true"/> if the system
|
||||
/// reaches a ready state; otherwise, <see langword="false"/> if the operation is canceled or the system fails to
|
||||
/// become ready.</returns>
|
||||
Task<bool> WaitForReady(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> RequestACSIn(string id);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<bool> RequestACSOut(string id);
|
||||
|
||||
/// <summary>
|
||||
/// Trả về danh sách các tải trọng hiện tại của robot, bao gồm ID, loại, vị trí và trọng lượng.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<RobotLoad[]> GetLoads();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<bool> CancelOrder();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
Task<bool> CancelAction();
|
||||
|
||||
/// <summary>
|
||||
/// Chức năng di chuyển robot giả lập theo tọa độ (x, y) trong không gian 2D.
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> SimMoveStraight(double x, double y, CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Chức năng xoay robot giả lập theo một góc nhất định (đơn vị: độ).
|
||||
/// </summary>
|
||||
/// <param name="angle"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotResult> SimRotate(double angle, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Service quản lý các robot trong hệ thống RobotNet.
|
||||
/// </summary>
|
||||
public interface IRobotManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Trả về đối tượng điểu khiển robot theo ID.
|
||||
/// </summary>
|
||||
/// <param name="robotId"></param>
|
||||
/// <returns></returns>
|
||||
Task<IRobot?> GetRobotById(string robotId);
|
||||
|
||||
/// <summary>
|
||||
/// Lấy trạng thái của một robot theo ID.
|
||||
/// </summary>
|
||||
/// <param name="robotId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RobotState> GetRobotState(string robotId);
|
||||
|
||||
/// <summary>
|
||||
/// Tìm kiếm các robot trong bản đồ theo tên và mô hình.
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<string>> SearchRobots(string map, string model);
|
||||
|
||||
/// <summary>
|
||||
/// Tìm kiếm các robot trong bản đồ theo tên và mô hình.
|
||||
/// </summary>
|
||||
/// <param name="map"></param>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="expr"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<string>> SearchRobots(string map, string model, Expression<Func<Expressions.RobotState, bool>> expr);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Regulates if the action is allowed to be executed during movement and/or parallel to other actions.
|
||||
/// </summary>
|
||||
public enum BlockingType
|
||||
{
|
||||
/// <summary>
|
||||
/// Action can happen in parallel with others, including movement.
|
||||
/// </summary>
|
||||
NONE,
|
||||
|
||||
/// <summary>
|
||||
/// Action can happen simultaneously with others, but not while moving.
|
||||
/// </summary>
|
||||
SOFT,
|
||||
|
||||
/// <summary>
|
||||
/// No other actions can be performed while this action is running.
|
||||
/// </summary>
|
||||
HARD
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mô tả một hành động của robot.
|
||||
/// </summary>
|
||||
/// <param name="ActionType"></param>
|
||||
/// <param name="BlockingType"></param>
|
||||
public record RobotAction(string ActionType, BlockingType BlockingType)
|
||||
{
|
||||
/// <summary>
|
||||
/// Danh sách các tham số của hành động robot.
|
||||
/// </summary>
|
||||
public IDictionary<string, string>? Parameters { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dữ liệu trả về từ các hành động của robot, bao gồm thông tin về thành công hay thất bại và thông điệp mô tả.
|
||||
/// </summary>
|
||||
/// <param name="IsSuccess"></param>
|
||||
/// <param name="Message"></param>
|
||||
public record RobotResult(bool IsSuccess, string Message);
|
||||
|
||||
/// <summary>
|
||||
/// Thông tin về tải trọng của robot, bao gồm ID, loại, vị trí và trọng lượng.
|
||||
/// </summary>
|
||||
/// <param name="Id"></param>
|
||||
/// <param name="Type"></param>
|
||||
/// <param name="Position"></param>
|
||||
/// <param name="Weight"></param>
|
||||
public record RobotLoad(string Id, string Type, string Position, double Weight);
|
||||
22
RobotNet.Script/IUnixDevice.cs
Normal file
22
RobotNet.Script/IUnixDevice.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace RobotNet.Script;
|
||||
|
||||
/// <summary>
|
||||
/// Service để đọc và ghi dữ liệu từ các thiết bị Unix.
|
||||
/// </summary>
|
||||
public interface IUnixDevice
|
||||
{
|
||||
/// <summary>
|
||||
/// Đọc dữ liệu từ thiết bị Unix theo tên và độ dài yêu cầu.
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <returns></returns>
|
||||
byte[] ReadDev(string name, int length);
|
||||
|
||||
/// <summary>
|
||||
/// Ghi dữ liệu vào thiết bị Unix theo tên.
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <param name="data"></param>
|
||||
void WriteDev(string name, byte[] data);
|
||||
}
|
||||
21
RobotNet.Script/MissionAttribute.cs
Normal file
21
RobotNet.Script/MissionAttribute.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
namespace RobotNet.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="Step"></param>
|
||||
/// <param name="Message"></param>
|
||||
public record MissionState(int Step, string Message);
|
||||
|
||||
/// <summary>
|
||||
/// Khai báo một nhiệm vụ trong hệ thống RobotNet.
|
||||
/// </summary>
|
||||
/// <param name="isMultipleRun"></param>
|
||||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
|
||||
public class MissionAttribute(bool isMultipleRun = true) : Attribute
|
||||
{
|
||||
/// <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;
|
||||
}
|
||||
15
RobotNet.Script/RobotNet.Script.csproj
Normal file
15
RobotNet.Script/RobotNet.Script.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<IsAotCompatible>True</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RobotNet.Script.Expressions\RobotNet.Script.Expressions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
20
RobotNet.Script/TaskAttribute.cs
Normal file
20
RobotNet.Script/TaskAttribute.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace RobotNet.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;
|
||||
}
|
||||
14
RobotNet.Script/VariableAttribute.cs
Normal file
14
RobotNet.Script/VariableAttribute.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
namespace RobotNet.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