Dynomotion

Group: DynoMotion Message: 11552 From: cnc_machines Date: 5/21/2015
Subject: Printing to a File
Greetings,

I am wanting to write the current position of an axis to a file. To start with I am trying to open the file and save "Hello World". When I try to do so it saves to the console rather than the file.

    Jog(1,-15000);              // jog slowly negative
    while (ReadBit(1026)) ;      // loop until IO bit goes low
    Jog(1,0);                // stop
   
    FILE *f=fopen("Z:\\Automation Department\\LengthBH.txt","wt");
   
    printf("Hello world\n");
    fclose(f);


I am not sure how to get it to write to file, any idea what I am missing?


Once this is working I would really like to write out the current position for axis 1. Any ideas on how to do this?


Thanks!


Scott

Group: DynoMotion Message: 11554 From: Tom Kerekes Date: 5/21/2015
Subject: Re: Printing to a File
Hi Scott,

printf("Hello world\n");    - prints to the Console

fprintf(f,"Hello world\n") ;- prints to a file f

Regards
TK

Group: DynoMotion Message: 11555 From: lmp582002 Date: 5/21/2015
Subject: Re: Printing to a File
Great! Thanks. In order to send the current position I would use the following?

ch1->Dest
 
If that is the case then the way to write out the file would be:

 
    FILE *f=fopen("Z:\\Automation Department\\LengthBH.txt","wt");
    
    printf(f,"(ch1->Dest)*812.3");

    fclose(f);

I am multiplying by 8123 because that is that is the number of steps per inch and this would write the inch location.

Thanks,

Scott
Group: DynoMotion Message: 11556 From: Tom Kerekes Date: 5/21/2015
Subject: Re: Printing to a File
Hi Scott,

You made 2 mistakes:

#1 fprintf - has 2 'f' characters in it.

#2 to print a floating point number you need to have a string of characters with a %f in it.  The print statement will substitute the value of the number of the specified parameter for the %f.   So it would be:

fprintf("Dest1 = %f\n",ch1->Dest * 812.3);

printf/fprintf has very powerful conversion and formatting options.  You can research on the web.  ie.


HTH
Regards
TK
 

Group: DynoMotion Message: 11557 From: lmp582002 Date: 5/21/2015
Subject: Re: Printing to a File
I will read through to get a better understanding. Thanks for the explanation.

Scott