S7-1200 SCL - read whole I/O port

Join Date
Jul 2013
Location
Here
Posts
31
Hi,

I only know how to read one bit of e.g. an input port, using e.g. I0.7 or names from the standard table for such a single IO line.

Is there some command to read all bits of an input or output port as a byte at once? E.g. the state of all bits in input module number 0, or 8, or 12, etc..

What I want to do is logging data, like all I/O states and statemachine states of a program due to a very rarely occuring error, to have a chance to see what lead to the problem.

So far what I've done is, using S7Connector.dll (the commercial one) to repeatedly poll all the I/O ports etc, but this is rather taxing on the little PLC & its ethernet facility, I don't get a very high update rate.

So instead I'd like to buffer a number of state changes inside the PLC before reading them over ethernet on the PC, not only reducing the overhead but also not missing any changes.
It's more efficient and insensitive to changes to just always read the whole ports as opposed to query all those individual IO lines...
 
looks like PEEK, using area designator 16#81 and 16#82 for input / output does this (not tried yet whether byteOffset:=8 will read input port 8)
 
Think it might be simpler than PEEK.

I0.0 to I0.3
IB0
I0.0 to I0.7
IW0

If you wanted to read I0.0 to I1.7 then ID0 should do it.

From the Manual:

Each different memory location has a unique address. Your user program uses these
addresses to access the information in the memory location. The absolute address consists
of the following elements:
● Memory area identifier (such as I, Q, or M)
● Size of the data to be accessed ("B' for Byte, "W" for Word, or "D" for DWord)
● Starting address of the data (such as byte 3 or word 3)
When accessing a bit in the address for a Boolean value, you do not enter a mnemonic for
the size. You enter only the memory area, the byte location, and the bit location for the data
(such as I0.0, Q0.1, or M3.4).
 
Ah! I've seen this before, not used on inputs, though. But forgot it either way.
Thanks :) That looks indeed a bit less wordsy than peek with unused parameters...
 
Think it might be simpler than PEEK.

I0.0 to I0.3
IB0
I0.0 to I0.7
IW0

If you wanted to read I0.0 to I1.7 then ID0 should do it.

From the Manual:

Each different memory location has a unique address. Your user program uses these
addresses to access the information in the memory location. The absolute address consists
of the following elements:
● Memory area identifier (such as I, Q, or M)
● Size of the data to be accessed ("B' for Byte, "W" for Word, or "D" for DWord)
● Starting address of the data (such as byte 3 or word 3)
When accessing a bit in the address for a Boolean value, you do not enter a mnemonic for
the size. You enter only the memory area, the byte location, and the bit location for the data
(such as I0.0, Q0.1, or M3.4).

I was trying to access the input buffer bit by bit and was able to access IB0 representing I0.0-I0.7
IB1 representing I1.0-I1.5 (probably to I1.7 but haven't tried)
But I had issues when trying to access the entire input buffer using IW0. An example "tmepWord".x1 would point to I1.1 and not I0.1 which was puzzling to me until I got help and I was given the attached file where IW0 is ordered I1.0-I1.7 for the first 8 bits and then I0.0-I0.7 for bits 9-15 which was backwards to what I was trying.

The question: Where can in Siemens manual online or otherwise can I find this information in detail?

Thanks
Kal

index1.png
 
I am only working with S7-1200 but that doesn't sound right. I am guessing that if you go in to PLC configuration and look at the memory addresses assigned to your input cards that you have crossed the starting addresses. So the first input module has a higher starting address than the second.
 
I was trying to access the input buffer bit by bit and was able to access IB0 representing I0.0-I0.7
IB1 representing I1.0-I1.5 (probably to I1.7 but haven't tried)
But I had issues when trying to access the entire input buffer using IW0. An example "tmepWord".x1 would point to I1.1 and not I0.1 which was puzzling to me until I got help and I was given the attached file where IW0 is ordered I1.0-I1.7 for the first 8 bits and then I0.0-I0.7 for bits 9-15 which was backwards to what I was trying.

The question: Where can in Siemens manual online or otherwise can I find this information in detail?

Thanks
Kal


As HJTRBO said, this is an Endianness issue, and that's just how the PLC processes the data. It never really made sense to me, but I know other programmers that swear it is way simpler this way.

The way that I've found is much simpler to read IO data than using slice based addressing (mytag.x1) is to apply a PLC Data Type to the IO. If, for example, I have a drive status word at IW10, I can create a custom data type with that exact structure, and then apply that data type to I10.0. S7 (in V13 SP1, at least) will then treat is as a structure, with all the names you've built in. Instead of having to remember that mytag.x0 is the running bit, mytag.x1 is the error bit, etc, you can access mytag.running and mytag.error directly.

Slice based addressing makes a lot of sense for alarm words and things like that, but for IO it doesn't add much. Using data types builds in a lot of documentation that otherwise might get forgotten.
 
Last edited:
I choked on this for a while during my first 1200 project. I ended up making an FC with just comments explaining some of the weird things I learned, in case I had to come back to it in the future.

Capture.GIF
 
Did they apply UDT for io to s7-1200? Last time i checked it was only for 1500.

The 1200 needs to be at FW4, but yes, it works the same as the 1500. You can use PLC data types for I/Q, but not M. Obviously, you can use them for DBs as well.

Its a big help for any IO that has a consistent data type or telegram, like drives. The only downside is that sometimes vendors often really try to pack the bits in, say having 1 byte of data divided into 3 status bits and a 5 bit "integer". Since there is no supported data type for 5 bit numbers, it doesn't smoothly translate into a structure, and you still have to do silly programming to get it all separated.
 
Thanks Gentlemen,
Big Endian, that explains it.

The issue came up with s7-1214c V3.0 communication between two CPUs as I was sending the input buffer from one cpu to the other and wanted to use only one connection to do that instead of using two connection to send B0 Byte 0 and Byte 1 separately. Then I was pointed to that WORD and dWORD arrangement that threw me off.
I spent hours reading and re-reading this link and nothing in it pointed to that arrangement of bytes.

Cheers
Kal
 

Similar Topics

Hello, I am currently forced to use s7-1200 (6ES7214-1AG40-0XB0) PLC for one small project. I do have some experience with S7-300/400 mostly in...
Replies
6
Views
5,039
Hi, I am new to Siemens and SCL. I have a datablock which is a global data block. I want to use some of the values in this DB in a FB block...
Replies
3
Views
3,523
Hey, is it possible to know, within a program, the number of the FB, or OB, the code is currently executed in? Like, some function...
Replies
2
Views
2,042
Hi Guys! I'm preparing a short training for some colleagues on how to use the S7-1200 CPU and while explaining the 3 different programming...
Replies
2
Views
3,428
Hi, im creating compressor station project with S7-1200. Project requires that 4 compressors should work in cascade - that's already done, and...
Replies
13
Views
11,527
Back
Top Bottom