11 Commits

Author SHA1 Message Date
Felix Weiß
43c7f72ac4 Added auto register reset to default typed value on disconnect 2022-10-21 11:56:58 +02:00
Felix Weiß
2e35ed87af Updated hyperlinks in readme 2022-10-20 10:16:11 +02:00
Felix Weiß
a7f97a72ea Package id change in readme 2022-10-20 10:11:13 +02:00
Felix Weiß
51870166e4 Update publish.yml 2022-10-20 10:04:49 +02:00
Felix Weiß
b43e9bd201 Package id 2022-10-20 10:02:59 +02:00
Felix Weiß
e313dbc3ec Changed package ID 2022-10-20 10:01:53 +02:00
Felix Weiß
bdf9f93f97 Update MewtocolNet.csproj 2022-10-20 09:50:58 +02:00
Felix Weiß
fe816ab78e Update publish.yml 2022-10-20 09:46:08 +02:00
Felix Weiß
48a5977185 Create publish.yml 2022-10-20 09:36:35 +02:00
Felix Weiß
c69f63c191 Update README.md 2022-09-27 10:21:37 +02:00
Felix Weiß
6a2f278dd1 Fixed negative queued msges
- version count up
2022-09-27 10:18:01 +02:00
7 changed files with 139 additions and 11 deletions

57
.github/workflows/publish.yml vendored Normal file
View File

@@ -0,0 +1,57 @@
name: publish to nuget
on:
push:
branches:
- master # Default release branch, may also be named 'master' or 'develop'
jobs:
publish:
name: build, pack & publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
# - name: Setup dotnet
# uses: actions/setup-dotnet@v1
# with:
# dotnet-version: 3.1.200
# Publish
- name: publish on version change
id: publish_nuget
uses: brandedoutcast/publish-nuget@v2
with:
# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: MewtocolNet/MewtocolNet.csproj
# Configuration to build and package
# BUILD_CONFIGURATION: Release
# Platform target to compile (default is empty/AnyCPU)
# BUILD_PLATFORM: x64
# NuGet package id, used for version detection & defaults to project name
PACKAGE_NAME: Mewtocol.NET
# Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH
# VERSION_FILE_PATH: Directory.Build.props
# Regex pattern to extract version info in a capturing group
# VERSION_REGEX: ^\s*<Version>(.*)<\/Version>\s*$
# Useful with external providers like Nerdbank.GitVersioning, ignores VERSION_FILE_PATH & VERSION_REGEX
# VERSION_STATIC: 1.0.0
# Flag to toggle git tagging, enabled by default
# TAG_COMMIT: true
# Format of the git tag, [*] gets replaced with actual version
# TAG_FORMAT: v*
# API key to authenticate with NuGet server
NUGET_KEY: ${{secrets.NUGET_KEY}}
# NuGet server uri hosting the packages, defaults to https://api.nuget.org
# NUGET_SOURCE: https://api.nuget.org
# Flag to toggle pushing symbols along with nuget package to the server, disabled by default
# INCLUDE_SYMBOLS: false

View File

@@ -34,7 +34,7 @@ class Program {
Task.Factory.StartNew(async () => { Task.Factory.StartNew(async () => {
//attaching the logger //attaching the logger
Logger.LogLevel = LogLevel.Critical; Logger.LogLevel = LogLevel.Verbose;
Logger.OnNewLogMessage((date, msg) => { Logger.OnNewLogMessage((date, msg) => {
Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}"); Console.WriteLine($"{date.ToString("HH:mm:ss")} {msg}");
}); });
@@ -50,6 +50,7 @@ class Program {
while (true) { while (true) {
if (isProgressReadout) continue; if (isProgressReadout) continue;
Console.Title = $"Polling Paused: {interf.PollingPaused}, " + Console.Title = $"Polling Paused: {interf.PollingPaused}, " +
$"Poller active: {interf.PollerActive}, " +
$"Speed UP: {interf.BytesPerSecondUpstream} B/s, " + $"Speed UP: {interf.BytesPerSecondUpstream} B/s, " +
$"Speed DOWN: {interf.BytesPerSecondDownstream} B/s, " + $"Speed DOWN: {interf.BytesPerSecondDownstream} B/s, " +
$"Poll delay: {interf.PollerDelayMs} ms, " + $"Poll delay: {interf.PollerDelayMs} ms, " +
@@ -58,7 +59,21 @@ class Program {
} }
}); });
await interf.ConnectAsync((plcinf) => AfterConnect(interf, registers)); //await interf.ConnectAsync((plcinf) => AfterConnect(interf, registers));
bool flip = false;
while(true) {
if(!flip) {
await interf.ConnectAsync();
} else {
interf.Disconnect();
}
flip = !flip;
await Task.Delay(5000);
}
}); });

View File

