Skip to content

Error in batch reading of bit data using S7MultiVar #50

Description

@tzm2270969436

Data writing using S7MultiVar is successful.However, the use of S7MultiVar for batch data reading does not match the actual situation.

Sharp7

 //DB1.DBX0.0
 var tag1 = new S7Consts.S7Tag
 {
     Area = (int)S7Area.DB,
     DBNumber = 1,
     Start = 0, // 0 * 8 + 0
     Elements = 1,
     WordLen = 1
 };
 //DB1.DBX0.2
 var tag2 = new S7Consts.S7Tag
 {
     Area = (int)S7Area.DB,
     DBNumber = 1,
     Start = 2,// 0 * 8 + 2
     Elements = 1,
     WordLen = 1
 };

 var writeBuffer = new byte[2] { 1, 1 };
 var writeMultivar = new S7MultiVar(s7Client);
 writeMultivar.Add(tag1, ref writeBuffer);
 writeMultivar.Add(tag2, ref writeBuffer, 1);
 //Write Ok
 writeMultivar.Write();

 var readBuffer = new byte[2];
 var readMultivar = new S7MultiVar(s7Client);
 readMultivar.Add(tag1, ref readBuffer);
 readMultivar.Add(tag2, ref readBuffer, 1);
 //Read Error,readBuffer [1,0]
 readMultivar.Read();

Sharp7 Document

When WordLen=S7WLBit the Offset (Start) must be expressed in bits.
Ex. The Start for DB4.DBX 10.3 is (10*8)+3 = 83.


I attempted to modify the source code on line 1194 of the S7Client.cs file. After the modification, the bit reading was successful. However, I'm not sure if this will affect other data types.

Problem

The original code:

if (ItemSize % 2 != 0)

Solution

if (ItemSize % 2 != 0 && (S7ItemRead[1] != TS_ResBit))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions