Skip to content

Commit

Permalink
[BUG] Inconsistent behavior when bulk writing over cyclic property (#261
Browse files Browse the repository at this point in the history
)

* Create draft PR for #260

* add "lethargic" write method and adjust the compiler
- compiler now uses the lethargic method to set data that should be written later by bulk read and prevents request to write the data again in cyclic loop.

---------

Co-authored-by: PTKu <PTKu@users.noreply.github.com>
Co-authored-by: Peter <61538034+PTKu@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 21, 2023
1 parent 7000595 commit 6bcb0fa
Show file tree
Hide file tree
Showing 22 changed files with 1,082 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,29 @@ private void CreateAssignment(ITypeDeclaration typeDeclaration, IDeclaration dec
case IScalarTypeDeclaration scalarTypeDeclaration:
case IStringTypeDeclaration stringTypeDeclaration:
AddToSource($"var _{declaration.Name}_i_FE8484DAB3 = 0;");
AddToSource($"{declaration.Name}.Select(p => p.Cyclic = plain.{declaration.Name}[_{declaration.Name}_i_FE8484DAB3++]).ToArray();");
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($"{declaration.Name}.Select(p => p.LethargicWrite(plain.{declaration.Name}[_{declaration.Name}_i_FE8484DAB3++])).ToArray();");
AddToSource($"#pragma warning restore CS0612\n");
break;
}
break;
case IReferenceTypeDeclaration referenceTypeDeclaration:
break;
case IEnumTypeDeclaration enumTypeDeclaration:
AddToSource($" {declaration.Name}.Cyclic = (short)plain.{declaration.Name};");
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($" {declaration.Name}.LethargicWrite((short)plain.{declaration.Name});");
AddToSource($"#pragma warning restore CS0612\n");
break;
case INamedValueTypeDeclaration namedValueTypeDeclaration:
AddToSource($" {declaration.Name}.Cyclic = plain.{declaration.Name};");
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($" {declaration.Name}.LethargicWrite(plain.{declaration.Name});");
AddToSource($"#pragma warning restore CS0612\n");
break;
case IScalarTypeDeclaration scalarTypeDeclaration:
case IStringTypeDeclaration stringTypeDeclaration:
AddToSource($" {declaration.Name}.Cyclic = plain.{declaration.Name};");
AddToSource($"#pragma warning disable CS0612\n");
AddToSource($" {declaration.Name}.LethargicWrite(plain.{declaration.Name});");
AddToSource($"#pragma warning restore CS0612\n");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ public async virtual Task PlainToOnline<T>(T plain)
public async Task<IEnumerable<ITwinPrimitive>> PlainToOnlineAsync(Pocos.ArrayDeclarationSimpleNamespace.array_declaration_class plain)
{
var _primitive_i_FE8484DAB3 = 0;
primitive.Select(p => p.Cyclic = plain.primitive[_primitive_i_FE8484DAB3++]).ToArray();
#pragma warning disable CS0612
primitive.Select(p => p.LethargicWrite(plain.primitive[_primitive_i_FE8484DAB3++])).ToArray();
#pragma warning restore CS0612
var _complex_i_FE8484DAB3 = 0;
#pragma warning disable CS0612
complex.Select(p => p._PlainToOnlineNoacAsync(plain.complex[_complex_i_FE8484DAB3++])).ToArray();
Expand All @@ -91,7 +93,9 @@ public async Task<IEnumerable<ITwinPrimitive>> PlainToOnlineAsync(Pocos.ArrayDec
public async Task _PlainToOnlineNoacAsync(Pocos.ArrayDeclarationSimpleNamespace.array_declaration_class plain)
{
var _primitive_i_FE8484DAB3 = 0;
primitive.Select(p => p.Cyclic = plain.primitive[_primitive_i_FE8484DAB3++]).ToArray();
#pragma warning disable CS0612
primitive.Select(p => p.LethargicWrite(plain.primitive[_primitive_i_FE8484DAB3++])).ToArray();
#pragma warning restore CS0612
var _complex_i_FE8484DAB3 = 0;
#pragma warning disable CS0612
complex.Select(p => p._PlainToOnlineNoacAsync(plain.complex[_complex_i_FE8484DAB3++])).ToArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,57 +187,145 @@ public async virtual Task PlainToOnline<T>(T plain)

public async Task<IEnumerable<ITwinPrimitive>> PlainToOnlineAsync(Pocos.class_all_primitives plain)
{
myBOOL.Cyclic = plain.myBOOL;
myBYTE.Cyclic = plain.myBYTE;
myWORD.Cyclic = plain.myWORD;
myDWORD.Cyclic = plain.myDWORD;
myLWORD.Cyclic = plain.myLWORD;
mySINT.Cyclic = plain.mySINT;
myINT.Cyclic = plain.myINT;
myDINT.Cyclic = plain.myDINT;
myLINT.Cyclic = plain.myLINT;
myUSINT.Cyclic = plain.myUSINT;
myUINT.Cyclic = plain.myUINT;
myUDINT.Cyclic = plain.myUDINT;
myULINT.Cyclic = plain.myULINT;
myREAL.Cyclic = plain.myREAL;
myLREAL.Cyclic = plain.myLREAL;
myTIME.Cyclic = plain.myTIME;
myLTIME.Cyclic = plain.myLTIME;
myDATE.Cyclic = plain.myDATE;
myTIME_OF_DAY.Cyclic = plain.myTIME_OF_DAY;
myDATE_AND_TIME.Cyclic = plain.myDATE_AND_TIME;
mySTRING.Cyclic = plain.mySTRING;
myWSTRING.Cyclic = plain.myWSTRING;
#pragma warning disable CS0612
myBOOL.LethargicWrite(plain.myBOOL);
#pragma warning restore CS0612
#pragma warning disable CS0612
myBYTE.LethargicWrite(plain.myBYTE);
#pragma warning restore CS0612
#pragma warning disable CS0612
myWORD.LethargicWrite(plain.myWORD);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDWORD.LethargicWrite(plain.myDWORD);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLWORD.LethargicWrite(plain.myLWORD);
#pragma warning restore CS0612
#pragma warning disable CS0612
mySINT.LethargicWrite(plain.mySINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myINT.LethargicWrite(plain.myINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDINT.LethargicWrite(plain.myDINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLINT.LethargicWrite(plain.myLINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myUSINT.LethargicWrite(plain.myUSINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myUINT.LethargicWrite(plain.myUINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myUDINT.LethargicWrite(plain.myUDINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myULINT.LethargicWrite(plain.myULINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myREAL.LethargicWrite(plain.myREAL);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLREAL.LethargicWrite(plain.myLREAL);
#pragma warning restore CS0612
#pragma warning disable CS0612
myTIME.LethargicWrite(plain.myTIME);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLTIME.LethargicWrite(plain.myLTIME);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDATE.LethargicWrite(plain.myDATE);
#pragma warning restore CS0612
#pragma warning disable CS0612
myTIME_OF_DAY.LethargicWrite(plain.myTIME_OF_DAY);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDATE_AND_TIME.LethargicWrite(plain.myDATE_AND_TIME);
#pragma warning restore CS0612
#pragma warning disable CS0612
mySTRING.LethargicWrite(plain.mySTRING);
#pragma warning restore CS0612
#pragma warning disable CS0612
myWSTRING.LethargicWrite(plain.myWSTRING);
#pragma warning restore CS0612
return await this.WriteAsync<IgnoreOnPocoOperation>();
}

[Obsolete("This method should not be used if you indent to access the controllers data. Use `PlainToOnline` instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public async Task _PlainToOnlineNoacAsync(Pocos.class_all_primitives plain)
{
myBOOL.Cyclic = plain.myBOOL;
myBYTE.Cyclic = plain.myBYTE;
myWORD.Cyclic = plain.myWORD;
myDWORD.Cyclic = plain.myDWORD;
myLWORD.Cyclic = plain.myLWORD;
mySINT.Cyclic = plain.mySINT;
myINT.Cyclic = plain.myINT;
myDINT.Cyclic = plain.myDINT;
myLINT.Cyclic = plain.myLINT;
myUSINT.Cyclic = plain.myUSINT;
myUINT.Cyclic = plain.myUINT;
myUDINT.Cyclic = plain.myUDINT;
myULINT.Cyclic = plain.myULINT;
myREAL.Cyclic = plain.myREAL;
myLREAL.Cyclic = plain.myLREAL;
myTIME.Cyclic = plain.myTIME;
myLTIME.Cyclic = plain.myLTIME;
myDATE.Cyclic = plain.myDATE;
myTIME_OF_DAY.Cyclic = plain.myTIME_OF_DAY;
myDATE_AND_TIME.Cyclic = plain.myDATE_AND_TIME;
mySTRING.Cyclic = plain.mySTRING;
myWSTRING.Cyclic = plain.myWSTRING;
#pragma warning disable CS0612
myBOOL.LethargicWrite(plain.myBOOL);
#pragma warning restore CS0612
#pragma warning disable CS0612
myBYTE.LethargicWrite(plain.myBYTE);
#pragma warning restore CS0612
#pragma warning disable CS0612
myWORD.LethargicWrite(plain.myWORD);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDWORD.LethargicWrite(plain.myDWORD);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLWORD.LethargicWrite(plain.myLWORD);
#pragma warning restore CS0612
#pragma warning disable CS0612
mySINT.LethargicWrite(plain.mySINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myINT.LethargicWrite(plain.myINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDINT.LethargicWrite(plain.myDINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLINT.LethargicWrite(plain.myLINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myUSINT.LethargicWrite(plain.myUSINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myUINT.LethargicWrite(plain.myUINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myUDINT.LethargicWrite(plain.myUDINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myULINT.LethargicWrite(plain.myULINT);
#pragma warning restore CS0612
#pragma warning disable CS0612
myREAL.LethargicWrite(plain.myREAL);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLREAL.LethargicWrite(plain.myLREAL);
#pragma warning restore CS0612
#pragma warning disable CS0612
myTIME.LethargicWrite(plain.myTIME);
#pragma warning restore CS0612
#pragma warning disable CS0612
myLTIME.LethargicWrite(plain.myLTIME);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDATE.LethargicWrite(plain.myDATE);
#pragma warning restore CS0612
#pragma warning disable CS0612
myTIME_OF_DAY.LethargicWrite(plain.myTIME_OF_DAY);
#pragma warning restore CS0612
#pragma warning disable CS0612
myDATE_AND_TIME.LethargicWrite(plain.myDATE_AND_TIME);
#pragma warning restore CS0612
#pragma warning disable CS0612
mySTRING.LethargicWrite(plain.mySTRING);
#pragma warning restore CS0612
#pragma warning disable CS0612
myWSTRING.LethargicWrite(plain.myWSTRING);
#pragma warning restore CS0612
}

public async virtual Task<T> ShadowToPlain<T>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,25 @@ public async virtual Task PlainToOnline<T>(T plain)

public async Task<IEnumerable<ITwinPrimitive>> PlainToOnlineAsync(Pocos.Simatic.Ax.StateFramework.AbstractState plain)
{
StateID.Cyclic = plain.StateID;
StateName.Cyclic = plain.StateName;
#pragma warning disable CS0612
StateID.LethargicWrite(plain.StateID);
#pragma warning restore CS0612
#pragma warning disable CS0612
StateName.LethargicWrite(plain.StateName);
#pragma warning restore CS0612
return await this.WriteAsync<IgnoreOnPocoOperation>();
}

[Obsolete("This method should not be used if you indent to access the controllers data. Use `PlainToOnline` instead.")]
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public async Task _PlainToOnlineNoacAsync(Pocos.Simatic.Ax.StateFramework.AbstractState plain)
{
StateID.Cyclic = plain.StateID;
StateName.Cyclic = plain.StateName;
#pragma warning disable CS0612
StateID.LethargicWrite(plain.StateID);
#pragma warning restore CS0612
#pragma warning disable CS0612
StateName.LethargicWrite(plain.StateName);
#pragma warning restore CS0612
}

public async virtual Task<T> ShadowToPlain<T>()
Expand Down
Loading

0 comments on commit 6bcb0fa

Please sign in to comment.