Skip to content

Commit b187c85

Browse files
committed
Fix NPE in AbstractInstance while no PortConfigs are set
Bump v0.0.27
1 parent 1966dfa commit b187c85

File tree

7 files changed

+101
-10
lines changed

7 files changed

+101
-10
lines changed

ArtNetSharp.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NodeInputExample", "Example
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControlerRDMExample", "Examples\ControlerRDMExample\ControlerRDMExample.csproj", "{90BF6833-7425-4D6B-A8F9-8487A60F1B78}"
1717
EndProject
18+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConfigExample", "Examples\ConfigExample\ConfigExample.csproj", "{DF3AFD9A-0629-43C9-AAC6-5EF22728C5E8}"
19+
EndProject
1820
Global
1921
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2022
Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
4547
{90BF6833-7425-4D6B-A8F9-8487A60F1B78}.Debug|Any CPU.Build.0 = Debug|Any CPU
4648
{90BF6833-7425-4D6B-A8F9-8487A60F1B78}.Release|Any CPU.ActiveCfg = Release|Any CPU
4749
{90BF6833-7425-4D6B-A8F9-8487A60F1B78}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{DF3AFD9A-0629-43C9-AAC6-5EF22728C5E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{DF3AFD9A-0629-43C9-AAC6-5EF22728C5E8}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{DF3AFD9A-0629-43C9-AAC6-5EF22728C5E8}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{DF3AFD9A-0629-43C9-AAC6-5EF22728C5E8}.Release|Any CPU.Build.0 = Release|Any CPU
4854
EndGlobalSection
4955
GlobalSection(SolutionProperties) = preSolution
5056
HideSolutionNode = FALSE

ArtNetSharp/ArtNetSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks>
44
<PackageLicenseFile>LICENSE</PackageLicenseFile>
5-
<Version>0.0.26</Version>
5+
<Version>0.0.27</Version>
66
<RepositoryUrl>https://github.com/DMXControl/ArtNetSharp</RepositoryUrl>
77
<PackageProjectUrl>$(RepositoryUrl)</PackageProjectUrl>
88
<PackageTags>RDM; ArtNet; E1.20; E1.33; E1.37-1; E1.37-2; E1.37-7</PackageTags>

ArtNetSharp/Communication/AbstractInstance.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public void Dispose()
239239
private readonly ConcurrentDictionary<string, RemoteClient> remoteClients = new ConcurrentDictionary<string, RemoteClient>();
240240
private readonly ConcurrentDictionary<string, RemoteClient> remoteClientsTimeouted = new ConcurrentDictionary<string, RemoteClient>();
241241
public IReadOnlyCollection<RemoteClient> RemoteClients { get; private set; } = new List<RemoteClient>();
242-
public IReadOnlyCollection<RemoteClientPort> RemoteClientsPorts { get { return remoteClients.SelectMany(rc => rc.Value.Ports).ToList().AsReadOnly(); } }
242+
public IReadOnlyCollection<RemoteClientPort> RemoteClientsPorts { get { return remoteClients?.Where(rc => rc.Value?.Ports != null).SelectMany(rc => rc.Value.Ports).ToList().AsReadOnly(); } }
243243

244244
public event EventHandler<PortAddress> DMXReceived;
245245
public event EventHandler SyncReceived;
@@ -581,7 +581,7 @@ private async Task sendAllArtDMX()
581581

582582
try
583583
{
584-
var ports = RemoteClientsPorts.Where(port => port.OutputPortAddress.HasValue && !port.Timouted()).ToList();
584+
var ports = RemoteClientsPorts?.Where(port => port.OutputPortAddress.HasValue && !port.Timouted())?.ToList();
585585

586586
int sended = 0;
587587
foreach (var port in ports)
@@ -590,13 +590,23 @@ private async Task sendAllArtDMX()
590590
if (sendDMXBuffer.TryGetValue(port.OutputPortAddress.Value, out DMXSendBag bag))
591591
if ((bag.Updated && (DateTime.UtcNow - bag.LastSended).TotalMilliseconds >= dmxRefreshTime) || (DateTime.UtcNow - bag.LastSended).TotalMilliseconds >= dmxKeepAliveTime)
592592
{
593-
bag.LastSended = DateTime.UtcNow;
594-
PortConfig config = portConfigs.FirstOrDefault(pc => PortAddress.Equals(pc.PortAddress, port.OutputPortAddress));
595-
byte sourcePort = config?.PortNumber ?? 0;
596-
await sendArtDMX(port, sourcePort, bag.Data, bag.GetSequence(), config?.ForceBroadcast ?? false);
597-
sended++;
598-
if (config == null)
593+
PortConfig config = null;
594+
byte sourcePort = 0;
595+
try
596+
{
597+
bag.LastSended = DateTime.UtcNow;
598+
config = portConfigs?.FirstOrDefault(pc => PortAddress.Equals(pc.PortAddress, port.OutputPortAddress));
599+
sourcePort = config?.PortNumber ?? 0;
600+
await sendArtDMX(port, sourcePort, bag.Data, bag.GetSequence(), config?.ForceBroadcast ?? false);
601+
sended++;
602+
if (config == null)
603+
return;
604+
}
605+
catch (Exception e)
606+
{
607+
Logger.LogError(e, "Inner Block");
599608
return;
609+
}
600610
foreach (IPv4Address ip in config?.AdditionalIPEndpoints)
601611
{
602612
await sendArtDMX(ip, config.PortAddress, sourcePort, bag.Data, bag.GetSequence());
@@ -605,7 +615,7 @@ private async Task sendAllArtDMX()
605615
bag.LastSended = DateTime.UtcNow;
606616
}
607617
}
608-
catch (Exception e) { Logger.LogError(e); }
618+
catch (Exception e) { Logger.LogError(e, "Outer Block"); }
609619
if (EnableSync && sended != 0)
610620
await sendArtSync();
611621

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<ProjectReference Include="..\..\ArtNetSharp\ArtNetSharp.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage
2+
// attributes that are applied to this project.
3+
// Project-level suppressions either have no target or are given
4+
// a specific target and scoped to a namespace, type, member, etc.
5+
6+
using System.Diagnostics.CodeAnalysis;
7+
8+
[assembly: SuppressMessage("Style", "IDE0090:\"new(...)\" verwenden", Justification = "<Ausstehend>")]

Examples/ConfigExample/Program.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using ArtNetSharp;
2+
using ArtNetSharp.Communication;
3+
4+
Console.WriteLine("Config Example!");
5+
6+
//Add Logging
7+
//ArtNet.SetLoggerFectory(YOUR_LOGGER_FACTORY);
8+
9+
//Set Networkinterfaces
10+
//var broadcastIp = new IPAddress(new byte[] { 2, 255, 255, 255 });
11+
//ArtNet.Instance.NetworkClients.ToList().ForEach(ncb => ncb.Enabled = IPAddress.Equals(broadcastIp, ncb.BroadcastIpAddress));
12+
13+
// Create Instance
14+
ConfigInstance controllerInstance = new ConfigInstance(ArtNet.Instance);
15+
controllerInstance.Name = controllerInstance.ShortName = "Config Example";
16+
17+
// Configure Ports
18+
//for (byte i = 1; i <= 32; i++)
19+
// controllerInstance.AddPortConfig(new PortConfig(i, new PortAddress((ushort)(i - 1)), false, true) { PortNumber = (byte)i, Type = EPortType.InputToArtNet | EPortType.ArtNet });
20+
21+
// Add Instance
22+
ArtNet.Instance.AddInstance(controllerInstance);
23+
controllerInstance.RemoteClientDiscovered += (o, e) =>
24+
{
25+
Console.WriteLine($"Discovered: {e.IpAddress}");
26+
e.PortDiscovered += (o1, e1) =>
27+
{
28+
e1.PropertyChanged += (o2, e2) =>
29+
{
30+
if (e2.PropertyName?.Equals(nameof(RemoteClientPort.LastSeen)) ?? true)
31+
return;
32+
33+
Console.WriteLine($"{e.IpAddress}/{e1.PortIndex}:{e2.PropertyName} changed");
34+
};
35+
};
36+
}; controllerInstance.RemoteClientTimedOut += (o, e) =>
37+
{
38+
Console.WriteLine($"TimedOuted: {e.IpAddress}");
39+
};
40+
Console.ReadLine();
41+
42+
// Genrerate some DMX-Data
43+
//byte[] data = new byte[512];
44+
//while (true)
45+
//{
46+
// await Task.Delay(200);
47+
// for (short k = 0; k < 512; k++)
48+
// data[k]++;
49+
50+
// for (ushort i = 0; i < 32; i++)
51+
// controllerInstance.WriteDMXValues(i, data);
52+
//}

Examples/ConfigExample/Usings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global using org.dmxc.wkdt.Light.ArtNet;

0 commit comments

Comments
 (0)