码迷,mamicode.com
首页 > 其他好文 > 详细

[TIA PORTAL][CONVERT] Convert Char Array to DInt...DInt to Char Array..Useful and easy function

时间:2020-06-26 01:17:33      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:bsp   lan   temp   _for   com   port   blank   body   lower   

Function

"LCA_DI" Convert Char Array to DInt

"LDI_CA" Convert DInt to Char Array 

Example
Parameter

Input 

Output

InOut

Static

CA Array[0..9] of Char
DI UDInt
CA2 Array[1..10] of Char

Temp

Constant 

 Programming
 
#DI := "LCA_DI"(#CA);

"LDI_CA"(INUM := #DI,
         OCHR => #CA2);

 

 Result
 技术图片
 Library
 "LCA_DI" Convert Char Array to DInt
 Parameter

Input
ICHR Array[*] of Char
Output

InOut

Temp
TI Int
TMOD_NUM DInt
TTOL_NUM UDInt
TONE_NUM DInt
TUP_BOU Int
TLW_BOU Int
Constant

Return
LCA_DI UDInt

Programming
    #TTOL_NUM := 0;
    #TONE_NUM := 0;
    
    #TMOD_NUM := 1;
    
    #TUP_BOU := DINT_TO_INT(IN := UPPER_BOUND(ARR := #ICHR, DIM := 1));
    #TLW_BOU := DINT_TO_INT(IN := LOWER_BOUND(ARR := #ICHR, DIM := 1));
    
    FOR #TI := #TUP_BOU TO #TLW_BOU BY -1 DO
        #TONE_NUM := INT_TO_DINT(ABS(CHAR_TO_INT(#ICHR[#TI])) - 16#30);
        IF #TONE_NUM < 0 OR #TONE_NUM > 9 THEN
            #TONE_NUM := 0;
        END_IF;
        
        #TTOL_NUM := #TTOL_NUM + DINT_TO_UDINT(#TONE_NUM * #TMOD_NUM);
        #TMOD_NUM := #TMOD_NUM * 10;
    END_FOR;
    
    #LCA_DI := #TTOL_NUM;
    
"LDI_CA" Convert DInt to Char Array 
 Parameter

Input
INUM UDInt
Output
OCHR Array[*] of Char
InOut

Temp
TI Int
TCHR Char
TMOD Int
TMOD_NUM UDInt
TUP_BOU Int
TLW_BOU Int
Constant

Return
LDI_CA Void

Programming
    #TMOD := 0;
    #TMOD_NUM := 1;
    
    #TUP_BOU := DINT_TO_INT(IN := UPPER_BOUND(ARR := #OCHR, DIM := 1));
    #TLW_BOU := DINT_TO_INT(IN := LOWER_BOUND(ARR := #OCHR, DIM := 1));
    
    FOR #TI := #TUP_BOU TO #TLW_BOU BY -1 DO
        #TMOD := UDINT_TO_INT((#INUM / #TMOD_NUM) MOD 10);
        #OCHR[#TI] := INT_TO_CHAR(ABS(#TMOD) + 16#30);
        
        #TMOD_NUM := #TMOD_NUM * 10;
    END_FOR;

 

 Video
 
 
技术图片
 

[TIA PORTAL][CONVERT] Convert Char Array to DInt...DInt to Char Array..Useful and easy function

标签:bsp   lan   temp   _for   com   port   blank   body   lower   

原文地址:https://www.cnblogs.com/sstan1020/p/13193481.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!