New C# Method Request

If you have a question about the software please ask it here.

New C# Method Request

Postby beefy » Wed Aug 09, 2017 8:08 pm

Hi Balazs,

would it be difficult to create a method to do the Initial Movement Preparation run ?

At present it's all manual. You do a Run From Here, then Cycle Start to get the Initial Movement Preparation window, then press OK in this window and the Initial Movement is performed.

I'm wanting to automate this so I could call the button Set Next Line / Run From Here, then call "InitialMovement();"

I played with the Inital Movement Window and noticed it retained its last settings between UCCNC close down and restart, so that would mean a user would only have to set up the tick boxes, etc once. Alternatively, we could have parameters in the InitialMovement() method e.g. InitialMovement(bool rapidFeedrate, etc, etc);

Cheers,

Keith
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: New C# Method Request

Postby dezsoe » Wed Aug 09, 2017 8:39 pm

Hi Keith,

What about doing the initial movements from your code and then calling RemoveRunfromhere()? This would do exactly what you want. (If I understand what you mean. :))
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: New C# Method Request

Postby beefy » Thu Aug 10, 2017 6:23 am

Thanks Dezsoe,

I hear what you are saying but I don't know how that would work. I mean how would I "extract" the XY co-ordinates from a line of gcode so that I could use macro/plugin code to tell the torch to go to that position.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: New C# Method Request

Postby dezsoe » Thu Aug 10, 2017 7:44 am

Nice question! :) I think I've forgotten this...
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: New C# Method Request

Postby Robertspark » Thu Aug 10, 2017 10:26 am

Keith,

Do you want to run from the previous g-code line end point (X+Y), or the current gcode line end point (X+Y) or another co-ordinate?
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: New C# Method Request

Postby beefy » Thu Aug 10, 2017 10:40 am

dezsoe wrote:Nice question! :) I think I've forgotten this...


Ha ha, that makes me feel better :D I was busting my brains trying to figure out how I could do it. Couldn't find any UCCNC functions to grab the XY co-ordinates from a selected gcode line.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: New C# Method Request

Postby beefy » Thu Aug 10, 2017 10:44 am

Robertspark wrote:Keith,

Do you want to run from the previous g-code line end point (X+Y), or the current gcode line end point (X+Y) or another co-ordinate?


Ooh, let me think about that one.

Well if I used the button code for Set Next Line / Run From Here, it would require that the XY co-ordinates were at the end of the previous gcode block.

So basically, let's say I had a flameout and I want to do a dry start and fire the torch while it's moving.

Normally I'd use the gcode window to scroll to the gcode line I want to run from. Then I'd press "Run From Here", then Cycle Start. The Initial Movement Prep window would pop up and I'd click OK. The torch would rapid to the XY co-ords in the previous gcode line. THAT is the bit I'm trying to automate in a macro/plugin, hence the request for a function that effectively presses the OK button in the Initial Movement Prep window, saving the user from doing this manually.

You are holding me in suspense Rob, do you have something up your sleeve to pull that XY co-ord from the previous gcode line.

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Re: New C# Method Request

Postby Robertspark » Thu Aug 10, 2017 11:41 am

Basically,

What I can do at present is read the current line of a gcode file (by using streamreader, and obtaining the current line number from uccnc from reading field number 866).

What I cannot do yet [but have an idea of how to do it] is to split the line up into an array of motion {N**; X**; Y**; Z**, A**; B**; C**; I**; J**; K**; R**; F **; S**; T**; O**; P**; Q**; H**}

The best way is probably to split the string alphabetically and create an array, so that the positions of the alphabetic letters are consistent (i.e. Z= position 25 (c# indexes arrays from position zero, i.e. "A" would be position zero in such a sorted array). If you are only looking for X and Y some would argue why create an array of the rest of the items, well they may be useful for other things..... the array is not going to take up much space in memory / slow the cnc down so it will probably be easier than using Array.IndexOf to find the position of X and Y within the array when you already know they are in position 23 & 24 always, and A will be at position 0 (zero) as some of us use a rotary axis too hence may as well keep track of the A-axis too for motion

Hence easy to find whatever you want from the line of g-code

The difficulty is some g-code is formatted differently to others (i.e. some has spaces between "N50 G1 X 200 Y 50 F150" and some does not "N50G1X200Y50F150" so by splitting the array you should not have a problem.

Doing this process automatically does require some intelligent thought by the code....

1) does the present gcode line have motion within it? (eg N51M206) won't do anything for you
2) doe the present gcode line have motion relevant to your application in it (eg N51Z3) won't help you out if you were automatically looking for previous X, Y, Z, A, B, C gcode line co-ordinates.....

In these cases you want to step back another g-code line (automatically) and re-read / parse to array and try again to find valid g-code line end co-ordinates.

Also you want to ignore comments..... "(THC OFF / THC ON / TOUCH OFF)" ..... certainly don't want any with an A, B, C, X, Y, Z in the comments or they could be put in the array as motion co-ordinates "A0" etc if you were to reuse them.
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: New C# Method Request

Postby Robertspark » Thu Aug 10, 2017 1:18 pm

first bit of the working code here:

(reads the current gcode line from the currently loaded gcode file)

.... may have another idea about parse the string into A; X; Y & Z....

Code: Select all

// get gcode line
string strGcode = AS3.Getfield(866); // read the current [active] gcode line number
string strCurrGcodeFilename = exec.Getgcodefilename(); // Get  path + filename of current loaded gcode file

MessageBox.Show(strGcode + "\n" + strCurrGcodeFilename);

int myLineNumber = Convert.ToInt32(strGcode);

using( System.IO.Stream fileStream = System.IO.File.Open(strCurrGcodeFilename, System.IO.FileMode.Open) )
{
using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream) )
    {
        string line = null;
        for( int i = 0; i < myLineNumber; ++i )
        {
            line = reader.ReadLine();
         
        }
      
      MessageBox.Show(line);
    }
}

Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: New C# Method Request

Postby beefy » Thu Aug 10, 2017 6:01 pm

Hi Rob,

thanks very much.

I've considered this type of approach but as we are finding out it can get a little complex. There is "regex.split" which once learned may be able to pull the XY co-ords from the string, but then there are other considerations like finding what axis letters the user has chosen for their system i.e. could they have chosen XA instead of XY. Then there is the issue of floating point, and positive vs negative numbers if the gcode is running in an incremental mode.

No doubt all doable with some thought and research, but the code for the OK button (Initial Movement Preparation window) is already inside UCCNC so I was hoping it would be fairly simple for Balazs to give us a function for this. It would greatly simplify things.

Balazs, any thoughts on this ??

Cheers,

Keith.
beefy
 
Posts: 449
Joined: Mon Sep 05, 2016 10:34 am

Next

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 15 guests