大家好,最近我做了一个S7200与32台威胜电表通信的程序,可以与地址1至8号表通信,到第9台时怎么也通信不上,查看通信协议也不知是什么原因,第9台不知是发送命令有错还是9号表无响应,请大家帮看看,谢谢
ORGANIZATION_BLOCK 主程序:OB1
TITLE=程序注释
BEGIN
Network 1
// 通信参数(01001001):
Network 2
LD SM0.1
CALL SBR1
Network 3
LD SM0.7
ED
CALL SBR0
Network 4
LD SM0.1
MOVB 0, VB120
Network 5
LD SM0.0
TON T40, 50
A T40
EU
S M5.0, 1
Network 6
LD M5.0
LPS
TON T41, 10
A T41
R M5.0, 1
LPP
MOVB 1, VB120
Network 7
LDB<> SMB86, 16#0
EU
INCB VB120
Network 8
// P263页,中断程序用法
LD SM0.0
LPS
AB= VB120, 1
= M0.0
LRD
AB= VB120, 2
TON T44, 20
A T44
= M0.1
LRD
AB= VB120, 3
TON T45, 20
A T45
= M0.2
LRD
AB= VB120, 4
TON T46, 20
A T46
= M0.3
LRD
AB= VB120, 5
TON T47, 20
A T47
= M0.4
LRD
AB= VB120, 6
TON T48, 20
A T48
= M0.5
LRD
AB= VB120, 7
TON T49, 20
A T49
= M0.6
LPP
AB= VB120, 8
TON T50, 3
A T50
= M0.7
Network 9
LD SM0.0
LPS
AB= VB120, 9
TON T51, 20
A T51
= M1.0
LRD
AB= VB120, 10
TON T51, 20
A T51
= M1.1
LRD
AB= VB120, 11
TON T52, 20
A T52
= M1.2
LRD
AB= VB120, 12
TON T53, 20
A T53
= M1.3
LRD
AB= VB120, 13
TON T54, 20
A T54
= M1.4
LRD
AB= VB120, 14
TON T55, 20
A T55
= M1.5
LRD
AB= VB120, 15
TON T56, 20
A T56
= M1.6
LRD
AB= VB120, 16
TON T57, 20
A T57
= M1.7
LPP
AB= VB120, 17
TON T58, 20
A T58
= M2.0
Network 10
LD SM0.0
LPS
AB= VB120, 18
TON T59, 20
A T59
= M2.1
LRD
AB= VB120, 19
TON T60, 20
A T60
= M2.2
LRD
AB= VB120, 20
TON T61, 20
A T61
= M2.3
LRD
AB= VB120, 21
TON T62, 20
A T62
= M2.4
LRD
AB= VB120, 22
TON T63, 20
A T63
= M2.5
LRD
AB= VB120, 23
TON T101, 20
A T101
= M2.6
LRD
AB= VB120, 24
TON T102, 20
A T102
= M2.7
LPP
AB= VB120, 25
TON T103, 20
A T103
= M3.0
Network 11
LD SM0.0
LPS
AB= VB120, 26
TON T104, 20
A T104
= M3.1
LRD
AB= VB120, 27
TON T105, 20
A T105
= M3.2
LRD
AB= VB120, 28
TON T106, 20
A T106
= M3.3
LRD
AB= VB120, 29
TON T107, 30
A T107
= M3.4
LRD
AB= VB120, 30
TON T108, 30
A T108
= M3.5
LRD
AB= VB120, 31
TON T109, 30
A T109
= M3.6
LPP
AB= VB120, 32
TON T110, 30
A T110
= M3.7
Network 12
// 数据域9010,按照从低至高字节发送,发送方按照加33H处理,
// (90)16=(144)10;(33)16=(51)10; 则(144+51)=(195)10=(C3)16;
LDB= VB120, 32
TON T37, 30
A T37
MOVB 1, VB120
Network 13
LD M0.0
EU
CALL SBR3, 1, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 14
LD M0.1
EU
CALL SBR3, 2, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 15
LD M0.2
EU
CALL SBR3, 3, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 16
// 4号表读电量
LD M0.3
EU
CALL SBR3, 4, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 17
// 5
LD M0.4
EU
CALL SBR3, 5, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 18
// 6
LD M0.5
EU
CALL SBR3, 6, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 19
// 7
LD M0.6
EU
CALL SBR3, 7, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 20
// 8
LD M0.7
EU
CALL SBR3, 8, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 21
// 9
LD M1.0
EU
CALL SBR3, 9, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 22
// 10
LD M1.1
EU
CALL SBR3, 10, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 23
// 11
LD M1.2
EU
CALL SBR3, 11, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 24
// 12
LD M1.3
EU
CALL SBR3, 12, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 25
// 13
LD M1.4
EU
CALL SBR3, 13, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 26
// 14
LD M1.5
EU
CALL SBR3, 14, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 27
// 15
LD M1.6
EU
CALL SBR3, 15, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 28
// 16
LD M1.7
EU
CALL SBR3, 16, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 29
// 17
LD M2.0
EU
CALL SBR3, 17, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 30
// 18
LD M2.1
EU
CALL SBR3, 18, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 31
// 19
LD M2.2
EU
CALL SBR3, 19, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 32
// 20
LD M2.3
EU
CALL SBR3, 20, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 33
// 21
LD M2.4
EU
CALL SBR3, 21, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 34
// 22
LD M2.5
EU
CALL SBR3, 22, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 35
// 23
LD M2.6
EU
CALL SBR3, 23, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 36
// 24
LD M2.7
EU
CALL SBR3, 24, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 37
// 25
LD M3.0
EU
CALL SBR3, 25, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 38
// 26
LD M3.1
EU
CALL SBR3, 26, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 39
// 27
LD M3.2
EU
CALL SBR3, 27, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 40
// 28
LD M3.3
EU
CALL SBR3, 28, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 41
// 29
LD M3.4
EU
CALL SBR3, 29, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 42
// 30
LD M3.5
EU
CALL SBR3, 30, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 43
// 31
LD M3.6
EU
CALL SBR3, 31, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 44
// 32
LD M3.7
EU
CALL SBR3, 32, 0, 0, 0, 0, 0, VB350
XMT VB100, 0
Network 45
LD SM0.0
LPS
AD<> VD480, 0
S Q0.0, 1
LRD
AD<> VD580, 0
S Q0.1, 1
LRD
AD<> VD680, 0
S Q0.2, 1
LRD
AD<> VD780, 0
S Q0.3, 1
LRD
AD<> VD880, 0
S Q0.4, 1
LPP
AD<> VD3480, 0
S Q0.5, 1
Network 46
LD SM0.0
LPS
AB>= VB120, 9
S Q0.6, 1
LRD
AB>= VB120, 4
S Q0.7, 1
LRD
AB>= VB120, 5
S Q1.0, 1
LRD
AB>= VB120, 32
S Q1.1, 1
LPP
MOVB VB120, VB304
END_ORGANIZATION_BLOCK
SUBROUTINE_BLOCK 通信模式转换:SBR0
TITLE=子程序注释
BEGIN
Network 1 // 端口0为PPI从站
// 16#08=(00001000)2
LD SM0.0
MOVB 16#08, SMB30
Network 2
Network 3
Network 4
Network 5
Network 6
Network 7
Network 8
Network 9
Network 10 // 网络标题
// 网络注释
Network 11
Network 12
Network 13
Network 14
Network 15
Network 16
Network 17
Network 18
Network 19
Network 20 // 网络标题
// 网络注释
Network 21
Network 22
Network 23
Network 24
Network 25
Network 26
Network 27
Network 28
Network 29
Network 30 // 网络标题
// 网络注释
END_SUBROUTINE_BLOCK
SUBROUTINE_BLOCK 通信参数:SBR1
TITLE=
BEGIN
Network 1
// 定义通信参数:
LD SM0.0
MOVB 16#49, SMB30
MOVB 16#E0, SMB87
MOVB 16#68, SMB88
MOVB 16#16, SMB89
MOVB 255, SMB94
Network 2
// 发送完成中断
LD SM0.0
ATCH INT0, 9
ENI
Network 3
// 数据项9010;(10)16加上33H为43H;90H加上33H为C3H;(90)16=(144)10+(51)10=(195)10=C3H
LD SM0.0
MOVB 16#12, VB100
MOVB 16#FE, VB101
MOVB 16#FE, VB102
MOVB 16#FE, VB103
MOVB 16#FE, VB104
MOVB 16#68, VB105
MOVB 16#68, VB112
MOVB 1, VB113
MOVB 2, VB114
MOVB 16#43, VB115
MOVB 16#C3, VB116
MOVB 16#16, VB118
END_SUBROUTINE_BLOCK
SUBROUTINE_BLOCK 电量运算:SBR2
TITLE=程序注释
VAR_INPUT
接收首字节:BYTE;
接收字节2:BYTE;
接收字节3:BYTE;
接收尾字节:BYTE;
END_VAR
VAR_IN_OUT
temp1:DWORD;
temp2:DWORD;
temp3:DWORD;
temp4:DWORD;
END_VAR
VAR_OUTPUT
节收输出1:BYTE;
实际电量:REAL;
END_VAR
BEGIN
Network 1
LD SM0.0
BMB LB0, LB20, 6
Network 2
// 00电量的万位和十万位转换为双整数
LD SM0.0
BTI LB3, LW30
AENO
MOVW LW30, LW32
AENO
-I 16#33, LW32
AENO
MOVW LW32, LW34
AENO
BCDI LW34
AENO
ITD LW34, LD36
AENO
MOVD LD36, LD16
*D +1000000, LD16
Network 3
// 68;电量的百位和千位转换为双整数
LD SM0.0
BTI LB2, LW40
AENO
MOVW LW40, LW42
AENO
-I 16#33, LW42
AENO
MOVW LW42, LW44
AENO
BCDI LW44
AENO
ITD LW44, LD46
AENO
MOVD +10000, LD12
*D LD46, LD12
Network 4
// 47;电量的个位和十位转换为双整数;
LD SM0.0
BTI LB1, LW50
AENO
MOVW LW50, LW52
AENO
-I 16#33, LW52
AENO
MOVW LW52, LW54
AENO
BCDI LW54
AENO
ITD LW54, LD56
AENO
MOVD +100, LD8
*D LD56, LD8
Network 5
// 49;所有数据先传送低位字节,因此VB513为电量最低位;
LD SM0.0
BTI LB0, AC0
AENO
-I 16#33, AC0
AENO
BCDI AC0
AENO
ITD AC0, LD4
Network 6
// 读出的有功总功率为:6847.49KW/h;存在VD1032中
LD SM0.0
MOVD LD16, AC1
AENO
+D LD12, AC1
AENO
+D LD8, AC1
AENO
+D LD4, AC1
AENO
DTR AC1, AC1
AENO
MOVR AC1, LD21
/R 100.0, LD21
Network 7
Network 8
Network 9
Network 10
Network 11
Network 12
Network 13
Network 14
Network 15
Network 16
Network 17
Network 18
Network 19
Network 20
Network 21
Network 22
Network 23 // 网络标题
// 网络注释
END_SUBROUTINE_BLOCK
SUBROUTINE_BLOCK 读电量:SBR3
TITLE=子程序注释
VAR_INPUT
地址1:BYTE;
地址2:BYTE;
地址3:BYTE;
地址4:BYTE;
地址5:BYTE;
地址6:BYTE;
END_VAR
VAR_OUTPUT
运算校验码:BYTE;
END_VAR
BEGIN
Network 1 // 网络标题
// 网络注释
LD SM0.0
BTI VB105, VW200
AENO
BTI VB112, VW202
AENO
BTI VB113, VW204
AENO
BTI VB114, VW206
AENO
BTI VB115, VW208
AENO
BTI VB116, VW210
Network 2
LD SM0.0
MOVB LB0, VB106
AENO
MOVB LB1, VB107
AENO
MOVB LB2, VB108
AENO
MOVB LB3, VB109
AENO
MOVB LB4, VB110
AENO
MOVB LB5, VB111
Network 3
LD SM0.0
BTI VB106, VW212
AENO
BTI VB107, VW214
AENO
BTI VB108, VW216
AENO
BTI VB109, VW218
AENO
BTI VB110, VW220
AENO
BTI VB111, VW222
Network 4
LD SM0.0
MOVW VW200, AC2
AENO
+I VW202, AC2
AENO
+I VW204, AC2
AENO
+I VW206, AC2
AENO
+I VW208, AC2
AENO
+I VW210, AC2
AENO
+I VW212, AC2
AENO
+I VW214, AC2
AENO
+I VW216, AC2
Network 5
LD SM0.0
+I VW218, AC2
AENO
+I VW220, AC2
AENO
MOVW AC2, VW224
AENO
+I VW222, VW224
AENO
MOVW VW224, VW226
-I 16#0, VW226
Network 6
LD SM0.0
HTA VB227, VB300, 2
AENO
ATH VB300, VB117, 2
AENO
ATH VB300, LB6, 2
END_SUBROUTINE_BLOCK
INTERRUPT_BLOCK INT_0:INT0
TITLE=接收完数据后转移数据,并启动下次发送
BEGIN
Network 1
// VB500:定义接收字符数;
// 校验码计算为VB501至VB516所有字节转换为十进制数后和;取十六进制的后两位;
// CS=(104+1+0+0+0+0+0+104+129+6+67+195+124+122+155+51)=(1058)10=(422)16;取后两位为22;
LD M0.0
RCV VB400, 0
AENO
CALL SBR2, VB413, VB414, VB415, VB416, VD440, VD444, VD448, VD452, VB470, VD460
Network 2
// 2
LD M0.1
RCV VB500, 0
AENO
CALL SBR2, VB513, VB514, VB515, VB516, VD540, VD544, VD548, VD552, VB570, VD560
Network 3
// 3
LD M0.2
RCV VB600, 0
AENO
CALL SBR2, VB613, VB614, VB615, VB616, VD640, VD644, VD648, VD652, VB670, VD660
Network 4
// 4
LD M0.3
RCV VB700, 0
AENO
CALL SBR2, VB713, VB714, VB715, VB716, VD740, VD744, VD748, VD752, VB770, VD760
Network 5
// 5
LD M0.4
RCV VB800, 0
AENO
CALL SBR2, VB813, VB814, VB815, VB816, VD840, VD844, VD848, VD852, VB870, VD860
Network 6
// 6
LD M0.5
RCV VB900, 0
AENO
CALL SBR2, VB913, VB914, VB915, VB916, VD940, VD944, VD948, VD952, VB970, VD960
Network 7
// 7
LD M0.6
RCV VB1000, 0
AENO
CALL SBR2, VB1013, VB1014, VB1015, VB1016, VD1040, VD1044, VD1048, VD1052, VB1070, VD1060
Network 8
// 8
LD M0.7
RCV VB1100, 0
AENO
CALL SBR2, VB1113, VB1114, VB1115, VB1116, VD1140, VD1144, VD1148, VD1152, VB1170, VD1160
Network 9
// 9
LD M1.0
RCV VB1200, 0
AENO
CALL SBR2, VB1213, VB1214, VB1215, VB1216, VD1240, VD1244, VD1248, VD1252, VB1270, VD1260
Network 10
// 10
LD M1.1
RCV VB1300, 0
AENO
CALL SBR2, VB1313, VB1314, VB1315, VB1316, VD1340, VD1344, VD1348, VD1352, VB1370, VD1360
Network 11
// 11
LD M1.2
RCV VB1400, 0
AENO
CALL SBR2, VB1413, VB1414, VB1415, VB1416, VD1440, VD1444, VD1448, VD1452, VB1470, VD1460
Network 12
// 12
LD M1.3
RCV VB1500, 0
AENO
CALL SBR2, VB1513, VB1514, VB1515, VB1516, VD1540, VD1544, VD1548, VD1552, VB1570, VD1560
Network 13
// 13
LD M1.4
RCV VB1600, 0
AENO
CALL SBR2, VB1613, VB1614, VB1615, VB1616, VD1640, VD1644, VD1648, VD1652, VB1670, VD1660
Network 14
// 14
LD M1.5
RCV VB1700, 0
AENO
CALL SBR2, VB1713, VB1714, VB1715, VB1716, VD1740, VD1744, VD1748, VD1752, VB1770, VD1760
Network 15 // 网络标题
// 15
LD M1.6
RCV VB1800, 0
AENO
CALL SBR2, VB1813, VB1814, VB1815, VB1816, VD1840, VD1844, VD1848, VD1852, VB1870, VD1860
Network 16
// 16
LD M1.7
RCV VB1900, 0
AENO
CALL SBR2, VB1913, VB1914, VB1915, VB1916, VD1940, VD1944, VD1948, VD1952, VB1970, VD1960
Network 17
// 17
LD M2.0
RCV VB2000, 0
AENO
CALL SBR2, VB2013, VB2014, VB2015, VB2016, VD2040, VD2044, VD2048, VD2052, VB2070, VD2060
Network 18
// 18
LD M2.1
RCV VB2100, 0
AENO
CALL SBR2, VB2113, VB2114, VB2115, VB2116, VD2140, VD2144, VD2148, VD2152, VB2170, VD2160
Network 19
// 19
LD M2.2
RCV VB2200, 0
AENO
CALL SBR2, VB2213, VB2214, VB2215, VB2216, VD2240, VD2244, VD2248, VD2252, VB2270, VD2260
Network 20
// 20
LD M2.3
RCV VB2300, 0
AENO
CALL SBR2, VB2313, VB2314, VB2315, VB2316, VD2340, VD2344, VD2348, VD2352, VB2370, VD2360
Network 21
// 21
LD M2.4
RCV VB2400, 0
AENO
CALL SBR2, VB2413, VB2414, VB2415, VB2416, VD2440, VD2444, VD2448, VD2452, VB2470, VD2460
Network 22
// 22
LD M2.5
RCV VB2500, 0
AENO
CALL SBR2, VB2513, VB2514, VB2515, VB2516, VD2540, VD2544, VD2548, VD2552, VB2570, VD2560
Network 23
// 23
LD M2.6
RCV VB2600, 0
AENO
CALL SBR2, VB2613, VB2614, VB2615, VB2616, VD2640, VD2644, VD2648, VD2652, VB2670, VD2660
Network 24
// 24
LD M2.7
RCV VB2700, 0
AENO
CALL SBR2, VB2713, VB2714, VB2715, VB2716, VD2740, VD2744, VD2748, VD2752, VB2770, VD2760
Network 25
// 25
LD M3.0
RCV VB2800, 0
AENO
CALL SBR2, VB2813, VB2814, VB2815, VB2816, VD2840, VD2844, VD2848, VD2852, VB2870, VD2860
Network 26
// 26
LD M3.1
RCV VB2900, 0
AENO
CALL SBR2, VB2913, VB2914, VB2915, VB2916, VD2940, VD2944, VD2948, VD2952, VB2970, VD2960
Network 27
// 27
LD M3.2
RCV VB3000, 0
AENO
CALL SBR2, VB3013, VB3014, VB3015, VB3016, VD3040, VD3044, VD3048, VD3052, VB3070, VD3060
Network 28
// 28
LD M3.3
RCV VB3100, 0
AENO
CALL SBR2, VB3113, VB3114, VB3115, VB3116, VD3140, VD3144, VD3148, VD3152, VB3170, VD3160
Network 29
// 29
LD M3.4
RCV VB3200, 0
AENO
CALL SBR2, VB3213, VB3214, VB3215, VB3216, VD3240, VD3244, VD3248, VD3252, VB3270, VD3260
Network 30
// 30
LD M3.5
RCV VB3300, 0
AENO
CALL SBR2, VB3313, VB3314, VB3315, VB3316, VD3340, VD3344, VD3348, VD3352, VB3370, VD3360
Network 31
// 31
LD M3.6
RCV VB3300, 0
AENO
CALL SBR2, VB3313, VB3314, VB3315, VB3316, VD3340, VD3344, VD3348, VD3352, VB3370, VD3360
Network 32
// 32
LD M3.7
RCV VB3400, 0
AENO
CALL SBR2, VB3413, VB3414, VB3415, VB3416, VD3440, VD3444, VD3448, VD3452, VB3470, VD3460
Network 33
LD SM0.0
MOVD VD460, VD480
MOVD VD560, VD580
MOVD VD660, VD680
MOVD VD760, VD780
MOVD VD860, VD880
MOVD VD960, VD980
MOVD VD1060, VD1080
MOVD VD1160, VD1180
MOVD VD1260, VD1280
MOVD VD1360, VD1380
MOVD VD1460, VD1480
MOVD VD1560, VD1580
MOVD VD1660, VD1680
MOVD VD1760, VD1780
MOVD VD1860, VD1880
MOVD VD1960, VD1980
MOVD VD2060, VD2080
MOVD VD2160, VD2180
MOVD VD2260, VD2280
MOVD VD2360, VD2380
MOVD VD2460, VD2480
MOVD VD2560, VD2580
MOVD VD2660, VD2680
MOVD VD2760, VD2780
MOVD VD2860, VD2880
MOVD VD2960, VD2980
MOVD VD3060, VD3080
MOVD VD3160, VD3180
MOVD VD3260, VD3280
MOVD VD3360, VD3380
MOVD VD3460, VD3480
Network 34
Network 35
Network 36
Network 37
Network 38
Network 39
Network 40 // 网络标题
// 网络注释
Network 41
Network 42
Network 43
Network 44
Network 45
Network 46
Network 47
Network 48
Network 49
Network 50 // 网络标题
// 网络注释
END_INTERRUPT_BLOCK
INTERRUPT_BLOCK INT_1:INT1
TITLE=
BEGIN
Network 1
END_INTERRUPT_BLOCK