Skip to content

Commit f285337

Browse files
committed
Fix WriteDMX-Bug (Delta)
Bump v0.0.37
1 parent 8cddc88 commit f285337

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

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>net6.0;net7.0;net8.0;net9.0</TargetFrameworks>
44
<PackageLicenseFile>LICENSE</PackageLicenseFile>
5-
<Version>0.0.36</Version>
5+
<Version>0.0.37</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-5; E1.37-7</PackageTags>

ArtNetSharp/Communication/AbstractInstance.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -186,16 +186,16 @@ public DMXSendBag(byte[] data, PortAddress portAddress)
186186
PortAddress = portAddress;
187187
}
188188

189-
internal async void Update(byte[] data, ushort? startindex = null, ushort? count = null)
189+
internal async void Update(byte[] data, ushort? destinationIndex = null, ushort? count = null)
190190
{
191191
if (IsDisposed || IsDisposing)
192192
return;
193193

194194
await SemaphoreSlim?.WaitAsync();
195195
try
196196
{
197-
if ((startindex + count) <= Data.Length)
198-
Array.Copy(data, 0, Data, startindex.Value, count.Value);
197+
if ((destinationIndex + count) <= Data.Length)
198+
Array.Copy(data, 0, Data, destinationIndex.Value, count.Value);
199199
else
200200
Array.Copy(data, 0, Data, 0, Math.Min(data.Length, Data.Length));
201201

@@ -1072,7 +1072,7 @@ public void RemovePortConfig(params PortConfig[] portConfigs)
10721072
}
10731073
}
10741074

1075-
public void WriteDMXValues(PortAddress portAddress, byte[] data, ushort? startindex = null, ushort? count = null)
1075+
public void WriteDMXValues(PortAddress portAddress, byte[] data, ushort? destinationIndex = null, ushort? count = null)
10761076
{
10771077
if (this.IsDisposing || this.IsDisposed)
10781078
return;
@@ -1081,26 +1081,28 @@ public void WriteDMXValues(PortAddress portAddress, byte[] data, ushort? startin
10811081
throw new ArgumentOutOfRangeException();
10821082

10831083
ushort length = (ushort)data.Length;
1084+
if(count is null)
1085+
count = length;
10841086

1085-
if (startindex > length)
1086-
throw new ArgumentOutOfRangeException();
1087+
if (count > length)
1088+
throw new ArgumentOutOfRangeException($"{nameof(count)} has to be less then {nameof(data)}.{nameof(data.Length)}");
10871089

10881090

1089-
if ((startindex + count) > length)
1090-
throw new ArgumentOutOfRangeException();
1091+
if ((destinationIndex + count) > 512)
1092+
throw new ArgumentOutOfRangeException($"{nameof(destinationIndex)} + {nameof(count)} has to be less then 512");
10911093

10921094
int _startIndex = 0;
10931095
int _count = length;
1094-
if (startindex.HasValue)
1095-
_startIndex = startindex.Value;
1096+
if (destinationIndex.HasValue)
1097+
_startIndex = destinationIndex.Value;
10961098
if (count.HasValue)
10971099
_count = Math.Min(_count, count.Value);
10981100

10991101

11001102
try
11011103
{
11021104
if (sendDMXBuffer.TryGetValue(portAddress, out DMXSendBag bag))
1103-
bag.Update(data, startindex, count);
1105+
bag.Update(data, destinationIndex, count);
11041106
else
11051107
{
11061108
var newBag = new DMXSendBag(data, portAddress);

ArtNetTests/LoopTests/LoopTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ public async Task TestSendDMX()
287287
for (byte b = 0; b <= 10; b++)
288288
await doDmxStuff(b);
289289

290+
instanceTX.WriteDMXValues(portAddress, new byte[] { 0, 1, 2, 3, 4, 5 }, 10, 5);
291+
290292
instanceRX.DMXReceived -= InstanceRX_DMXReceived;
291293

292294
Assert.Multiple(() =>

0 commit comments

Comments
 (0)