mirror of
https://github.com/OpenLogics/MewtocolNet.git
synced 2025-12-06 03:01:24 +00:00
Fix not supported extended msg header on older plcs
This commit is contained in:
@@ -444,6 +444,30 @@ namespace MewtocolNet
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public EndInitSetup<T> WithHeartbeatTask(Func<Task> heartBeatAsync, bool executeInProg = false) => WithHeartbeatTask(heartBeatAsync, executeInProg);
|
public EndInitSetup<T> WithHeartbeatTask(Func<Task> heartBeatAsync, bool executeInProg = false) => WithHeartbeatTask(heartBeatAsync, executeInProg);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Disables all heartbeat tasks
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
public EndInitSetup<T> DisableHeartBeat() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
var plc = (MewtocolInterface)(object)this.intf;
|
||||||
|
|
||||||
|
plc.disableHeartbeat = true;
|
||||||
|
|
||||||
|
return new EndInitSetup<T> {
|
||||||
|
postInit = this,
|
||||||
|
};
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
|
||||||
|
throw;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builds and returns the final plc interface
|
/// Builds and returns the final plc interface
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -79,6 +79,8 @@ namespace MewtocolNet {
|
|||||||
private protected Task<MewtocolFrameResponse> regularSendTask;
|
private protected Task<MewtocolFrameResponse> regularSendTask;
|
||||||
|
|
||||||
private protected bool wasInitialStatusReceived;
|
private protected bool wasInitialStatusReceived;
|
||||||
|
private protected bool supportsExtendedMessageHeader;
|
||||||
|
private protected string messageHeader = "%";
|
||||||
private protected MewtocolVersion mewtocolVersion;
|
private protected MewtocolVersion mewtocolVersion;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
internal Task heartbeatTask = Task.CompletedTask;
|
internal Task heartbeatTask = Task.CompletedTask;
|
||||||
|
|
||||||
|
internal bool disableHeartbeat = false;
|
||||||
internal Func<IPlc, Task> heartbeatCallbackTask;
|
internal Func<IPlc, Task> heartbeatCallbackTask;
|
||||||
internal bool execHeartBeatCallbackTaskInProg = false;
|
internal bool execHeartBeatCallbackTaskInProg = false;
|
||||||
|
|
||||||
@@ -146,6 +147,13 @@ namespace MewtocolNet {
|
|||||||
|
|
||||||
private async Task HeartbeatTickTask () {
|
private async Task HeartbeatTickTask () {
|
||||||
|
|
||||||
|
if (disableHeartbeat) {
|
||||||
|
|
||||||
|
await Task.CompletedTask;
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (regularSendTask != null && !regularSendTask.IsCompleted) await regularSendTask;
|
if (regularSendTask != null && !regularSendTask.IsCompleted) await regularSendTask;
|
||||||
|
|
||||||
Logger.LogVerbose("Sending heartbeat", this);
|
Logger.LogVerbose("Sending heartbeat", this);
|
||||||
|
|||||||
@@ -65,12 +65,21 @@ namespace MewtocolNet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isConnectingStage) {
|
if (isConnectingStage) {
|
||||||
|
|
||||||
//set the intial obj
|
//set the intial obj
|
||||||
PlcInfo = plcInf;
|
PlcInfo = plcInf;
|
||||||
|
|
||||||
|
//check if the plc supports the extended command header (<)
|
||||||
|
var res = await SendCommandInternalAsync($"<{GetStationNumber()}#RDD0000000001");
|
||||||
|
supportsExtendedMessageHeader = res.Success;
|
||||||
|
messageHeader = res.Success ? "<" : "%";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
//update the obj with RT dynamic values only
|
//update the obj with RT dynamic values only
|
||||||
PlcInfo.SelfDiagnosticError = plcInf.SelfDiagnosticError;
|
PlcInfo.SelfDiagnosticError = plcInf.SelfDiagnosticError;
|
||||||
PlcInfo.OperationMode = plcInf.OperationMode;
|
PlcInfo.OperationMode = plcInf.OperationMode;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return PlcInfo;
|
return PlcInfo;
|
||||||
@@ -257,7 +266,7 @@ namespace MewtocolNet {
|
|||||||
string startStr = start.ToString().PadLeft(5, '0');
|
string startStr = start.ToString().PadLeft(5, '0');
|
||||||
string endStr = (start + wordLength - 1).ToString().PadLeft(5, '0');
|
string endStr = (start + wordLength - 1).ToString().PadLeft(5, '0');
|
||||||
|
|
||||||
string requeststring = $"%{GetStationNumber()}#WDD{startStr}{endStr}{byteString}";
|
string requeststring = $"{messageHeader}{GetStationNumber()}#WDD{startStr}{endStr}{byteString}";
|
||||||
var result = await SendCommandInternalAsync(requeststring);
|
var result = await SendCommandInternalAsync(requeststring);
|
||||||
|
|
||||||
return result.Success;
|
return result.Success;
|
||||||
@@ -270,6 +279,7 @@ namespace MewtocolNet {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="start">Start adress</param>
|
/// <param name="start">Start adress</param>
|
||||||
/// <param name="byteCount">Number of bytes to get</param>
|
/// <param name="byteCount">Number of bytes to get</param>
|
||||||
|
/// <param name="areaPrefix">The memory area to read</param>
|
||||||
/// <param name="onProgress">Gets invoked when the progress changes, contains the progress as a double from 0 - 1.0</param>
|
/// <param name="onProgress">Gets invoked when the progress changes, contains the progress as a double from 0 - 1.0</param>
|
||||||
/// <returns>A byte array of the requested DT area</returns>
|
/// <returns>A byte array of the requested DT area</returns>
|
||||||
public async Task<byte[]> ReadAreaByteRangeAsync(int start, int byteCount, RegisterPrefix areaPrefix = RegisterPrefix.DT, Action<double> onProgress = null) {
|
public async Task<byte[]> ReadAreaByteRangeAsync(int start, int byteCount, RegisterPrefix areaPrefix = RegisterPrefix.DT, Action<double> onProgress = null) {
|
||||||
@@ -316,7 +326,7 @@ namespace MewtocolNet {
|
|||||||
int blockSize = wordEnd - wordStart + 1;
|
int blockSize = wordEnd - wordStart + 1;
|
||||||
string startStr = wordStart.ToString().PadLeft(padLeftLen, '0');
|
string startStr = wordStart.ToString().PadLeft(padLeftLen, '0');
|
||||||
string endStr = wordEnd.ToString().PadLeft(padLeftLen, '0');
|
string endStr = wordEnd.ToString().PadLeft(padLeftLen, '0');
|
||||||
string requeststring = $"<{GetStationNumber()}#{areaCodeStr}{startStr}{endStr}";
|
string requeststring = $"{messageHeader}{GetStationNumber()}#{areaCodeStr}{startStr}{endStr}";
|
||||||
|
|
||||||
var result = await SendCommandInternalAsync(requeststring, onReceiveProgress: readProg);
|
var result = await SendCommandInternalAsync(requeststring, onReceiveProgress: readProg);
|
||||||
|
|
||||||
|
|||||||
@@ -81,8 +81,6 @@ namespace MewtocolNet.Registers {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
uint MemoryAddress { get; }
|
uint MemoryAddress { get; }
|
||||||
|
|
||||||
string MemoryAreaHash { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the value of the register as the plc representation string
|
/// Gets the value of the register as the plc representation string
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -101,8 +101,6 @@ namespace MewtocolNet.Registers {
|
|||||||
|
|
||||||
public string MemoryAreaInfo => underlyingMemory.ToString();
|
public string MemoryAreaInfo => underlyingMemory.ToString();
|
||||||
|
|
||||||
public string MemoryAreaHash => underlyingMemory.GetHashCode().ToString();
|
|
||||||
|
|
||||||
internal Register() { }
|
internal Register() { }
|
||||||
|
|
||||||
internal virtual void OnPlcConnected () {
|
internal virtual void OnPlcConnected () {
|
||||||
|
|||||||
Reference in New Issue
Block a user