Page 1 of 1

load data from file

Posted: Tue May 02, 2023 8:14 am
by IvanSiberia
I have a code that requests data from a file on drive C.

Code: Select all

double Scan_file_ProbeXYZ(void)
{

	FILE *f;
	char s[256];
	double cnt = 0;

	f = fopen("C:\\temp\\kflopProbeXYZ.txt", "rt");
	if (!f)
	{
		printf("Unable to open file\n");
		return;
	}

	while (!feof(f))
	{
		fgets(s, 100, f);

		if (!feof(f))
		{
			cnt++;
		}
	}

	fclose(f);

	return cnt;
}
As I understand it, the program each time loads a new line from the KMotion. How can this process be accelerated?

Re: load data from file

Posted: Tue May 02, 2023 10:50 pm
by TomKerekes
Hi Ivan,

That method was not designed to work with large amounts of data. File data is mixed between status requests which occurs only a few times per second. So only a few lines of data per second.

Lines can be up to 1024 characters long so using a format with long lines with increase throughput correspondingly.

Otherwise you might create a PC Program to download the file to the KFLOP Gather Buffer. This will have a much higher rate. See the Download Waveform Example.

HTH

Re: load data from file

Posted: Mon Jul 10, 2023 4:21 pm
by IvanSiberia
Hi Tom! I tried using buffer. As far as I understand it is used inside kmotion to pass parameters to kflop. gather_buffer[0] is losing my values. From what address can I correctly use the buffer?

Re: load data from file

Posted: Mon Jul 10, 2023 4:32 pm
by TomKerekes
Hi Ivan,

KMotion should only use the gather_buffer if a Step Response Plot is made. The gather_buffer is one million doubles long. If you limit any Step Response Plots to 1.5 seconds or less the last half of the gather_buffer should not be used.

HTH

Re: load data from file

Posted: Tue Jul 11, 2023 2:16 am
by IvanSiberia
Strange, but my Step Response Plot is not enabled, and the data has changed. Could this be related to the m100 commands?

Re: load data from file

Posted: Tue Jul 11, 2023 11:15 pm
by TomKerekes
Hi Ivan,

Not unless your M100 Program changes it.

Do you do realize the memory will be lost if KFLOP looses power?