You are not registered yet. Please click here to register!


 
 
plc storereviewsdownloads
This board is for PLC Related Q&A ONLY. Please DON'T use it for advertising, etc.
 
Try our online PLC Simulator- FREE.  Click here now to try it.

---------->>>>>Get FREE PLC Programming Tips

New Here? Please read this important info!!!


Go Back   PLCS.net - Interactive Q & A > PLCS.net - Interactive Q & A > LIVE PLC Questions And Answers

PLC training tools sale

Reply
 
Thread Tools Display Modes
Old June 17th, 2017, 08:49 PM   #1
XtremeIN
Member
United States

XtremeIN is offline
 
XtremeIN's Avatar
 
Join Date: Jun 2005
Location: Indiana
Posts: 213
DL06 PRINT statement and leading zero's

Hello all,
I am working on a project that sends data via a serial connection to a Raspberry Pi. So far everything is going well but the customer has a request that I have yet to figure out how to do. When using a Vmem in a PRINT box is there a way to place leading zeros on the Vmem value, Say the reading is 8o, but I want it to display/send 080.

Thanks,
Micheal

This is the current PRINT statement:

"PR012345678900" V4200 "" V4201 "" V4202 "" V4203 "" V4204 "" V4205 "" V4206 "" V4207 "" V4250 "" V4251 "" V3566 "" "$N"

The result is:
PR012345678900 80 80 80 80 80 80 80 80 80 80 853

The desired result would be:
PR0123456789000800800800800800800800800800800853
  Reply With Quote
Old June 17th, 2017, 11:02 PM   #2
labeledas
Member
Canada

labeledas is offline
 
labeledas's Avatar
 
Join Date: Apr 2010
Location: Peace River Alberta
Posts: 527
Could you do it on pi side I would add a a Special unique character or sequence between each vmem like_%_ then explode you data on the pi side into an array iterate through it and pad it depending on the value of the number and then stick it back together.

You could do it on the dl side as well by concatena ting a string using conditionals on each vmem but it may prove cumbersome
  Reply With Quote
Old June 18th, 2017, 12:04 AM   #3
XtremeIN
Member
United States

XtremeIN is offline
 
XtremeIN's Avatar
 
Join Date: Jun 2005
Location: Indiana
Posts: 213
It was requested by the guy doing the Pi programming. I think it has to do with the way he is wanting to separate the data package being sent via the PLC. He would like each data package sent to be the exact same length. I told him that is probably the one thing that I cannot do, but was hoping someone would have an idea/solution.

Thanks,
Micheal
  Reply With Quote
Old June 18th, 2017, 12:29 AM   #4
labeledas
Member
Canada

labeledas is offline
 
labeledas's Avatar
 
Join Date: Apr 2010
Location: Peace River Alberta
Posts: 527
You could always load you values onto the stack run a for next loop using pop to get the values out to a holding register and run a few compares

If less than 100 vprint "00" vmem next
If less than 1000 vprint "0" vmem next

Then printv to output string

I have never tried it before but it may work
You would also have to load onto the stack in reverse order ie 3566 first and 4200 last
  Reply With Quote
Old June 18th, 2017, 09:27 AM   #5
bernie_carlton
Lifetime Supporting Member + Moderator
United States

bernie_carlton is offline
 
bernie_carlton's Avatar
 
Join Date: Apr 2002
Location: Yakima, Washington
Posts: 6,158
Check out the VPRINT instruction to build the string in memory. It has more formatting capabilities. Then use PRINTV to send the completed string.
__________________
Controlling outputs is the PLC's way of getting its inputs to change.

www.thePLCguy.com
  Reply With Quote
Reply
Jump to Live PLC Question and Answer Forum

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 11:37 AM.


.