Page 1 of 1

Using big array of data in a Gcode program

Posted: Mon Oct 02, 2023 2:15 pm
by dominfo
Hello Tom

In my application I need to use a generic Gcode program with Variables which should take values from a big array of data (20000 integers) during runtime.

I investigate on using the gather buffer.

step1/ load the 20000 integer values in the gather
=> From a .Net application, how can I upload the 20000 integer in the gather buffer.
I looked in doc without a clear answer

the code would be like this:

Code: Select all

KM.KMotionLock()
KM.ServiceConsole()
KM.WaitToken(500)
KM.WriteLine("SetGatherHex " & offset & " " & nData)
KM.WriteLine(data)
KM.ReleaseToken()
with offset=0, nData the number of variables in data variable, data is a string with the 20000 integer in HEX format separated by a space.
Question 1:
=> this data would be extremely large and could cause issues and timeout during the KM.WriteLine(data)?



step2/ run the gcode which will use a dedicated M1xx Mcode running a C program to fetch the gather value
inspired by
CaptureXYMotionPosDest.c

Code: Select all

//dedicated Mcode running this C program
p = gather_buffer;
indexGather = (Qvalue- 1) * 40;
persist.UserData[50] = p[indexGather]; indexGather += 1;// from gather;

for (int i = 1; i <= 20; i++) {
	//read start segment from gather
	persist.UserData[50 + (2 * i) -1] = p[indexGather]; indexGather += 1;
	//read end segment from gather
	persist.UserData[52 + (2 * i)] = p[indexGather]; indexGather += 1;
}

SetVars(50, (1+40), 50); //41 variables to copy from persistent 50 to Gcode #50
The Gcode would continue execution after the Mxx by moving to positions from #51 to #90

Question :
Is my investigation possible? Do you have other proposal on using so much variables with a Gcode program using #variables?


Thanks for your support
Frederic

Re: Using big array of data in a Gcode program

Posted: Mon Oct 02, 2023 5:16 pm
by TomKerekes
Hi Frederic,

I don't see the need to send the data to KFLOP to then have KFLOP put the values into the GCode Variables. Why not have your .NET App put the data directly into the GCode Variables now that we have added that capability? See new release here.

.NET Help here.

Re: Using big array of data in a Gcode program

Posted: Mon Oct 02, 2023 6:11 pm
by dominfo
Hi Tom

My array is about 20000 integers.
We don't have 20000 Gcode variables available in the GcodeInterpreter, am I right ?

Frederic

Re: Using big array of data in a Gcode program

Posted: Mon Oct 02, 2023 6:24 pm
by TomKerekes
Hi Frederic,

That is correct. 5400 variables. 0-4999 are available for User use.

Re: Using big array of data in a Gcode program

Posted: Mon Oct 02, 2023 6:40 pm
by dominfo
Hi Tom,

So is my proposal a correct solution then ?

I found some useful help to send from .Net this big amount of data
=> PC VCS Examples\SimpleFormsCS\Form1.cs

Code: Select all

                int L = 256;  // put up to 256 per line (with ';' every 8)
                if (KM.GetBoardType() == BOARD_TYPE.KFLOP) 
                    L = 8;  // KFLOP does 8 per line                                       
                            
                // fill simple buffer with a ramp
                for (int i = 0; i < N; i++) data[i] = i;

                // first get the token for the board to allow uninterrupted access
                if (KM.WaitToken(1000000) != KMOTION_TOKEN.KMOTION_LOCKED) return;

                SentData = true;
                T0 = DateTime.Now;

                // tell the board we will send N (32 bit ) words at offset 0
                KM.WriteLine(String.Format("SetGatherHex {0} {1}", 0, N));

                // send the data (simple ramp)  (8 hex words per line)

                for (int i = 0; i < N; i++)
                {
                    s = s + data[i].ToString("X8");

                    if (((i % L) == L - 1) || i == N - 1)  // every 8/256 or on the last send it
                    {
                        KM.WriteLine(s);
                        nchars_sent += s.Length;
                        s = "";
                    }
                    else
                    {
                        s = s + " ";  // otherwise insert a space
                    }
                }
                // release our access to the board
                KM.ReleaseToken();

Re: Using big array of data in a Gcode program

Posted: Mon Oct 02, 2023 10:12 pm
by TomKerekes
Hi Frederic,

Well again I don't see why you would want to sent all the data to KFLOP and then upload 50 variables at a time to the PC. Why not have the MCode have your .NET App put 50 variables at a time (or 1000) to the Interpreter?

Re: Using big array of data in a Gcode program

Posted: Thu Oct 05, 2023 10:00 am
by dominfo
Hello Tom

I understand now your answer. I misunderstood the fact that the GcodeInterpreter is in the PC and not in KFLOP.
=> it makes no sense to push all datas to KFLOP, because those will be treated by the GcodeInterpreter in the PC.

Thanks again for you feedback

Frederic