File operations (fopen, fscanf, fprintf, etc)
Moderators: TomKerekes, dynomotion
-
- Posts: 4
- Joined: Tue Aug 13, 2019 11:57 am
File operations (fopen, fscanf, fprintf, etc)
Hello!
Where can I find detailed information regarding operations with text files?
What is "wt", "rt", "r+" etc.
What parameters of the fopen, fscanf, fprintf commands can generally take values
How can I navigate the lines of a file, go to the beginning or end, insert an empty line, select and replace characters... etc.
I can not find this information anywhere.
Thanks for the answer
Where can I find detailed information regarding operations with text files?
What is "wt", "rt", "r+" etc.
What parameters of the fopen, fscanf, fprintf commands can generally take values
How can I navigate the lines of a file, go to the beginning or end, insert an empty line, select and replace characters... etc.
I can not find this information anywhere.
Thanks for the answer
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: File operations (fopen, fscanf, fprintf, etc)
Hi Anton,
rt - read file text mode
wt - write file text mode
at - append to file write mode
https://en.wikipedia.org/wiki/Printf_format_string
https://en.wikipedia.org/wiki/Scanf_format_string
See KMotionDef.h for available KFLOP functions, variables, and definitions. Here is an excerpt:Where can I find detailed information regarding operations with text files?
Code: Select all
typedef int FILE;
FILE *fopen(const char*, const char*); // Open a text file for writing on the PC 2nd param = "rt" or "wt" or "at"(append write text mode)
int fprintf(FILE *f, const char * format, ...); // Print formatted string to the PC's Disk File
int fclose(FILE *f); // Close the disk file on the PC
#define MAX_READ_DISK_LENGTH 1024 // max allowed length of disk file line length
char *fgets(char *str, int n, FILE *file); //read string from PC disk file, str=buffer, n=buffer length, f=FILE pointer, returns NULL on error
int fscanf(FILE *f, const char *format, ...); //read sting from PC Disk file, convert values, returns number of items converted
int feof(FILE *f); // End of file status for disk reading
KFLOP support for accessing files on the PC is very basic. Only text mode (not binary) is supported. Only:What is "wt", "rt", "r+" etc.
rt - read file text mode
wt - write file text mode
at - append to file write mode
please see the KMotionDef.h file. For formatting codes Google these functions to find many on-line explanations. Such as:What parameters of the fopen, fscanf, fprintf commands can generally take values
https://en.wikipedia.org/wiki/Printf_format_string
https://en.wikipedia.org/wiki/Scanf_format_string
You would need to do such things yourself by reading the file line-by-line and then writing a new file line-by-line.How can I navigate the lines of a file, go to the beginning or end, insert an empty line, select
and replace characters... etc.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 4
- Joined: Tue Aug 13, 2019 11:57 am
Re: File operations (fopen, fscanf, fprintf, etc)
Wow! I did it! Thank you very much!
But could you tell me if it is possible to obtain the following information in any format (for subsequent recording to a file):
1) Current time
2) Program execution time
3) The name of the executable program file (<program1.tap> for example)
Thanks for the answers, Tom!
But could you tell me if it is possible to obtain the following information in any format (for subsequent recording to a file):
1) Current time
2) Program execution time
3) The name of the executable program file (<program1.tap> for example)
Thanks for the answers, Tom!
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: File operations (fopen, fscanf, fprintf, etc)
Hi Anton,
Not currently. Time_sec() returns seconds from power up.But could you tell me if it is possible to obtain the following information in any format (for subsequent recording to a file):
1) Current time
You can monitor JOB_ACTIVE to determine when a Job starts and how long it has been running.2) Program execution time
Not currently3) The name of the executable program file (<program1.tap> for example)
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 4
- Joined: Tue Aug 13, 2019 11:57 am
Re: File operations (fopen, fscanf, fprintf, etc)
It is very, very sad...
After all, we can see in the window title bar both the file name and the program execution time.
Thus, no report on the production process using KMotion is impossible to do ...
And the active state JOB_STATUS also appears when changing a hand tool, for example.
Okay, I can think of something with the runtime of the program, but with the rest ...
Thanks Tom!
After all, we can see in the window title bar both the file name and the program execution time.
Thus, no report on the production process using KMotion is impossible to do ...
And the active state JOB_STATUS also appears when changing a hand tool, for example.
Okay, I can think of something with the runtime of the program, but with the rest ...
Thanks Tom!
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: File operations (fopen, fscanf, fprintf, etc)
There is already a <>\KMotion\Data\RunLog.txt file written by KMotionCNC that has Time, Job Time, and Filename that looks like:
Mon, Aug 12, 2019, 04:09:07 Elapsed Job Time: 95.3 sec C:\KMotionSrc\GCode Programs\turbothisthread.ngc
Mon, Aug 12, 2019, 04:11:32 Elapsed Job Time: 18.9 sec C:\KMotionSrc\GCode Programs\turbothis thread no G95.ngc
Mon, Aug 12, 2019, 04:09:07 Elapsed Job Time: 95.3 sec C:\KMotionSrc\GCode Programs\turbothisthread.ngc
Mon, Aug 12, 2019, 04:11:32 Elapsed Job Time: 18.9 sec C:\KMotionSrc\GCode Programs\turbothis thread no G95.ngc
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.
-
- Posts: 4
- Joined: Tue Aug 13, 2019 11:57 am
Re: File operations (fopen, fscanf, fprintf, etc)
But I do not see AM&PM time in this file. And it is very unpleasant ...
- TomKerekes
- Posts: 2676
- Joined: Mon Dec 04, 2017 1:49 am
Re: File operations (fopen, fscanf, fprintf, etc)
Hi AntonKulinkov,
Oops. You are correct. We can offer a patch to use 24 hr format. We'd prefer that as adding AM/PM may break Code of existing Users. Does that work for you?I do not see AM&PM time in this file.
Regards,
Tom Kerekes
Dynomotion, Inc.
Tom Kerekes
Dynomotion, Inc.