@@ -19,11 +19,17 @@ namespace MewtocolNet {
/// </summary> /// </summary>
public bool PollingPaused => pollerIsPaused; public bool PollingPaused => pollerIsPaused;
/// <summary>
/// True if the poller is actvice (can be paused)
/// </summary>
public bool PollerActive => !pollerTaskStopped;
internal event Action PolledCycle; internal event Action PolledCycle;
internal volatile bool pollerTaskRunning; internal volatile bool pollerTaskRunning;
internal volatile bool pollerTaskStopped; internal volatile bool pollerTaskStopped;
internal volatile bool pollerIsPaused; internal volatile bool pollerIsPaused;
internal volatile bool pollerFirstCycle = false;
internal bool usePoller = false; internal bool usePoller = false;
@@ -37,6 +43,8 @@ namespace MewtocolNet {
pollerTaskRunning = false; pollerTaskRunning = false;
pollerTaskStopped = true; pollerTaskStopped = true;
ClearRegisterVals();
} }
/// <summary> /// <summary>
@@ -80,6 +88,8 @@ namespace MewtocolNet {
if (pollerTaskRunning) if (pollerTaskRunning)
return; return;
pollerFirstCycle = true;
Task.Factory.StartNew(async () => { Task.Factory.StartNew(async () => {
Logger.Log("Poller is attaching", LogLevel.Info, this); Logger.Log("Poller is attaching", LogLevel.Info, this);
@@ -167,6 +177,7 @@ namespace MewtocolNet {
} }
iteration++; iteration++;
pollerFirstCycle = false;
await Task.Delay(pollerDelayMs); await Task.Delay(pollerDelayMs);

View File

@@ -395,6 +395,17 @@ namespace MewtocolNet {
} }
private void ClearRegisterVals () {
for (int i = 0; i < Registers.Count; i++) {
var reg = Registers[i];
reg.ClearValue();
}
}
#endregion #endregion
#region Register Collection #region Register Collection
@@ -733,7 +744,10 @@ namespace MewtocolNet {
try { try {
queuedMessages++; queuedMessages++;
var response = await queue.Enqueue(() => SendSingleBlock(_msg)); var response = await queue.Enqueue(() => SendSingleBlock(_msg));
if (queuedMessages > 0)
queuedMessages--; queuedMessages--;
if (response == null) { if (response == null) {

View File

@@ -94,6 +94,38 @@ namespace MewtocolNet.Registers {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value")); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("Value"));
} }
internal void ClearValue () {
if (enumType != null && this is NRegister<int> intEnumReg) {
intEnumReg.SetValueFromPLC((int)0);
}
if (this is NRegister<short> shortReg) {
shortReg.SetValueFromPLC((short)0);
}
if (this is NRegister<ushort> ushortReg) {
ushortReg.SetValueFromPLC((ushort)0);
}
if (this is NRegister<int> intReg) {
intReg.SetValueFromPLC((int)0);
}
if (this is NRegister<uint> uintReg) {
uintReg.SetValueFromPLC((uint)0);
}
if (this is NRegister<float> floatReg) {
floatReg.SetValueFromPLC((float)0);
}
if (this is NRegister<TimeSpan> tsReg) {
tsReg.SetValueFromPLC(TimeSpan.Zero);
}
if (this is BRegister boolReg) {
boolReg.SetValueFromPLC(false);
}
if (this is SRegister stringReg) {
stringReg.SetValueFromPLC(null);
}
}
/// <summary> /// <summary>
/// Gets the starting memory are either numeric or A,B,C,D etc for special areas like inputs /// Gets the starting memory are either numeric or A,B,C,D etc for special areas like inputs
/// </summary> /// </summary>

View File

@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<PackageId>MewtocolNet</PackageId> <PackageId>Mewtocol.NET</PackageId>
<Version>0.5.8</Version> <Version>0.6.2</Version>
<Authors>Felix Weiss</Authors> <Authors>Felix Weiss</Authors>
<Company>Womed</Company> <Company>Womed</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild> <GeneratePackageOnBuild>true</GeneratePackageOnBuild>

View File

@@ -1,7 +1,6 @@
[![.NET Windows](https://github.com/WOmed/MewtocolNet/actions/workflows/dotnet-windows.yml/badge.svg)](https://github.com/WOmed/MewtocolNet/actions/workflows/dotnet-windows.yml) [![Publish to Nuget](https://github.com/WOmed/MewtocolNet/actions/workflows/publish.yml/badge.svg)](https://github.com/WOmed/MewtocolNet/actions/workflows/publish.yml)
![Nuget](https://img.shields.io/nuget/v/MewtocolNet) [![Nuget](https://img.shields.io/nuget/v/Mewtocol.NET)](https://www.nuget.org/packages/Mewtocol.NET)
![Lines of code](https://img.shields.io/tokei/lines/github/WOmed/MewtocolNet) ![Lines of code](https://img.shields.io/tokei/lines/github/WOmed/MewtocolNet)
![Nuget](https://img.shields.io/nuget/dt/MewtocolNet)
![GitHub](https://img.shields.io/github/license/WOmed/MewtocolNet) ![GitHub](https://img.shields.io/github/license/WOmed/MewtocolNet)
![Status](https://img.shields.io/badge/Status-In%20dev-orange) ![Status](https://img.shields.io/badge/Status-In%20dev-orange)
@@ -51,14 +50,14 @@ Where is the RS232/Serial support?
# Installing # Installing
Install this package by using [Nuget](https://www.nuget.org/packages/MewtocolNet/) or reference Install this package by using [Nuget](https://www.nuget.org/packages/Mewtocol.NET) or reference
```XML ```XML
<PackageReference Include="MewtocolNet" Version="0.5.2" /> <PackageReference Include="Mewtocol.NET" Version="0.6.1"/>
``` ```
in your dependencies. in your dependencies.
Alternatively use the dotnet CLI and run Alternatively use the dotnet CLI and run
```Shell ```Shell
dotnet add package MewtocolNet dotnet add package Mewtocol.NET
``` ```
# Protocol description # Protocol description