D - application notes, Appendix, Unsigned integer to string conversion – Rockwell Automation 2706-DXX Dataliner Message Display DL5 Series User Manual
Page 109

2706-UM001A-US-P
Appendix
D
Application Notes
Unsigned Integer to String
Conversion
Serial protocol uses decimal values in the range of 0 to 65535 to send
variable data (Ctrl-V command). PLCs that do not support unsigned
integers can only generate values in the range of -32768 to 32767. To send
decimal values in the range used by the serial protocol, use the following
ladder logic. This program converts a 16-bit signed integer to an unsigned
ASCII decimal string. The ASCII decimal string can then be used to
generate serial commands for the DL5.
In this example, the 16-bit integer is in N17:0 (signed value = -12264,
unsigned value = 53272). The conversion uses N17:1 and ST18:1-4 as
temporary buffers. The ASCII decimal string is returned in ST18:5. The
conversion routine ladder logic is as follows:
AIC
Integer to String
Source N17:0
-12264<
Dest
ST18:5
GEQ
Grtr Than or Eql (A>=B)
Source A
-12264<
Source B
0
N17:0
0<
0000
AIC
Integer to String
Source
6
6<
Dest
ST18:1
LES
Less Than or Eql (ASource A
-12264<
Source B
0
N17:0
0<
0001
SUB
Subtract
Source A
N17:0
-12264<
Source B
-5536
15536<
Dest
N17:1
3272<
AIC
Integer to String
Source
5
5<
Dest
ST18:1
LES
Less Than or Eql (ASource A
-12264<
Source B
-5536
N17:0
-5536<
0002
SUB
Subtract
Source A
N17:0
-12264<
Source B
-15536
-15536<
Dest
N17:1
3272<