adccommunitymod (AutomationDirect) asked a question.

Print command on DL06

Created Date: January 31,2006

Created By: cjenkins

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

I am printing on a thermal serial printer from comm 2. All is working well, but I need to format the data going to the print. Ex. V2005 contains my current PSI (ex. 100.2 psi) so in my PRINT command it contains "PSI: " V2005:B and I get PSI: 1002 now I know I can divide V2005 by 10 and get PSI: 100 but I need to print out PSI: 100.2 Can anyone help?


  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2006

    Created by: testone

    Print

    "PSI: " V2005:B ". " V2006:B

    You will need two register. One with 100 and one with 2. Do some math to get the 100 put into V2005 and the decimal into V2006.

    V2005 = 1002 / 10

    V2006 = 1002 - ((1002 / 10) * 10)

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2006

    Created by: franji1

    It's a little more complicated than that because the formatting of numbers does not provide you with just a "2 ".

    Your example would print out

    PSI: 0100 . 0002

    because BCDs display leading 0s.

    I 've done this once before - let me see if I can find the code.

  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2006

    Created by: franji1

    Here's the program, complete with my own PRINT statement for testing (it prints the value out every second - I hooked up Hyperterminal to verify that it worked).

    I loaded 1234 BCD into V2005 to make sure the digits came out right. This program uses V1400 thru V1403 for the ASCII buffer - you may need to change those addresses in the program.

    Note that the PRINT statement now does a print with V1402%5 (print as ASCII text, length 5) instead of dealing with the raw BCD values. It's extra work, but you get the data formatted exactly as you want it.

    =================

    PLC 05

    // Rung 1

    // Address 0

    #BEGIN COMMENT

    "Every scan convert the 4 digit BCD value in V2005 to an ascii string of the form "

    " " "###.# " ". To do this, I must use V1400/V1401 to convert the BCD digits to their ASCII "

    "equivalent. Then I use V1402/V1403 for the output of massaging the text to insert the "

    "decimal point. "

    " "

    "Then in the PRINT statement, I use the ASCII text %length modifier on V1402 (the length "

    "is 5) "

    #END

    LD K1

    LDA O2005

    HTA V1400

    LDD V1400

    LDD K21436587

    SFLDGT

    OUTD V1402

    SHFR K24

    OUT V1404

    LDD V1402

    ANDD Kffffff

    ORD K2e000000

    OUTD V1402

    // Rung 2

    // Address 18

    STR SP4

    PD C0

    // Rung 3

    // Address 20

    STR C0

    PRINT K2 " " "PSI: " " V1402%5 " "$N " " "

    // Rung 4

    // Address 33

    END

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2006

    Created by: franji1

    One minor issue - it will still print out leading 0's, that is if the value is 10.2 it will print "010.2 "

    You cannot just replace the 0's with a space because 10.2 would display as " 1 .2 "

    I hope this is acceptable

  • adccommunitymod (AutomationDirect)

    Created Date: January 31,2006

    Created by: franji1

    Actually - you are using an 06, so you could use VPRINT and then PRINTV to eliminate the leading 0's. Let me know if you would like this solution instead.

  • adccommunitymod (AutomationDirect)

    Created Date: February 01,2006

    Created by: cjenkins

    Thanks for the help. The leading zero's before the decimal point is fine, but not 100.2000 franji1, I would like to see your code, it may make my customer happier than 090.2 I thank all for the advice.

    CJ

  • adccommunitymod (AutomationDirect)

    Created Date: February 01,2006

    Created by: testone

    Sorry, I have 1 more idea but it is bulkier....

    User 10 Print statements...

    V2005 = PSI / 10

    V2006 = PSI - (V2005 * 10)

    --- V2006 = 0 --- Print V2005:B ".0$N "

    --- V2006 = 1 --- Print V2005:B ".1$N "

    --- V2006 = 2 --- Print V2005:B ".2$N "

    --- V2006 = 3 --- Print V2005:B ".3$N "

    --- V2006 = 4 --- Print V2005:B ".4$N "

    --- V2006 = 5 --- Print V2005:B ".5$N "

    --- V2006 = 6 --- Print V2005:B ".6$N "

    --- V2006 = 7 --- Print V2005:B ".7$N "

    --- V2006 = 8 --- Print V2005:B ".8$N "

    --- V2006 = 9 --- Print V2005:B ".9$N "

    This would print leading zeros and single decimal... 0090.2 etc...

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: February 01,2006

    Created by: franji1

    Originally posted by cjenkins:

    Thanks for the help. The leading zero's before the decimal point is fine, but not 100.2000 franji1, I would like to see your code, it may make my customer happier than 090.2 I thank all for the advice.

    CJ

    Here it is, but I did NOT use VPRINT/PRINTV - I just used ladder logic to replace the leading 0's with spaces. Note that the resulting character buffer occupies 3 words, not 2 (I had it wrong in the comment - the program was correct still).

    The output buffer is in V1402, V1403 AND V1404

    Here it is:

    =====================

    PLC 05

    // Rung 1

    // Address 0

    #BEGIN COMMENT

    "Every scan convert the 4 digit BCD value in V2005 to an ascii string of the form "

    " " "###.# " ". To do this, I must use V1400/V1401 to convert the BCD digits to their ASCII "

    "equivalent. Then I use V1402/V1403/1404 for the output of massaging the text to insert "

    "the decimal point. "

    " "

    "THIS IS 5 CHARACTERS, DO IT TAKES UP 3 V MEMORY LOCATIONS, NOT TWO "

    "AS I ORIGINALLY HAD DOCUMENTED (but had programmed correctly) "

    " "

    "In the NEXT rung, massage the text data in the accumulator to display leading spaces "

    "instead of leading 0's. "

    " "

    "Then in the PRINT statement, I use the ASCII text %length modifier on V1402 (the length "

    "is 5) "

    #END

    STR SP1

    LD K1

    LDA O2005

    HTA V1400

    LDD V1400

    LDD K21436587

    SFLDGT

    OUTD V1402

    SHFR K24

    OUT V1404

    LDD V1402

    ANDD Kffffff

    ORD K2e000000

    // Rung 2

    // Address 18

    #BEGIN COMMENT

    "The ASCII text is in the accumulator in this form numerically (due to how ascii characters "

    "are stored) "

    " "

    "Bits 31-24 - " ". " " "

    "Bits 23-16 - UNITS DIGIT "

    "Bits 15- 8 - TENS DIGIT "

    "Bits 7- 0 - HUNDREDS DIGIT "

    " "

    "So if the original value is less than 1000, (e.g. 0999), we want to replace the leading zero "

    "character with the space character (hex 20). Mask off the HUNDREDS DIGIT and "

    "replace it with 20 hex. "

    " "

    "AND if the original value is less than 100 (e.g. 0099), we want to replace the 2nd leading "

    "zero character with the space character. Mask off the TENS DIGIT and replace IT with "

    "20 hex. "

    " "

    "No need to worry about the UNITS digit, since we want a leading 0 for the units digit (e.g. "

    "we prefer to see 0001 displayed as " "0.1 " " not " ".1 " " "

    #END

    STRN V2005 K1000

    ANDD Kffffff00

    ORD K20

    ANDN V2005 K100

    ANDD Kffff00ff

    ORD K2000

    // Rung 3

    // Address 30

    #BEGIN COMMENT

    "Now that we have the accumulator formatted correctly with the first 3 digits and the "

    "decimal points, output it to V1402/V1403 "

    #END

    STR SP1

    OUTD V1402

    // Rung 4

    // Address 32

    STR SP4

    PD C0

    // Rung 5

    // Address 34

    STR C0

    PRINT K2 " " "PSI: " " V1402%5 " "$N " " "

    // Rung 6

    // Address 47

    #BEGIN COMMENT

    "Test code - increments V2005 to test transitions from 9->10, 99->100, 999->1000 "

    #END

    STR C0

    INC V2005

    // Rung 7

    // Address 50

    END

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: February 03,2006

    Created by: cjenkins

    Thanks for the help!

10 of 11