mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 11:11:23 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cc222abcc | ||
|
|
14659ffaad |
@@ -11,33 +11,58 @@ using MewtocolNet.RegisterAttributes;
|
||||
using MewtocolNet.Logging;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace MewtocolNet {
|
||||
|
||||
/// <summary>
|
||||
/// The PLC com interface class
|
||||
/// </summary>
|
||||
public partial class MewtocolInterface {
|
||||
public partial class MewtocolInterface : INotifyPropertyChanged {
|
||||
|
||||
/// <summary>
|
||||
/// Gets triggered when the PLC connection was established
|
||||
/// </summary>
|
||||
public event Action<PLCInfo> Connected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets triggered when the PLC connection was closed or lost
|
||||
/// </summary>
|
||||
public event Action Disconnected;
|
||||
|
||||
/// <summary>
|
||||
/// Gets triggered when a registered data register changes its value
|
||||
/// </summary>
|
||||
public event Action<Register> RegisterChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Gets triggered when a property of the interface changes
|
||||
/// </summary>
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private bool isConnected;
|
||||
/// <summary>
|
||||
/// The current connection state of the interface
|
||||
/// </summary>
|
||||
public bool IsConnected { get; private set; }
|
||||
public bool IsConnected {
|
||||
get => isConnected;
|
||||
private set {
|
||||
isConnected = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsConnected)));
|
||||
}
|
||||
}
|
||||
|
||||
private PLCInfo plcInfo;
|
||||
/// <summary>
|
||||
/// Generic information about the connected PLC
|
||||
/// </summary>
|
||||
public PLCInfo PlcInfo { get; private set; }
|
||||
public PLCInfo PlcInfo {
|
||||
get => plcInfo;
|
||||
private set {
|
||||
plcInfo = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(PlcInfo)));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The registered data registers of the PLC
|
||||
@@ -61,6 +86,19 @@ namespace MewtocolNet {
|
||||
/// </summary>
|
||||
public int StationNumber => stationNumber;
|
||||
|
||||
private int cycleTimeMs;
|
||||
/// <summary>
|
||||
/// The duration of the last message cycle
|
||||
/// </summary>
|
||||
public int CycleTimeMs {
|
||||
get { return cycleTimeMs; }
|
||||
set {
|
||||
cycleTimeMs = value;
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(CycleTimeMs)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal List<Task> PriorityTasks { get; set; } = new List<Task>();
|
||||
|
||||
#region Initialization
|
||||
@@ -90,7 +128,8 @@ namespace MewtocolNet {
|
||||
|
||||
RegisterChanged += (o) => {
|
||||
|
||||
string address = $"{o.GetRegisterString()}{o.MemoryAdress}".PadRight(5, (char)32); ;
|
||||
string address = $"{o.GetRegisterString()}{o.MemoryAdress}".PadRight(5, (char)32);
|
||||
;
|
||||
|
||||
Logger.Log($"{address} " +
|
||||
$"{(o.Name != null ? $"({o.Name}) " : "")}" +
|
||||
@@ -144,6 +183,7 @@ namespace MewtocolNet {
|
||||
|
||||
if (OnFailed != null) {
|
||||
OnFailed();
|
||||
Disconnected?.Invoke();
|
||||
Logger.Log("Initial connection failed", LogLevel.Info, this);
|
||||
}
|
||||
|
||||
@@ -561,7 +601,11 @@ namespace MewtocolNet {
|
||||
|
||||
} catch (Exception) {
|
||||
|
||||
if (IsConnected) {
|
||||
IsConnected = false;
|
||||
Disconnected?.Invoke();
|
||||
}
|
||||
|
||||
KillPoller();
|
||||
Logger.Log("The PLC connection was closed", LogLevel.Error, this);
|
||||
return null;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<PackageId>MewtocolNet</PackageId>
|
||||
<Version>0.3.2</Version>
|
||||
<Version>0.3.3</Version>
|
||||
<Authors>Felix Weiss</Authors>
|
||||
<Company>Womed</Company>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
|
||||
Reference in New Issue
Block a user