当前位置:网站首页>Botu uses peek and poke for IO mapping
Botu uses peek and poke for IO mapping
2022-07-03 05:05:00 【DoTheTran】
Berto S7120、SCL Language programming 、PEEK、POKE Instructions 、IO mapping
brief introduction
Sometimes we need to map a variable to IO On domain , For example, a size of 16 The array variable of corresponds to the output Q0.0 To Q1.7, If one by one assignment is too verbose , Now we can use SCL Linguistic PEEK、POKE Instructions , Perform index addressing mapping
This article refers to the Siemens Help Center website :
http://www.ad.siemens.com.cn/productportal/Prods/S7-1200_PLC_EASY_PLUS/07-Program/03-instruction/03-Address/03-PEEK_POKE.html
background
Take the parking lot project as an example , share 20 A parking space , Each parking space corresponds to a sensor and a red light . For the convenience of programming , Use them separately DB The size in the block is 20 The array variable of represents the parking space sensor and the red light . It is very convenient to assign values in the way of circular array at one time 20 Assignment of lamp States .
But the problem is , How to input and output variables in an array , The convenient and fast mapping is I Point and Q How about it? ?
SCL Language
First of all SCL Language , It can easily complete the work that requires many instructions in the ladder diagram , It's like C Language programming is generally , It mainly uses IF…THEN/FOR/WHILE Statement to construct condition 、 loop 、 Judge such a structure , Add instructions to these structures again , To realize logical judgment . All programs are written in a plain text environment , But not as intuitive as ladder diagram .
PEEK And POKE
Use S7-1200 ,SCL Programming language PEEK and POKE Instructions , Can realize the right I/O、M Read or write memory and data blocks .
Applicable conditions of the directive :
- Used only for SCL programing language ;
- Software from TIA PORTAL V11 SP2 rise ;
- S7-1200 CPU Firmware from V2.2 rise ;
- Applicable operands ,I、Q、M、DB;
- DB Must be a non optimized access block .
Because we are right about I spot 、Q Point addressing , So use PEEK_BOOL and POKE_BOOL Instructions .
PEEK_BOOL Instructions
PEEK_BOOL Instructions are used to read input (I)、 Output (Q)、 Memory (M) Or data block (DB) Bit of variable .PEEK The instruction assigns the obtained data value to the corresponding variable in the form of return value .
PEEK_BOOL Command format :
among , Parameters area, There are four values according to the area where the data is located .
| area value | type | explain |
|---|---|---|
| 16#81 | I | Input area variables |
| 16#82 | Q | Output area variables |
| 16#83 | M | M Zone variable |
| 16#84 | DB | Block variables |
POKE_BOOL Instructions
POKE _BOOL Instructions can be used to input (I)( Generally not used )、 Output (Q)、 Memory (M) Or data block (DB) Write the variable address .POKE The instruction can pass the result to the corresponding variable in the instruction body .
PEEK_BOOL Command format :
Parameters area The value of is the same as PEEK.
Start
First, create a new one FC block , Name it IO mapping , Language choice SCL
Open the new block , Pull out the block interface above , Create two new temporary variables . among i As a cyclic variable ,io_offset Become IO Offset of the starting address of the domain .
At the command → Basic instructions → Mobile operating → read / Write to memory , find PEEK_BOOL and POKE_BOOL Instructions , Double click for easy input .
stay FC Block, enter the following code
FOR #i := 0 TO 19 DO //I -> Input
#io_offset := #i + 8 * 2 + 0;// from I2.0 Start
" An array variable ". Parking space sensor [#i] :=
PEEK_BOOL(area := 16#81,//16#81 by I
dbNumber := 0,
byteOffset := #io_offset / 8,
bitOffset := #io_offset MOD 8);
END_FOR;
FOR #i := 0 TO 19 DO // Output -> Q
#io_offset := #i + 8 * 4 + 0;// from Q4.0 Start
POKE_BOOL(area := 16#82, //16#82 by Q
dbNumber := 0,
byteOffset := #io_offset / 8,
bitOffset := #io_offset MOD 8,
value := " An array variable ". Parking space red light [#i]);
END_FOR
ad locum
If the mapped address is a continuous storage space , This method can use FOR Loop assignment . It's easy to find the law , Array element subscripts from 0 Start adding one by one 1, If I/O Point is from 0.0 Start , The bit variable of the corresponding input address is from 0 To 7 And back and forth , The byte address is first 8 individual 0, And then there was 8 individual 1…… So the summary is that the byte address is subscript division 8 The business of , Bit addresses are subscript divisible 8 The remainder of , In programming language, byte address is subscript /8, Bit address is subscript MOD8. If the byte address is not from 0.0 Start , Add an offset at the beginning of the loop . Then we can use FOR Loop to quickly implement bit by bit assignment .
边栏推荐
- Market status and development prospects of the global automatic tea picker industry in 2022
- leetcode860. Lemonade change
- appium1.22.x 版本后的 appium inspector 需单独安装
- [backtrader source code analysis 4] use Python to rewrite the first function of backtrader: time2num, which improves the efficiency by 2.2 times
- Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
- 1115 counting nodes in a BST (30 points)
- Preparation for school and professional cognition
- Literature reading_ Research on the usefulness identification of tourism online comments based on semantic fusion of multimodal data (Chinese Literature)
- [PHP vulnerability weak type] basic knowledge, PHP weak equality, error reporting and bypassing
- Based on RFC 3986 (unified resource descriptor (URI): general syntax)
猜你喜欢

Gbase8s unique index and non unique index

Promise

Review the configuration of vscode to develop golang
![[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached](/img/95/833f5ec20207ee5d7e6cdfa7208c5e.jpg)
[research materials] 2021 annual report on mergers and acquisitions in the property management industry - Download attached

Actual combat 8051 drives 8-bit nixie tube

MPM model and ab pressure test
![[tools run SQL blind note]](/img/c3/86db4568b221d2423914990a88eec2.png)
[tools run SQL blind note]

Online VR model display - 3D visual display solution

2022-02-11 daily clock in: problem fine brush
![[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)](/img/34/d195752992f8955bc2a41b4ce751db.jpg)
[set theory] relationship properties (symmetry | symmetry examples | symmetry related theorems | antisymmetry | antisymmetry examples | antisymmetry theorems)
随机推荐
1111 online map (30 points)
First + only! Alibaba cloud's real-time computing version of Flink passed the stability test of big data products of the Institute of ICT
[SQL injection point] location and judgment of the injection point
Realize file download through the tag of < a > and customize the file name
Market status and development prospect prediction of the near infrared sensor industry of the global Internet of things in 2022
Wechat applet distance and map
论文阅读_中文NLP_ELECTRA
Mobile terminal - uniapp development record (public request encapsulation)
Current market situation and development prospect prediction of global direct energy deposition 3D printer industry in 2022
Market status and development prospects of the global IOT active infrared sensor industry in 2022
[research materials] annual report of China's pension market in 2021 - Download attached
Objects. Requirenonnull method description
50 practical applications of R language (36) - data visualization from basic to advanced
Use Sqlalchemy module to obtain the table name and field name of the existing table in the database
Use posture of sudo right raising vulnerability in actual combat (cve-2021-3156)
@RequestMapping
论文阅读_中文医疗模型_ eHealth
音频焦点系列:手写一个demo理解音频焦点与AudioMananger
Unity tool Luban learning notes 1
[backtrader source code analysis 5] rewrite several time number conversion functions in utils with Python