mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
feat: Add Plc.ReadStatusAsync
This commit is contained in:
@@ -329,5 +329,15 @@ namespace S7.Net
|
||||
|
||||
return package.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] BuildSzlReadRequestPackage(ushort szlId, ushort szlIndex)
|
||||
{
|
||||
var stream = new System.IO.MemoryStream();
|
||||
|
||||
WriteSzlReadRequest(stream, szlId, szlIndex);
|
||||
stream.SetLength(stream.Position);
|
||||
|
||||
return stream.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -312,6 +312,17 @@ namespace S7.Net
|
||||
return dataItems;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read the current status from the PLC. A value of 0x08 indicates the PLC is in run status, regardless of the PLC type.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation, with it's result set to the current PLC status on completion.</returns>
|
||||
public async Task<byte> ReadStatusAsync(CancellationToken cancellationToken) {
|
||||
var dataToSend = BuildSzlReadRequestPackage(0x0424, 0);
|
||||
var s7data = await RequestTsduAsync(dataToSend, cancellationToken);
|
||||
|
||||
return (byte) (s7data[94] & 0x0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a number of bytes from a DB starting from a specified index. This handles more than 200 bytes with multiple requests.
|
||||
/// If the write was not successful, check LastErrorCode or LastErrorString.
|
||||
|
||||
Reference in New Issue
Block a user