西門子S7-300 PLC與模擬屏串行通信
4.2 數(shù)據(jù)發(fā)送
(1) 將同步字及測量值db36.dbw21開始的數(shù)據(jù)送到db42.dbw12開始的數(shù)據(jù)區(qū)去,為向串口發(fā)送做準(zhǔn)備。程序如下:
遙測第一幀(fc36)
l w#16#eb90
傳送兩次同步字eb90,分別給db42.dbw12和db42.dbw14
t db42.dbw12
l w#16#eb90
t db42.dbw14
l b#16#61
//將報(bào)文類型字“61”送給db42.dbb16
t db42.dbb16
l w#16#100
//第一幀將起始地址“0100”送給db42.dbw17
t db42.dbw17
//第二幀將起始地址“0120”送給db42.dbw17
l w#16#40
//將正文字節(jié)數(shù)“40”(64字節(jié))送給db42.dbw19
t db42.dbw19
l db36.dbw21
//第一幀將db36.dbw21開始的32個(gè)字的模擬量
caw 送到db42.dbw21開始的區(qū)域
t db42.dbw21
l db36.dbw23
caw
t db42.dbw23
…………………
l db36.dbw83
caw
t db42.dbw83
opn db42 //遙信校驗(yàn)
l p#17.0 //第二幀與第一幀相同
t md100
l dbw[md100]
t mw10
l 33
t mw16
l mw16
next: t mw12
l md100
l p#2.0
+d
t md100
l dbw[md100]
l mw10
xow
t mw10
l mw12
loop next
l md100
l p#2.0
+d
t md100
l mw10
t mw14
l mw14
slw 8
t dbw[md100]
l mw10
aw w#16#ff00
t mw10
l mw10
l dbw[md100]
xow
t dbw[md100]
l dbw16
t mw18
l mw18
aw w#16#ff00
t mw18
l mw18
l dbw[md100]
xow
t dbw[md100]
?。?) 將db42.dbw12開始,長度為95個(gè)字的數(shù)據(jù)送到串行端口,程序如下:
//supply laddr, db_no,dbb_no,len
l 256 // laddr
t db40.dbw2
l 42 // db_no
t db40.dbw4
t db42.dbw4
l 12 // dbb_no
t db40.dbw6
t db42.dbw6
l 95 // len
t db40.dbw8
t db42.dbw8
//send with instance-db
call fb8 , db21
sf :=’s’
req :=db40.dbx0.0
r :=db40.dbx0.1
laddr :=db40.dbw2
db_no :=db40.dbw4
dbb_no :=db40.dbw6
len :=db40.dbw8
r_cpu_no:=
r_typ :=
r_no :=
r_offset :=
r_cf_byt :=
r_cf_bit :=
done :=db40.dbx0.4
error :=db40.dbx0.5
status :=db40.dbw12
// generate edge p_snd_rk_req
an db40.dbx0.0 // p_snd_rk_req
s db40.dbx0.0
// set p_snd_rk_req
o db40.dbx0.4 // p_snd_rk_done
o db40.dbx0.5 // p_snd_rk_error
r db40.dbx0.0 // p_snd_rk_req
// check “complete without error”
an db40.dbx0.4
// check p_snd_rk_done if p_snd_rk_done equals 0,
jc cher
// jump to cher and check p_snd_rk_error
//”complete without error”
// p_snd_rk_done=1
l db42.dbw0
//“complete without error”
+1 // increment counter
t db42.dbw0
nop //further user function
nop
nop
be
// check “complete with error”
// p_snd_rk_error=1
cher: an db40.dbx0.5
//check p_snd_rk_error
bec //if no error occurred, jump to end
//“complete with error”
l db42.dbw2
//“complete with error”
+1 //increment counter
t db42.dbw2
l db40.dbw12
t db40.dbw14 //save status
nop //error-handling
nop
nop
be
?。?) 數(shù)據(jù)刷新,程序如下:
an m2.4
l s5t#100ms
sd t0
a t0
jnb _007
l w#16#1
l md4
rrd
t md4
set
save
clr
_007: a br
= l20.0
a l20.0
a(
l md4
l l#0
==d
?。?P> jnb _008
l 1
t md4
_008: nop 0
a l20.0
bld 102
= m2.4
a(
o m5.0
o m6.4
)
jnb _003
call fc36
_003: nop 0
a(
o m4.0
o m5.4
?。?P> jnb _004
call fc38
_004: nop 0
評論