Format real number for a serial printer

cowski

Member
Join Date
Jan 2018
Location
IA
Posts
3
I am trying to print from a Compact Logix PLC to a serial printer (a point of sale type printer - you send it ascii characters to print).

Is there any way to format a real number in RSLogix5000? I need to print the weight to .1 precision.

I can easily format the number for display on the panelview plus... Does anyone know how to send this formatted string back to the PLC? I tried a macro similar to "/*N:4 {weight} NOFILL DP:1*/" but it did not run.

Thank you!🍺, any help would be appreciated.
 
  • multiply by 10 and put result into INT (or DINT*)
    • which rounds, I think
      • otherwise add 0.5 before putting result into *INT
  • convert INT to BCD
  • add 48 to each nibble to get ASCII code for each digit
  • insert decimal point (ASCII 46)
* what is the range?




(Whoops, Gary is right, I did it again LOL).
 
Thanks Gents.

The range is 0.0 to 999.9.

I tried converting to a string with RTOS (real to string). The RTOS instruction itself is imprecise (I guess due to the nature of how RS 5000 stores floating point numbers in 32 bit format....). If I put 12.4 into RTOS it outputs a string of "12.39999996".

Maybe if convert to DINT then add 48 to each nibble to get ASCII code for each digit...that sounds like a good idea.
 
It's not just Logix; that's just how IEEE single-precision floating point works. Any system that isn't specifically set up to round to a fixed number of decimal places for a display will produce those results.

For numbers between 0.0 and 999.9, multiplying by 10 with a DINT destination will give you the desired rounding and a fixed decimal position. Use DTOS to convert that DINT to a String, and insert a decimal point character into the string.

Note: When doing this kind of data manipulation for something that will go into an HMI or other cyclic data read/write, I use a final COPY instruction to make sure that the HMI or other data exchange can't grab the value of the tag in between instructions.

DTOS_Example.PNG
 
Last edited:
Thanks Gents.

The range is 0.0 to 999.9.

I tried converting to a string with RTOS (real to string). The RTOS instruction itself is imprecise (I guess due to the nature of how RS 5000 stores floating point numbers in 32 bit format....). If I put 12.4 into RTOS it outputs a string of "12.39999996".

Maybe if convert to DINT then add 48 to each nibble to get ASCII code for each digit...that sounds like a good idea.




It may be simpler to use RTOS as Gary suggested, but add 5000.05 first (5000 to get a leading thousands digit; 0.05 for rounding), and send to the printer the a substring comprising only characters 1 through 5 (character 0 is the thousands digit; character 4 is the decimal point). The only downsides are the leading zeros for values less than 100.


or add the .05 for rounding, append the characters one at a time from the beginning, and send one character after the decimal point. Hmm, does RTOS ever not include a decimal point? does it include a trailing zero after said decimal point?
 
Last edited:
Right, thank you Ken and Gary.

Thank you for the example code that described my exact question Ken!

I'll note that's a IEEE single-precision floating point issue (and not a RSLogix one).
 
PXjuEbz.png
 

Similar Topics

Hi, everybody Do you know anybody function in Step7 for convert 6-bit curret format to real, thanks
Replies
13
Views
4,054
In a PV 5310, can you format a numeric object to create comma's in the thousands position? I see no way from the properties panel.
Replies
11
Views
454
Hi all, if I remember correctly, there is some way in a ControlLogix (or CompactLogix) where you can sort of map tags into SLC addressing format...
Replies
8
Views
1,155
I can't see any option to display the date in UK format, i.e. dd/mm/yyyy Is it available in TIA Portal v18?
Replies
21
Views
1,790
Hello expert I have migrate legacy project that use Applicom OPC DA with 3rd client and S7-400. I see in client code add item string call...
Replies
0
Views
366
Back
Top Bottom