Welcome Guest,Register Now
Log In

ANT Forum

Welcome guest, please Login or Register

   

C# Decode example how to make output to text file instead of console

Rank

Total Posts: 1

Joined 2017-01-30

PM

Hi everyone!

In Decode example for c# all output from decoded messages are pushed to Console.

The thing is that I would like to output messages to text file. I managed to change Console.Writeline -> file.Writeline inside eventHandlars but the problem is the filename is defined inside event.

The real question is how to pass file as parameter from Main() to these eventhadler functions.

Thx      
Rank

Total Posts: 7

Joined 2017-02-08

PM

I doubt whether you want to do this. In Linux only few files write directly to a file; output to the console is much more common and handier.

You might want to use pipe/redirection by running a program, followed by a ">" followed by the output file.

for example:
decode bla.fit
produces console output, but
decode bla.fit > output.csv
produces a output text file named output.csv

In this example you'll find more use for your tool.

I'm no C# programmer but in any C-like/Pascal/Java program there is an interface to command-line parameters.

for example:
int main(int argccharargv[]{
...


argv[0] is the name of the program itself, if
argc 
then you can additional arguments with
argv[i] 


What you need is an extra class, that handles the messages accordingly by writing them to a file. Something like:
class FileOutputListener implements (ListenerAListener Betc){
  FileOutputListener
(String aFilename{
      Filename 
aFilename;
      
Outputfile ofstream.create(Filenameaccess modes bla);
  
}
//destructor, closing, freeing.
protected:
  
string Filename;
  
ofstream Outputfile;

  
OnMesg(const MessageTypeMsg{

   Outputfile 
<< Msg.getHeartRate() << "...";
  
}


So you initialize the new listener with the filename.