save
This commit is contained in:
50
BlazorApp/Models/Canopen/CanopenDeviceRegistry.cs
Normal file
50
BlazorApp/Models/Canopen/CanopenDeviceRegistry.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user