Go to Post The best way to deal with an opponent who is going to hang is to go and hang yourself. - dtengineering [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 8 votes, 5.00 average. Display Modes
  #1   Spotlight this post!  
Unread 01-01-2010, 12:08
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
ofstream (standard C++ file output) not working

I was testing a logging system, where you would be able to log data to a logfile on the cRIO, and then FTP to it to see what happened. I used a modified simpleRobot, and added a streambuf* to the variable list, a ofstream, initialized to "cRIOUserLog.log", and then rdbuf to clog. but clog<<"Logging Test"<<endl; (which should also flush) does not appear to do anything. I FTP'd to the cRIO, and looked in most of the directories, but I cannot find cRIOUserLog.log. Is there something I need to do? I remember someone somewhere in some thread somewhile ago saying something about a write flag, but I was able to use IMAQ_write_png (don't think this is the actual name) to write PNG's to the cRIO.
Relevant code:
PHP Code:
class SuperSimpleRobot
{
streambufofsTclog;
ofstream UserLog;
//...
public:
SuperSimpleRobot():
UserLog("cRIOUserLog.log")//...
{
    
ofsTclog=UserLog.rdbuf();
    
clog.rdbuf(ofTclog);
    
//...
    
clog<<"Logging Test"<<endl;
}
//...
}; 
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #2   Spotlight this post!  
Unread 01-01-2010, 12:55
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: ofstream (standard C++ file output) not working

Try calling Priv_SetWriteFileAllowed(1) in the constructor.

I've never used ofstream on the cRIO, but I've gotten C-style file I/O to work (FILE*, fopen(), fwrite(), etc.).
__________________
Patrick Fairbank
Team 254 | Mentor (2012-)
Team 1503 | Mentor (2007-2011)
Team 296 | Alumnus (2001-2004) | Mentor (2005-2006)

patfairbank.com
Reply With Quote
  #3   Spotlight this post!  
Unread 01-01-2010, 17:38
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: ofstream (standard C++ file output) not working

Ditto. C-style has always run fine with me. If you know what you're doing it's not that hard to make a class similar to ofstream with c-style calls.
__________________
Reply With Quote
  #4   Spotlight this post!  
Unread 01-01-2010, 18:26
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: ofstream (standard C++ file output) not working

Quote:
Originally Posted by Pat Fairbank View Post
Try calling Priv_SetWriteFileAllowed(1) in the constructor.

I've never used ofstream on the cRIO, but I've gotten C-style file I/O to work (FILE*, fopen(), fwrite(), etc.).
Thanks! I will try that next time I get a chance.

Quote:
Originally Posted by slavik262 View Post
Ditto. C-style has always run fine with me. If you know what you're doing it's not that hard to make a class similar to ofstream with c-style calls.
I know about C IO, but like C++ much better due to its simplicity, and ease of use by semi-incompetent people
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #5   Spotlight this post!  
Unread 02-01-2010, 11:40
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: ofstream (standard C++ file output) not working

What I was saying is that if you can't get ofstream to work, write your own class that copies its behavior and use the C-style I/O in the member functions.
__________________
Reply With Quote
  #6   Spotlight this post!  
Unread 02-01-2010, 12:37
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: ofstream (standard C++ file output) not working

Quote:
Originally Posted by slavik262 View Post
What I was saying is that if you can't get ofstream to work, write your own class that copies its behavior and use the C-style I/O in the member functions.
if C style works, why would ofstream not work?
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #7   Spotlight this post!  
Unread 02-01-2010, 18:01
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: ofstream (standard C++ file output) not working

