Skip to content

Commit

Permalink
Add unsigned read
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Oct 19, 2023
1 parent a475127 commit 3733aa0
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.2.1",
"version": "1.2.2",
"publicReleaseRefSpec": [
"^refs/heads/master$",
"^refs/heads/main$"
Expand Down
71 changes: 71 additions & 0 deletions src/S7PlcRx/RxS7.cs
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,16 @@ private void GetTagValue(Tag? tag)
return Read<ushort[]>(tag, DataType.DataBlock, dB, dbIndex, VarType.Word);
}

if (tag.Type == typeof(short[]))
{
return Read<short[]>(tag, DataType.DataBlock, dB, dbIndex, VarType.Word);
}

if (tag.Type == typeof(short))
{
return Read<short>(tag, DataType.DataBlock, dB, dbIndex, VarType.Word);
}

return Read<ushort>(tag, DataType.DataBlock, dB, dbIndex, VarType.Word);

case "DBD":
Expand Down Expand Up @@ -873,6 +883,16 @@ private void GetTagValue(Tag? tag)
return Read<ushort[]>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

if (tag.Type == typeof(short[]))
{
return Read<short[]>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

if (tag.Type == typeof(short))
{
return Read<short>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

return Read<ushort>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);

case "ED":
Expand All @@ -883,6 +903,16 @@ private void GetTagValue(Tag? tag)
return Read<uint[]>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);
}

if (tag.Type == typeof(int[]))
{
return Read<int[]>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);
}

if (tag.Type == typeof(int))
{
return Read<int>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);
}

return Read<uint>(tag, DataType.Input, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);

case "AB":
Expand All @@ -903,6 +933,16 @@ private void GetTagValue(Tag? tag)
return Read<ushort[]>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

if (tag.Type == typeof(short[]))
{
return Read<short[]>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

if (tag.Type == typeof(short))
{
return Read<short>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

return Read<ushort>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);

case "AD":
Expand All @@ -913,6 +953,16 @@ private void GetTagValue(Tag? tag)
return Read<uint[]>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);
}

if (tag.Type == typeof(int[]))
{
return Read<int[]>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);
}

if (tag.Type == typeof(int))
{
return Read<int>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);
}

return Read<uint>(tag, DataType.Output, 0, int.Parse(correctVariable.Substring(2)), VarType.DWord);

case "MB":
Expand All @@ -933,6 +983,16 @@ private void GetTagValue(Tag? tag)
return Read<ushort[]>(tag, DataType.Memory, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

if (tag.Type == typeof(short[]))
{
return Read<short[]>(tag, DataType.Memory, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

if (tag.Type == typeof(short))
{
return Read<short>(tag, DataType.Memory, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);
}

return Read<ushort>(tag, DataType.Memory, 0, int.Parse(correctVariable.Substring(2)), VarType.Word);

case "MD":
Expand Down Expand Up @@ -987,6 +1047,16 @@ private void GetTagValue(Tag? tag)
return Read<ushort[]>(tag, DataType.Counter, 0, int.Parse(correctVariable.Substring(2)), VarType.Counter);
}

if (tag.Type == typeof(short[]))
{
return Read<short[]>(tag, DataType.Counter, 0, int.Parse(correctVariable.Substring(2)), VarType.Counter);
}

if (tag.Type == typeof(short))
{
return Read<short>(tag, DataType.Counter, 0, int.Parse(correctVariable.Substring(2)), VarType.Counter);
}

return Read<ushort>(tag, DataType.Counter, 0, int.Parse(correctVariable.Substring(1)), VarType.Counter);

default:
Expand Down Expand Up @@ -1206,6 +1276,7 @@ private bool Write(Tag tag, DataType dataType, int db, int startByteAdr, object?
byte[] package;
switch (tag.Type.Name)
{
// TODO: fix Bit
case "Byte":
package = new byte[] { (byte)(value ?? Convert.ChangeType(tag.NewValue, typeof(byte)))! };
break;
Expand Down

0 comments on commit 3733aa0

Please sign in to comment.