Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cpu status enum #508

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion S7.Net.UnitTest/CommunicationTests/ReadPlcStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing a similar change for PlcAsynchronous.cs

{
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