Skip to content

Commit

Permalink
add cpu status enum
Browse files Browse the repository at this point in the history
  • Loading branch information
LUJIAN2020 committed Sep 12, 2023
1 parent ab6308e commit 194a75b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
10 changes: 10 additions & 0 deletions S7.Net/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,14 @@ public enum VarType
/// </summary>
Time
}

/// <summary>
/// cpu current status
/// </summary>
public enum CpuStatus : byte
{
Unknown = 0x00,
Run = 0x08,
Stop = 0x04,
}
}
5 changes: 2 additions & 3 deletions S7.Net/PlcAsynchronous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,11 @@ public async Task WriteClockAsync(System.DateTime value, CancellationToken cance
/// <param name="cancellationToken">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.</param>
/// <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 = default)
public async Task<CpuStatus> 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);
}

/// <summary>
Expand Down
5 changes: 2 additions & 3 deletions S7.Net/PlcSynchronous.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
/// <returns>The current PLC status.</returns>
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);
Expand Down

0 comments on commit 194a75b

Please sign in to comment.