Fix bug with writing too many bytes

This commit is contained in:
Peter Butzhammer
2024-04-26 15:20:51 +02:00
parent c3ccdad31c
commit e2a278940e
2 changed files with 4 additions and 4 deletions

View File

@@ -168,11 +168,11 @@ internal class Sharp7Connector: IDisposable
EnsureSuccessOrThrow(result, $"Error writing {operand}{dbNo}:{startByteAddress} bit {bitAdress}"); EnsureSuccessOrThrow(result, $"Error writing {operand}{dbNo}:{startByteAddress} bit {bitAdress}");
} }
public async Task WriteBytes(Operand operand, ushort startByteAddress, byte[] data, ushort dbNo, CancellationToken token) public async Task WriteBytes(Operand operand, ushort startByteAddress, byte[] data, ushort dbNo, ushort bytesToWrite, CancellationToken token)
{ {
EnsureConnectionValid(); EnsureConnectionValid();
var result = await Task.Factory.StartNew(() => sharp7.WriteArea(operand.ToArea(), dbNo, startByteAddress, data.Length, S7WordLength.Byte, data), token, TaskCreationOptions.None, scheduler); var result = await Task.Factory.StartNew(() => sharp7.WriteArea(operand.ToArea(), dbNo, startByteAddress, bytesToWrite, S7WordLength.Byte, data), token, TaskCreationOptions.None, scheduler);
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
EnsureSuccessOrThrow(result, $"Error writing {operand}{dbNo}:{startByteAddress}.{data.Length}"); EnsureSuccessOrThrow(result, $"Error writing {operand}{dbNo}:{startByteAddress}.{data.Length}");

View File

@@ -188,7 +188,7 @@ public class Sharp7Plc : IPlc
{ {
ValueConverter.WriteToBuffer(buffer, value, address); ValueConverter.WriteToBuffer(buffer, value, address);
await s7Connector.WriteBytes(address.Operand, address.Start, buffer, address.DbNo, token); await s7Connector.WriteBytes(address.Operand, address.Start, buffer, address.DbNo, address.BufferLength, token);
} }
finally finally
{ {
@@ -295,7 +295,7 @@ public class Sharp7Plc : IPlc
StartNotificationLoop(); StartNotificationLoop();
} }
private async Task<Unit> GetAllValues(IS7Connector connector) private async Task<Unit> GetAllValues(Sharp7Connector connector)
{ {
if (multiVariableSubscriptions.ExistingKeys.IsEmpty()) if (multiVariableSubscriptions.ExistingKeys.IsEmpty())
return Unit.Default; return Unit.Default;