-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07710ed
commit 1285813
Showing
4 changed files
with
139 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 14 additions & 14 deletions
28
...olerRDMExample/ControlerRDMExample.csproj → ...olerRDMExample/ControlerRDMExample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ArtNetSharp\ArtNetSharp.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\ArtNetSharp\ArtNetSharp.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
106 changes: 53 additions & 53 deletions
106
ControlerRDMExample/Program.cs → Examples/ControlerRDMExample/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
using ArtNetSharp; | ||
using ArtNetSharp.Communication; | ||
using ControlerRDMExample; | ||
using RDMSharp; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
|
||
Console.WriteLine("Controller RDM Example!"); | ||
|
||
//Add Logging | ||
//ArtNet.SetLoggerFectory(YOUR_LOGGER_FACTORY); | ||
|
||
//Set Networkinterfaces | ||
//var broadcastIp = new IPAddress(new byte[] { 2, 255, 255, 255 }); | ||
//ArtNet.Instance.NetworkClients.ToList().ForEach(ncb => ncb.Enabled = IPAddress.Equals(broadcastIp, ncb.BroadcastIpAddress)); | ||
|
||
// Create Instance | ||
ControllerInstance controllerInstance = new ControllerInstance(); | ||
controllerInstance.Name = controllerInstance.ShortName = "Controller RDM Example"; | ||
ConcurrentDictionary<RDMUID, TestRDMDevice> devices = new(); | ||
|
||
|
||
// Add Instance | ||
ArtNet.Instance.AddInstance(controllerInstance); | ||
|
||
// Configure Ports | ||
for (ushort i = 1; i <= 4; i++) | ||
{ | ||
try | ||
{ | ||
var outputConfig = new PortConfig((byte)i, new PortAddress((ushort)(i - 1)), true, false) { PortNumber = (byte)i, Type = EPortType.OutputFromArtNet, GoodOutput = EGoodOutput.ContiniuousOutput | EGoodOutput.DataTransmitted, }; | ||
outputConfig.AddAdditionalRdmUIDs(generateUIDs()); | ||
controllerInstance.AddPortConfig(outputConfig); | ||
controllerInstance.AddPortConfig(new PortConfig((byte)(i+4), new PortAddress((ushort)(i - 1)), false, true) { PortNumber = (byte)i, Type = EPortType.InputToArtNet | EPortType.ArtNet }); | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
} | ||
} | ||
|
||
RDMUID[] generateUIDs() | ||
{ | ||
RDMUID[] uids = new RDMUID[30]; | ||
for (int i = 0; i < uids.Length; i++) | ||
{ | ||
var uid = new RDMUID(0x9fff, (uint)devices.Count + 1); | ||
devices.TryAdd(uid, new TestRDMDevice(uid)); | ||
uids[i] = uid; | ||
} | ||
return uids; | ||
} | ||
using ArtNetSharp; | ||
using ArtNetSharp.Communication; | ||
using ControlerRDMExample; | ||
using RDMSharp; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Net; | ||
|
||
Console.WriteLine("Controller RDM Example!"); | ||
|
||
//Add Logging | ||
//ArtNet.SetLoggerFectory(YOUR_LOGGER_FACTORY); | ||
|
||
//Set Networkinterfaces | ||
//var broadcastIp = new IPAddress(new byte[] { 2, 255, 255, 255 }); | ||
//ArtNet.Instance.NetworkClients.ToList().ForEach(ncb => ncb.Enabled = IPAddress.Equals(broadcastIp, ncb.BroadcastIpAddress)); | ||
|
||
// Create Instance | ||
ControllerInstance controllerInstance = new ControllerInstance(); | ||
controllerInstance.Name = controllerInstance.ShortName = "Controller RDM Example"; | ||
ConcurrentDictionary<RDMUID, TestRDMDevice> devices = new(); | ||
|
||
|
||
// Add Instance | ||
ArtNet.Instance.AddInstance(controllerInstance); | ||
|
||
// Configure Ports | ||
for (ushort i = 1; i <= 4; i++) | ||
{ | ||
try | ||
{ | ||
var outputConfig = new PortConfig((byte)i, new PortAddress((ushort)(i - 1)), true, false) { PortNumber = (byte)i, Type = EPortType.OutputFromArtNet, GoodOutput = EGoodOutput.ContiniuousOutput | EGoodOutput.DataTransmitted, }; | ||
outputConfig.AddAdditionalRdmUIDs(generateUIDs()); | ||
controllerInstance.AddPortConfig(outputConfig); | ||
controllerInstance.AddPortConfig(new PortConfig((byte)(i+4), new PortAddress((ushort)(i - 1)), false, true) { PortNumber = (byte)i, Type = EPortType.InputToArtNet | EPortType.ArtNet }); | ||
} | ||
catch (Exception ex) | ||
{ | ||
|
||
} | ||
} | ||
|
||
RDMUID[] generateUIDs() | ||
{ | ||
RDMUID[] uids = new RDMUID[30]; | ||
for (int i = 0; i < uids.Length; i++) | ||
{ | ||
var uid = new RDMUID(0x9fff, (uint)devices.Count + 1); | ||
devices.TryAdd(uid, new TestRDMDevice(uid)); | ||
uids[i] = uid; | ||
} | ||
return uids; | ||
} | ||
Console.ReadLine(); |
134 changes: 67 additions & 67 deletions
134
ControlerRDMExample/RDMDeviceMock.cs → ...ples/ControlerRDMExample/RDMDeviceMock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,67 @@ | ||
using ArtNetSharp; | ||
using ArtNetSharp.Communication; | ||
using RDMSharp; | ||
using RDMSharp.ParameterWrapper; | ||
|
||
namespace ControlerRDMExample | ||
{ | ||
public abstract class AbstractRDMDeviceGeneratedMock : AbstractGeneratedRDMDevice | ||
{ | ||
internal static ControllerInstance Controller = ArtNet.Instance.Instances.OfType<ControllerInstance>().First(); | ||
public AbstractRDMDeviceGeneratedMock(RDMUID uid, ERDM_Parameter[] parameters, string manufacturer = null) : base(uid, parameters, manufacturer) | ||
{ | ||
Controller.ControllerRDMMessageReceived += Controller_ControllerRDMMessageReceived; | ||
} | ||
|
||
protected override async Task SendRDMMessage(RDMMessage rdmMessage) | ||
{ | ||
if (this.UID == rdmMessage.DestUID || this.UID == rdmMessage.SourceUID) | ||
{ | ||
Console.WriteLine("S:" + rdmMessage); | ||
await Controller.SendArtRDM(rdmMessage); | ||
} | ||
} | ||
|
||
private async void Controller_ControllerRDMMessageReceived(object? sender, ArtNetSharp.Misc.ControllerRDMMessageReceivedEventArgs e) | ||
{ | ||
if (e.Handled) | ||
return; | ||
if (e.Request.DestUID.IsBroadcast || this.UID == e.Request.DestUID || this.UID == e.Request.SourceUID) | ||
{ | ||
RDMMessage response = null; | ||
try | ||
{ | ||
response = processRequestMessage(e.Request); | ||
} | ||
catch (Exception ex) | ||
{ | ||
} | ||
if (response != null) | ||
e.SetResponse(response); | ||
|
||
Console.WriteLine($"Request:{Environment.NewLine}{e.Request}"); | ||
if (e.Handled) | ||
Console.WriteLine($"Response:{Environment.NewLine}{e.Response}"); | ||
} | ||
} | ||
} | ||
public class TestRDMDevice : AbstractRDMDeviceGeneratedMock | ||
{ | ||
public override EManufacturer ManufacturerID => (EManufacturer)0x9fff; | ||
public override ushort DeviceModelID => 20; | ||
public override ERDM_ProductCategoryCoarse ProductCategoryCoarse => ERDM_ProductCategoryCoarse.CONTROL; | ||
public override ERDM_ProductCategoryFine ProductCategoryFine => ERDM_ProductCategoryFine.DATA_CONVERSION; | ||
public override uint SoftwareVersionID => 0x1234; | ||
public override string DeviceModelDescription => "Test Model Description"; | ||
public override bool SupportDMXAddress => true; | ||
|
||
private static GeneratedPersonality[] PERSONALITYS = [new GeneratedPersonality(1, 5, "5CH RGB"), new GeneratedPersonality(2, 8, "8CH RGBAWY"), new GeneratedPersonality(3, 9, "9CH RGB 16-Bit")]; | ||
public override GeneratedPersonality[] Personalities => PERSONALITYS; | ||
public TestRDMDevice(RDMUID uid) : base(uid, [ERDM_Parameter.IDENTIFY_DEVICE, ERDM_Parameter.BOOT_SOFTWARE_VERSION_LABEL], "Dummy Manufacturer 9FFF") | ||
{ | ||
this.DeviceLabel = "Dummy Device 1"; | ||
this.TrySetParameter(ERDM_Parameter.IDENTIFY_DEVICE, false); | ||
this.TrySetParameter(ERDM_Parameter.BOOT_SOFTWARE_VERSION_LABEL, $"Dummy Software"); | ||
} | ||
} | ||
} | ||
using ArtNetSharp; | ||
using ArtNetSharp.Communication; | ||
using RDMSharp; | ||
using RDMSharp.ParameterWrapper; | ||
|
||
namespace ControlerRDMExample | ||
{ | ||
public abstract class AbstractRDMDeviceGeneratedMock : AbstractGeneratedRDMDevice | ||
{ | ||
internal static ControllerInstance Controller = ArtNet.Instance.Instances.OfType<ControllerInstance>().First(); | ||
public AbstractRDMDeviceGeneratedMock(RDMUID uid, ERDM_Parameter[] parameters, string manufacturer = null) : base(uid, parameters, manufacturer) | ||
{ | ||
Controller.ControllerRDMMessageReceived += Controller_ControllerRDMMessageReceived; | ||
} | ||
|
||
protected override async Task SendRDMMessage(RDMMessage rdmMessage) | ||
{ | ||
if (this.UID == rdmMessage.DestUID || this.UID == rdmMessage.SourceUID) | ||
{ | ||
Console.WriteLine("S:" + rdmMessage); | ||
await Controller.SendArtRDM(rdmMessage); | ||
} | ||
} | ||
|
||
private async void Controller_ControllerRDMMessageReceived(object? sender, ArtNetSharp.Misc.ControllerRDMMessageReceivedEventArgs e) | ||
Check warning on line 25 in Examples/ControlerRDMExample/RDMDeviceMock.cs GitHub Actions / build
|
||
{ | ||
if (e.Handled) | ||
return; | ||
if (e.Request.DestUID.IsBroadcast || this.UID == e.Request.DestUID || this.UID == e.Request.SourceUID) | ||
{ | ||
RDMMessage response = null; | ||
try | ||
{ | ||
response = processRequestMessage(e.Request); | ||
} | ||
catch (Exception ex) | ||
{ | ||
} | ||
if (response != null) | ||
e.SetResponse(response); | ||
|
||
Console.WriteLine($"Request:{Environment.NewLine}{e.Request}"); | ||
if (e.Handled) | ||
Console.WriteLine($"Response:{Environment.NewLine}{e.Response}"); | ||
} | ||
} | ||
} | ||
public class TestRDMDevice : AbstractRDMDeviceGeneratedMock | ||
{ | ||
public override EManufacturer ManufacturerID => (EManufacturer)0x9fff; | ||
public override ushort DeviceModelID => 20; | ||
public override ERDM_ProductCategoryCoarse ProductCategoryCoarse => ERDM_ProductCategoryCoarse.CONTROL; | ||
public override ERDM_ProductCategoryFine ProductCategoryFine => ERDM_ProductCategoryFine.DATA_CONVERSION; | ||
public override uint SoftwareVersionID => 0x1234; | ||
public override string DeviceModelDescription => "Test Model Description"; | ||
public override bool SupportDMXAddress => true; | ||
|
||
private static GeneratedPersonality[] PERSONALITYS = [new GeneratedPersonality(1, 5, "5CH RGB"), new GeneratedPersonality(2, 8, "8CH RGBAWY"), new GeneratedPersonality(3, 9, "9CH RGB 16-Bit")]; | ||
public override GeneratedPersonality[] Personalities => PERSONALITYS; | ||
public TestRDMDevice(RDMUID uid) : base(uid, [ERDM_Parameter.IDENTIFY_DEVICE, ERDM_Parameter.BOOT_SOFTWARE_VERSION_LABEL], "Dummy Manufacturer 9FFF") | ||
{ | ||
this.DeviceLabel = "Dummy Device 1"; | ||
this.TrySetParameter(ERDM_Parameter.IDENTIFY_DEVICE, false); | ||
this.TrySetParameter(ERDM_Parameter.BOOT_SOFTWARE_VERSION_LABEL, $"Dummy Software"); | ||
} | ||
} | ||
} |