Closed marcosdvpereira closed 6 years ago
Can you post the code to reproduce the problem also ?
On Plc the vars are USInt type.
public Dictionary<uint, byte> GetOptions(ushort db, uint[] offsets)
{
var result = new Dictionary<uint, byte>();
var read = new List<S7.Net.Types.DataItem>();
foreach (var offset in offsets)
{
read.Add(new S7.Net.Types.DataItem()
{
Count = 1,
DataType = S7.Net.DataType.DataBlock,
DB = db,
StartByteAdr = (int)offset,
VarType = S7.Net.VarType.Byte
});
}
_cpu.Read(read);
foreach (var item in read)
result[(uint)item.StartByteAdr] = item.Value.ToByte();
return result;
}
I can't find USInt type on Step7 or on TIA Portal. Can you upload the plc program or just a small part of it that contains the db ?
This should return: 1, 2, 3, 4 but return: 1, 8, 0, 4.
I know this issue is very old, but for others searching, USint is 1 byte with a max value of 255. Therefore, your c# class/struct should actually be Byte
This is probably fixed by a recently merged pull request. At least reading single bytes works now.
Someone who tests this scenario just to be sure, and for me this issue can be closed.
I tested reading single bit / byte using ReadMultipleVars as mentioned in PR #117. I'd say close this, as the datatype in PLC doesn't seem to matter anyway.
Reading multiple USInt vars only the first one read ok. Adding the code bellow fix my problem, but not sure if it is the right solution.
PLC.ReadMultipleVars(List):