Menu

Moka7 Multivar - Byte - FillByte

2014-10-04
2014-10-05
  • Martin Hinrichs

    Martin Hinrichs - 2014-10-04

    Hi,

    I am integrate the multivar Function in Moka7 and i am testing now.
    Now i found a problem where dont find a solution.

    Datatypes with 2bytes or 4bytes are running good.
    But if try to read/write a byte wrapped in a Telegramm with multiple items. The protocol fills up the data-parameter with 1 byte. o_O

    This picture show my Problem.
    http://i60.tinypic.com/zsnjr.jpg

    Parameter: (Write Var)
    ..
    ..
    Item [3]: (DB101.DBX 10.0 BYTE 1)
    Variable specification: 0x12
    Length of following address specification: 10
    Syntax Id: S7ANY (0x10)
    Transport size: BYTE (2)
    Length: 1
    DB number: 101
    Area: Data blocks (DB) (0x84)
    Address: 0x000050
    ..
    ..
    Data
    ..
    ..
    Item [3]: (Reserved)
    Return code: Reserved (0x00)
    Transport size: BYTE/WORD/DWORD (0x04)
    Data length: 1 Bytes
    Data: 01
    Fill byte: 0x00 <<--

    So every follow item get in trouble with this filling byte.
    It seems there a minimum Size (2bytes) for the Data. But i cant believe.

     
  • Davide Nardella

    Davide Nardella - 2014-10-04

    "It seems there a minimum Size (2bytes) for the Data. But i cant believe"
    You are almost near ;)

    You have this problem for all odd amount of byte (non only for 1 byte).
    The protocol requires that every block (except for the last one) must contain an even number of bytes.
    So, if the amount is odd, you need to add a padding byte.

     
  • Martin Hinrichs

    Martin Hinrichs - 2014-10-04

    Thats a really good answer. So i can fix it.

    I thought i can use it to read/write booleans on Siemens Devices.

    I could set the transport size to "Bit".
    But there are some unknow fields for me like start-adress and the length which is in byte So i think the protocol reserved also 1 byte and i have the problem with even byte again.

    Have Snap7 a Solution to write a Single Bit?

     
  • Davide Nardella

    Davide Nardella - 2014-10-05

    Yes, you can read/write a single bit, it is transferred as 1 byte.
    Yes, the data amount must be even.

    You need to add a further input int param : the wordLength.

    Add these constant in do S7 class

    public static final int WLBit = 0x01;
    public static final int WLByte = 0x02;
    public static final int WLTimer = 0x1D;
    public static final int WLCounter = 0x1C;

    The WordLength must be copied in PDU[22].

    Then modify this:

            // Adjusts Start and word length
            if ((Area==S7.S7AreaCT) || (Area==S7.S7AreaTM))
            {
                Address = Start;
                Length = DataSize;
                if (Area==S7.S7AreaCT)
                    PDU[22]=S7WLCounter;
                else
                    PDU[22]=S7WLTimer;
            }
            else
            {
                Address = Start<<3;
                Length  = DataSize<<3;
            }
    

    to:

            PDU[22]=WordLength;
            // Adjusts Start and word length
            if ((WordLength==S7.WLBit) || (WordLength==S7.WlTimer) || (WordLength==S7.WlCounter))
            {
                Address = Start;
                Length = DataSize;
            }
            else
            {
                Address = Start<<3;
                Length = DataSize<<3;
            }
    

    These are untested.

    For address calc refer to my email of (20/9/2014), I already explained you.

    For other infos about fields, please refer to C++ sources (s7_types.h)

     

Log in to post a comment.