From 67da9bb6e8c291956d2929d933afd16b44a8327c Mon Sep 17 00:00:00 2001 From: JIIIIL <504439788@qq.com> Date: Tue, 12 Sep 2023 10:46:54 +0800 Subject: [PATCH 1/3] add cpu status enum --- S7.Net/Enums.cs | 10 ++++++++++ S7.Net/PlcSynchronous.cs | 5 ++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/S7.Net/Enums.cs b/S7.Net/Enums.cs index 3eb7e4ba..4fa19d4e 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/PlcSynchronous.cs b/S7.Net/PlcSynchronous.cs index 2e281311..fcf05c08 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); From 194a75b0d8f9d2b37489cce021bde40aef24937d Mon Sep 17 00:00:00 2001 From: JIIIIL <504439788@qq.com> Date: Tue, 12 Sep 2023 10:46:54 +0800 Subject: [PATCH 2/3] add cpu status enum --- S7.Net/Enums.cs | 10 ++++++++++ S7.Net/PlcAsynchronous.cs | 5 ++--- S7.Net/PlcSynchronous.cs | 5 ++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/S7.Net/Enums.cs b/S7.Net/Enums.cs index 3eb7e4ba..4fa19d4e 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 8b828f3c..4f55c3c1 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 2e281311..fcf05c08 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); From 1640b8ce25933bbb102361e79b37f419c6eb9081 Mon Sep 17 00:00:00 2001 From: JIIIIL <504439788@qq.com> Date: Wed, 13 Sep 2023 09:14:38 +0800 Subject: [PATCH 3/3] alter ReadPlcStatus test --- S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs b/S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs index 13cc733b..8a28c45e 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(); }