CanRead/BlazorApp/Models/Canopen/CanopenDeviceRegistry.cs
2026-01-23 11:20:08 +07:00

51 lines
1.5 KiB
C#

using BlazorApp.Models.Canopen.Eds;
namespace BlazorApp.Models.Canopen
{
public static class CanopenDeviceRegistry
{
private static readonly Dictionary<int, ICanopenDeviceDecoder> _decoders
= new();
static CanopenDeviceRegistry()
{
// 🔹 Ví dụ cấu hình từ EDS
var encoderEds = new EdsDevice
{
NodeId = 5,
DeviceName = "Encoder GXMMW",
Tpdos =
{
[1] = new EdsTpdo
{
PdoIndex = 1,
Objects =
{
new EdsObject
{
Index = 0x6004,
Name = "Position",
BitOffset = 0,
BitLength = 32,
Factor = 0.094,
Unit = "mm"
}
}
}
}
};
Register(new EdsDeviceDecoder(encoderEds));
}
public static void Register(ICanopenDeviceDecoder decoder)
{
_decoders[decoder.NodeId] = decoder;
}
public static ICanopenDeviceDecoder? GetDecoder(int nodeId)
{
return _decoders.TryGetValue(nodeId, out var d) ? d : null;
}
}
}