The cRIO requires that you call Priv_SetWriteFileAllowed(1) before you can create files on the cRIO file system. You seem to be instantiating your ofstream object in the initialization list of your main robot class; in this case, the ofstream would attempt to create the specified file BEFORE you have allowed such an activity to take place (even if you call Priv_SetWriteFileAllowed(1) in your robot class's constructor - the initialization list gets executed first).

Also, ofstream has several methods that can be useful in diagnosing what has gone wrong. In particular, look at is_open(), good(), fail(), bad(), rdstate() here: http://www.cplusplus.com/reference/iostream/ofstream/

Hope this helps!
Reply With Quote
  #8   Spotlight this post!  
Unread 02-01-2010, 20:16
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: ofstream (standard C++ file output) not working

any files?
when we saved camera png's we did not have to call Priv_SetWriteFileAllowed(1)
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #9   Spotlight this post!  
Unread 04-01-2010, 07:39
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: ofstream (standard C++ file output) not working

Quote:
Originally Posted by byteit101 View Post
if C style works, why would ofstream not work?
It's a great question, but I've never had any issues reading/writing to the robot using C file I/O, and I've never called Priv_SetWriteFileAllowed(1). I know my suggestion is more of a workaround than a real answer, but I just thought it might help.
__________________
Reply With Quote
  #10   Spotlight this post!  
Unread 10-01-2010, 19:47
karatekid's Avatar
karatekid karatekid is offline
Registered User
AKA: Cole
FRC #0662 (Rocky Mountain Robotics)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2009
Location: Colorado Springs, Colorado
Posts: 120
karatekid has a spectacular aura aboutkaratekid has a spectacular aura aboutkaratekid has a spectacular aura about
Re: ofstream (standard C++ file output) not working

I got this from cprogramming.com:
#include <fstream>
#include <iostream>

using namespace std;

int main()
{
char str[10];

//Creates an instance of ofstream, and opens example.txt
ofstream a_file ( "example.txt" );
// Outputs to example.txt through a_file
a_file<<"This text will now be inside of example.txt";
// Close the file stream explicitly
a_file.close();
//Opens for reading the file
ifstream b_file ( "example.txt" );
//Reads one string from the file
b_file>> str;
//Should output 'this'
cout<< str <<"\n";
// b_file is closed implicitly here
}
This is how it is done in c++, for both input and output-this may not help, because I do not know how it will work with the robot, put it works for regular programs. Also, this only works for text files to my knowledge...
__________________
YOU JUST LOST THE GAME!

Last edited by karatekid : 10-01-2010 at 19:57.
Reply With Quote
  #11   Spotlight this post!  
Unread 11-01-2010, 15:24
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: ofstream (standard C++ file output) not working

karatekid, I don't think you know what this thread is about. I know how to use o/i/fstream, but cannot find the file it (supposedly)creates. This format (should) work for the robot, as well as any other target supporting C++ io. And it works for binary fills also

Another thought: would I have to use /myfile instead of just myfile?
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
  #12   Spotlight this post!  
Unread 11-01-2010, 20:21
karatekid's Avatar
karatekid karatekid is offline
Registered User
AKA: Cole
FRC #0662 (Rocky Mountain Robotics)
Team Role: Programmer
 
Join Date: Nov 2009
Rookie Year: 2009
Location: Colorado Springs, Colorado
Posts: 120
karatekid has a spectacular aura aboutkaratekid has a spectacular aura aboutkaratekid has a spectacular aura about
Re: ofstream (standard C++ file output) not working

Sorry?
__________________
YOU JUST LOST THE GAME!
Reply With Quote
  #13   Spotlight this post!  
Unread 13-01-2010, 11:03
slavik262's Avatar
slavik262 slavik262 is offline
We do what we must because we can.
AKA: Matt Kline
FRC #0537 (Charger Robotics)
Team Role: Alumni
 
Join Date: Jan 2007
Rookie Year: 2007
Location: Sussex, WI
Posts: 310
slavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to beholdslavik262 is a splendid one to behold
Send a message via AIM to slavik262
Re: ofstream (standard C++ file output) not working

Any luck so far or is it still not working?

Also, I don't remember needing a forward slash in front of the filename when saving.
__________________
Reply With Quote
  #14   Spotlight this post!  
Unread 13-01-2010, 11:28
Jared Russell's Avatar
Jared Russell Jared Russell is offline
Taking a year (mostly) off
FRC #0254 (The Cheesy Poofs), FRC #0341 (Miss Daisy)
Team Role: Engineer
 
Join Date: Nov 2002
Rookie Year: 2001
Location: San Francisco, CA
Posts: 3,077
Jared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond reputeJared Russell has a reputation beyond repute
Re: ofstream (standard C++ file output) not working

In Java, I recall I had to use a "file://" prefix on my filename (for example: "file://mylog.txt") in order to get file creation to work. Perhaps you have to do the same thing here?
Reply With Quote
  #15   Spotlight this post!  
Unread 13-01-2010, 16:49
byteit101's Avatar
byteit101 byteit101 is offline
WPILib maintainer (WPI)
AKA: Patrick Plenefisch
no team (The Cat Attack (Formerly))
Team Role: Programmer
 
Join Date: Jan 2009
Rookie Year: 2009
Location: Worcester
Posts: 699
byteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of lightbyteit101 is a glorious beacon of light
Re: ofstream (standard C++ file output) not working

Haven't tried to do it yet, yesterday we we only able to get LV/WR/NB installed. I think I might be able to test it Thursday, but definitely by Saturday.

Interesting Jared341, I will try this.
__________________
Bubble Wrap: programmers rewards
Watchdog.Kill();
printf("Watchdog is Dead, Celebrate!");
How to make a self aware robot: while (∞) cout<<(sqrt(-∞)/-0);
Previously FRC 451 (The Cat Attack)
Now part of the class of 2016 at WPI & helping on WPILib
Reply With Quote
Reply


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
p2 not working? Lone_Wolf92c Programming 5 22-02-2008 08:49
IR Board Not Working (But NOT Fried) itsme Electrical 2 18-02-2008 06:11
Beware - transmission output shaft is not 5/8"! jskene Kit & Additional Hardware 30 13-02-2006 14:01
Drive() Not a Standard Toolset in EasyC? Chris_Elston Programming 3 08-02-2006 09:01
Beware - transmission output shaft is not 5/8"! jskene Technical Discussion 3 19-01-2006 14:24


All times are GMT -5. The time now is 12:43.

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