S7NetPlus / s7netplus

S7.NET+ -- A .NET library to connect to Siemens Step7 devices
MIT License
1.33k stars 588 forks source link

Reading from address higher than 8096 #50

Closed Skokan44 closed 8 years ago

Skokan44 commented 8 years ago

Hi,

I am trying to read a data from a DB on S7-1200 station. I ran into problem and so far wasn't able to solve it. Apparently there is some problem, when I am reading data from position higher then 8096. Is it possible or am I doing something wrong?

ushort address = (ushort) (StackAdress + 2*RecPtr); var o = _plc.Read(DataType.DataBlock, DataBlockIndex,address, VarType.Int, RecSize);¨

Thanks, Martin.

mesta1 commented 8 years ago

Hi, are you using the NuGet version ? We updated the sources and solved the problem, but we still have to update NuGet. Try to download the latest sources and if you still have the problem, let me know.

Skokan44 commented 8 years ago

Yes I was using the NuGet version, now it is working just fine. Thank you for your work!

oiisamiio commented 8 years ago

var overflow = (int)(startByteAdr * 8 / 0xffffU); // handles words with address bigger than 8191

still results in invalid data if startByteAdr < 8191 + Count > 8191 and data overlap. So better let requests result in an error if startByteAdr < 8191 but + Count > 8191?

mesta1 commented 8 years ago

Please can you post the code to reproduce the issue?

oiisamiio commented 8 years ago

public ErrorCode Write(DataType dataType, int db, int startByteAdr, object value)

an example: if startByteAdr would be 8190 (DB1.DBD8190) and value length would be 4 bytes var overflow = (int)(startByteAdr * 8 / 0xffffU); // handles words with address bigger than 8191 var overflow would result in 0 address would overlap, request would overlap 0/1. Right?

Excuse my english

mesta1 commented 8 years ago

I'll test it asap.

oiisamiio commented 8 years ago

think we need something like this:

if ((startByteAdr*8/0xffffU) == 0)
{
   if ((startByteAdr*8/0xffffU) + varCount > 0)
   {
      throw new Exception(ErrorCode.WrongVarFormat.ToString());
   }
}
mesta1 commented 8 years ago

I don't think that throwing an error is a solution, but I still had no time to check this.

mesta1 commented 8 years ago

I did some tests today, but I couldn't reproduce the problem. This is the code that I tested, also on a S7-300 and Step7.

 [TestMethod]
 public void T11_WriteDbd8190()
 {
     ushort val = 16384;
     plc.Write("DB2.DBW8190", val);
     var result = plc.Read("DB2.DBW8190");
     Assert.AreEqual((ushort)16384, result);
 }

 [TestMethod]
 public void T12_WriteDbd8190()
 {
     int val2 = 32000;
     plc.Write("DB2.DBD8190", val2);
     var result2 =  plc.Read("DB2.DBD8190");
     Assert.AreEqual((uint)32000, result2);
 }
oiisamiio commented 8 years ago

Sorry, did also some tests. Looks fine, no issue

Please Close Issue, Thanks

mesta1 commented 8 years ago

No problem, thanks for your time.