Menu

Reading memory bits in an S7-300?

Help
2006-08-30
2013-05-09
  • Nobody/Anonymous

    Is it possible to read from the memory "M" table in an S7-300?  DB's are all well and good for larger projects, but we have some PLC programs that others have coded that do most of their interfacing using M "bits."

    I could not find any way in which I could access these.

     
    • Nobody/Anonymous

      1.It is posible to use daveReadBits on all memory areas.
      2.daveReadBits reads one single bit at a time. Hence it is very ineficient.
      If you want to know the state of single bits, read the byte which contains them and do something like:
      boolean myBitIsSet=(readByte & mask);
      where mask is a number that has a single bit set like 8 for bit x.3 or 64 for bit x.6.
      Why is daveReadBits there? Because the Siemens protocol supports it. Ask them what it is good for :-(
      Please also read the notes about speed and efficiency coming with libnodave. If you want the states of M6.5 and M45.3, it is best to read all bytes from MB6 to MB45 with a single call to daveReadBytes and extract the states from the 1st and the 39th byte of the buffer.
      Another thing is writing bits. If neighboured bits are used in the PLC program in write mode (i.e. there state is written by R, S or = operators) then daveWriteBits is the only way to change them   
      without affecting adjacent bits.
      However, if you can modify the PLC program, and if you have a lot of bits to set, instead of writing to M6.5 and M45.3 using daveWriteBits, consider writing these bits to an unused byte, e.g. MB127 and then do
      A M127.0
      = M6.5
      A M127.1
      = M45.3
      within the PLC program. This would allow to determine the state of 8*<max_byte_length> bits with a single with a single call to daveWriteBytes, where max_byte_length is e.g. 218 for 300/400 family and MPI-adapter. Other methods of transport may have higher limits.

      Thomas

       

Anonymous
Anonymous

Add attachments
Cancel