diff --git a/S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs b/S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs
index 13cc733..8a28c45 100644
--- a/S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs
+++ b/S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs
@@ -48,7 +48,7 @@ async Task Client(int port)
await conn.OpenAsync();
var status = await conn.ReadStatusAsync();
- Assert.AreEqual(0x08, status);
+ Assert.AreEqual(CpuStatus.Run, status);
conn.Close();
}
diff --git a/S7.Net/Enums.cs b/S7.Net/Enums.cs
index 3eb7e4b..4fa19d4 100644
--- a/S7.Net/Enums.cs
+++ b/S7.Net/Enums.cs
@@ -218,4 +218,14 @@ public enum VarType
///
Time
}
+
+ ///
+ /// cpu current status
+ ///
+ public enum CpuStatus : byte
+ {
+ Unknown = 0x00,
+ Run = 0x08,
+ Stop = 0x04,
+ }
}
diff --git a/S7.Net/PlcAsynchronous.cs b/S7.Net/PlcAsynchronous.cs
index 8b828f3..4f55c3c 100644
--- a/S7.Net/PlcAsynchronous.cs
+++ b/S7.Net/PlcAsynchronous.cs
@@ -347,12 +347,11 @@ public async Task WriteClockAsync(System.DateTime value, CancellationToken cance
/// The token to monitor for cancellation requests. The default value is None.
/// Please note that cancellation is advisory/cooperative and will not lead to immediate cancellation in all cases.
/// A task that represents the asynchronous operation, with it's result set to the current PLC status on completion.
- public async Task ReadStatusAsync(CancellationToken cancellationToken = default)
+ public async Task ReadStatusAsync(CancellationToken cancellationToken = default)
{
var dataToSend = BuildSzlReadRequestPackage(0x0424, 0);
var s7data = await RequestTsduAsync(dataToSend, cancellationToken);
-
- return (byte) (s7data[37] & 0x0f);
+ return (CpuStatus)(s7data[37] & 0x0f);
}
///
diff --git a/S7.Net/PlcSynchronous.cs b/S7.Net/PlcSynchronous.cs
index 2e28131..fcf05c0 100644
--- a/S7.Net/PlcSynchronous.cs
+++ b/S7.Net/PlcSynchronous.cs
@@ -520,12 +520,11 @@ public void WriteClock(System.DateTime value)
/// Read the current status from the PLC. A value of 0x08 indicates the PLC is in run status, regardless of the PLC type.
///
/// The current PLC status.
- public byte ReadStatus()
+ public CpuStatus ReadStatus()
{
var dataToSend = BuildSzlReadRequestPackage(0x0424, 0);
var s7data = RequestTsdu(dataToSend);
-
- return (byte) (s7data[37] & 0x0f);
+ return (CpuStatus)(s7data[37] & 0x0f);
}
private byte[] RequestTsdu(byte[] requestData) => RequestTsdu(requestData, 0, requestData.Length);