load data from file

Moderators: TomKerekes, dynomotion

Post Reply
IvanSiberia
Posts: 30
Joined: Fri Jun 17, 2022 11:21 am

load data from file

Post by IvanSiberia » Tue May 02, 2023 8:14 am

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?

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: load data from file

Post by TomKerekes » Tue May 02, 2023 10:50 pm

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
Regards,

Tom Kerekes
Dynomotion, Inc.

IvanSiberia
Posts: 30
Joined: Fri Jun 17, 2022 11:21 am

Re: load data from file

Post by IvanSiberia » Mon Jul 10, 2023 4:21 pm

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?

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: load data from file

Post by TomKerekes » Mon Jul 10, 2023 4:32 pm

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
Regards,

Tom Kerekes
Dynomotion, Inc.

IvanSiberia
Posts: 30
Joined: Fri Jun 17, 2022 11:21 am

Re: load data from file

Post by IvanSiberia » Tue Jul 11, 2023 2:16 am

Strange, but my Step Response Plot is not enabled, and the data has changed. Could this be related to the m100 commands?

User avatar
TomKerekes
Posts: 2546
Joined: Mon Dec 04, 2017 1:49 am

Re: load data from file

Post by TomKerekes » Tue Jul 11, 2023 11:15 pm

Hi Ivan,

Not unless your M100 Program changes it.

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

Tom Kerekes
Dynomotion, Inc.

Post Reply