Go to Post Improve yourself. Try not to tear others down. - Tom Line [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 18-01-2006, 00:28
BillyJ BillyJ is offline
Registered User
no team
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Texas
Posts: 13
BillyJ is an unknown quantity at this point
Printf

For some reason none of my attempts to send data back with the printf function seem to be working. Regular text seems to be working just fine but when I try to output variables it all just goes downhill.

Is there a simple explanation as to how to get printf working correctly?




Thanks
  #2   Spotlight this post!  
Unread 18-01-2006, 00:40
Pat Fairbank's Avatar
Pat Fairbank Pat Fairbank is offline
Circuit Breaker
FRC #0254 (The Cheesy Poofs)
Team Role: Engineer
 
Join Date: Mar 2003
Rookie Year: 2001
Location: San Jose, CA
Posts: 2,132
Pat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond reputePat Fairbank has a reputation beyond repute
Send a message via MSN to Pat Fairbank
Re: Printf

Seems like the printf header file with the handy usage instructions has disappeared along with the function's C code, into FRC_library.lib I would think.

Anyway, if the the syntax from last year's code still applies it should be something like:
Code:
printf("Myvariable = %d\r", (int)myvariable);
__________________
Patrick Fairbank
Team 254 | Mentor (2012-)
Team 1503 | Mentor (2007-2011)
Team 296 | Alumnus (2001-2004) | Mentor (2005-2006)

patfairbank.com
  #3   Spotlight this post!  
Unread 18-01-2006, 01:41
TimCraig TimCraig is offline
Registered User
AKA: Tim Craig
no team
 
Join Date: Aug 2004
Rookie Year: 2003
Location: San Jose, CA
Posts: 221
TimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to beholdTimCraig is a splendid one to behold
Re: Printf

Quote:
Originally Posted by BillyJ
Is there a simple explanation as to how to get printf working correctly?
Unless it's changed this year and I haven't had a chance to check, the printf function supplied is a partial implementation. For instance, no %f or %ld specifiers. And you have to be careful to make sure the passed argument list exactly matches the size of the specifiers in the string or very funny things can happen. Since printf takes a variable number of arguments, the compiler can't do strict type checking for you. All it can do is make sure the first argument passed is a string. For instace if you want to print the numerical value contained in a char, you need to cast it to an int if you specify %d.
  #4   Spotlight this post!  
Unread 18-01-2006, 10:06
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Printf

There's a copy of printf in the C library supplied by Microchip. In fact you can look at the source code in the src directory in the mcc18 install.

It implements most of the standard printf features except floating point. And does support longs and some of the other data types.

Be sure that the abridged version of printf that was supplied in the past is not part of your project, otherwise the linker will give you that one instead of the Microchip version.

The documentation for printf is in section 4.7 of the MPLab C18 Libraries PDF document. Kevin Watson has been making that easily available to teams on his web site that you can download.
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #5   Spotlight this post!  
Unread 20-01-2006, 02:36
eugenebrooks eugenebrooks is offline
Team Role: Engineer
AKA: Dr. Brooks
no team (WRRF)
 
Join Date: Jan 2004
Rookie Year: 2001
Location: Livermore, CA
Posts: 601
eugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond repute
Re: Printf

Quote:
Originally Posted by BradAMiller
There's a copy of printf in the C library supplied by Microchip. In fact you can look at the source code in the src directory in the mcc18 install.

It implements most of the standard printf features except floating point. And does support longs and some of the other data types.
You can also get the extended integer formatting code referred to in the white paper: "Introduction to C programming for first robotics applications" that will format signed and unsigned longs and will also format fixed point numbers, if you are using them. The white paper indicates where to download this code.
  #6   Spotlight this post!  
Unread 20-01-2006, 02:51
BillyJ BillyJ is offline
Registered User
no team
 
Join Date: Feb 2005
Rookie Year: 2003
Location: Texas
Posts: 13
BillyJ is an unknown quantity at this point
Re: Printf

Finally got it working, I don't know why I was having so much trouble before...

Thanks a lot for all your help.


On a somewhat related note - When I connect via the program port to download code I get the window IFI> and any of my printf's are displayed. Is there anyway to read this from the dashboard port or by method other than downloading code?


Thanks
  #7   Spotlight this post!  
Unread 20-01-2006, 20:10
eugenebrooks eugenebrooks is offline
Team Role: Engineer
AKA: Dr. Brooks
no team (WRRF)
 
Join Date: Jan 2004
Rookie Year: 2001
Location: Livermore, CA
Posts: 601
eugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond repute
Re: Printf

We are getting spurious newlines in code used last year to print the new values of digital and analog inputs when values change. Is anyone seeing spurious linebreaks from printf?
  #8   Spotlight this post!  
Unread 20-01-2006, 21:10
BradAMiller BradAMiller is offline
Registered User
AKA: Brad
#0190 ( Gompei and the Herd)
Team Role: Mentor
 
Join Date: Mar 2004
Location: Worcester, MA
Posts: 592
BradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant futureBradAMiller has a brilliant future
Re: Printf

Quote:
Originally Posted by eugenebrooks
We are getting spurious newlines in code used last year to print the new values of digital and analog inputs when values change. Is anyone seeing spurious linebreaks from printf?
If you are using "\n" for new lines, try changing them to "\r".
__________________
Brad Miller
Robotics Resource Center
Worcester Polytechnic Institute
  #9   Spotlight this post!  
Unread 20-01-2006, 21:21
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #5263
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Riverview, MI
Posts: 723
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan
Re: Printf

Quote:
Originally Posted by BillyJ
On a somewhat related note - When I connect via the program port to download code I get the window IFI> and any of my printf's are displayed. Is there anyway to read this from the dashboard port or by method other than downloading code?
You can do this a few ways. If you just need to see the feedback from the bot and that's it, open IFI Loader, click Options > Controller verification, make sure it finds the RC okay, and click Options > Terminal window. Another solution is to use HyperTerminal (bundled with Windows, post back if you need instructions making this work).

Good luck!
JBotAlan
__________________
Aren't signatures a bit outdated?
  #10   Spotlight this post!  
Unread 21-01-2006, 14:03
eugenebrooks eugenebrooks is offline
Team Role: Engineer
AKA: Dr. Brooks
no team (WRRF)
 
Join Date: Jan 2004
Rookie Year: 2001
Location: Livermore, CA
Posts: 601
eugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond reputeeugenebrooks has a reputation beyond repute
Re: Printf

Quote:
Originally Posted by BradAMiller
If you are using "\n" for new lines, try changing them to "\r".
Great call! If you use '\n' to end the lines in the printf routine spurious new lines show up in the middle of the line, for some reason. We switched them all to '\r' and this problem evaporated.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
printf could not find definition Alex829 Programming 7 27-06-2005 10:04
Printf Oddity : Programming Challange DarkAlex Programming 7 21-03-2005 08:12
printf statements do not display in autonomous mode PVC Pirates Programming 3 22-02-2005 15:41
Default Code and printf WilsonDJ00 Programming 2 22-01-2005 16:39
Anyone with a replacement Printf? Larry Barello Programming 5 19-03-2004 02:20


All times are GMT -5. The time now is 01:55.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi