New C# Method Request

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

Re: New C# Method Request

Postby Robertspark » Thu Aug 10, 2017 6:20 pm

Keith, thanks for regex.split, was not aware of it, just what I was looking for

What's floating point got to do with it?

It's just a string you are splitting on letters, then concatenate the split array from regex.split(string,pattern) string pattern = @"(G)|(g)|(X)|(x)|(Y)|(y)|(Z)|(z)|(A)|(a)|(B)|(b)"

Then search the array for axis letters any use them as the last points?

You can check to see if the machine is in absolute or incremental mode, if you are in incremental mode... And it stopped you really no man's land

.... Execpt uccnc does give axis distance to go.... So it would be possible to backtrack imho
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: New C# Method Request

Postby dezsoe » Thu Aug 10, 2017 7:06 pm

Hi Rob,

I use this regex to extract whole words from a g-code line:

Code: Select all
        Private sControlsPattern As String =
                "(" +
                "([abcdefhijklpqrsxyz]\s*[+-]?([0-9]+([\.,][0-9]*)?|[\.,][0-9]+)\s*)|" +
                "([g]\s*\d+([\.][0-9])*\s*)|" +
                "(m\s*\d+\s*{\s*)|" +
                "(}\s*)|" +
                "([mnot]\s*\d+\s*)|" +
                "([abcdefhijklpqrstxyz]\s*#\s*\d+\s*)|" +
                "([abcdefhijklpqrstxyz]\s*##\s*\d+\s*)|" +
                "(#\s*\d+\s*=)|" +
                "(@)|" +
                "(\(.*\))\s*" +
                ")"

Thinking over the whole thread, I'm sure that the easiest (and fastest) way would be to have a function like this: DoRFHAndGetParams(x, y, z, a, b, c, sx, sy, sz, sa, sb, sc, feed, rx, ry, ra), where UCCNC loads the parameters as it would be in the IMP window and returns a bool as a result of RFH (the given line number in field 866 is valid). The parameters x..c are the coordinates, sx..sc are the scale values, feed is feed, rx..ra are the rotation parameters.
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 7:12 pm

Nice, thanks very much Dezsoe

(I'm more learning than trying to avoid the creation of a function by cncdrive, and I've learnt quite a few things in this thread)
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: New C# Method Request

Postby beefy » Thu Aug 10, 2017 7:33 pm

Robertspark wrote:Keith, thanks for regex.split, was not aware of it, just what I was looking for

What's floating point got to do with it?


Hi Rob,

ha ha, I was not aware of it either, just Googled about extracting numbers from a string and found out about it on the good old Stackexchange forum.

Here's one thread I came across:

https://www.dotnetperls.com/regex-split-numbers

Regarding floating point, I was just meaning we also have to include the decimal point as more often than not, XY co-ordinates are not whole integers.

Like I say, all doable with a bit of research and thinking. However, my problem now is time. Had plenty of that up until the beginning of this year.

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

Re: New C# Method Request

Postby beefy » Thu Aug 10, 2017 7:43 pm

dezsoe wrote:Thinking over the whole thread, I'm sure that the easiest (and fastest) way would be to have a function like this: DoRFHAndGetParams(x, y, z, a, b, c, sx, sy, sz, sa, sb, sc, feed, rx, ry, ra), where UCCNC loads the parameters as it would be in the IMP window and returns a bool as a result of RFH (the given line number in field 866 is valid). The parameters x..c are the coordinates, sx..sc are the scale values, feed is feed, rx..ra are the rotation parameters.


Exactly Dezsoe,

I'd even be happy with with a much simpler function for now (no parameters), because the Initial Movement Preparation window tick boxes, etc remember the last entries, so it could be set up once and you're good to go.

Of course I wouldn't say no to the function with parameters :)

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

Re: New C# Method Request

Postby Robertspark » Fri Aug 11, 2017 1:14 pm

beefy wrote: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


I'm re-reading this original post again.....


[I may have misunderstood earlier (not the first and won't be the last time...)]

Basically you want to cut down on the number of manual steps?

What about changing the screen button "run from here" to a custom button code macro.

This one doesn't work ... but maybe someone has an idea of how to automate the enter keypress that does work.
It doesn't fail from an error, just it seems to wait for the manual enter keypress still

Code: Select all
exec.Callbutton(169);
exec.Wait(100);
//SendKeys.SendWait("~");
SendKeys.SendWait("{ENTER}");
exec.Wait(100);
exec.Callbutton(128);


https://msdn.microsoft.com/en-us/librar ... d(v=vs.110).aspx
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: New C# Method Request

Postby beefy » Fri Aug 11, 2017 10:40 pm

Hi Rob,

thanks for that bit of code, more learning to do (Sendkeys).

ha ha, yes you got it exactly. I'm trying to create a very user friendly system where one button does lots of stuff for the user.

The Run From Here button is the easy bit, there's a button code for that. But the Initial Movement Prep box is manual and a user needs to know how to do it. There's no UCCNC function to operate it. After a flameout, I'm wanting to simply scroll to the gcode line I want to do a dry run from, the press the "magic" button that does all sorts of magic for you.

I'll be straight up, one day I'm hoping to sell my own table here in Australia and I want it to have great plasma functionality. Whether I get there is a different story. I was cutting stainless a couple of years ago and the torch cut height was a QUARTER of a mm. I got LOTS of flameouts due to a minute amount of slag buildup on the nozzle and the cut recover feature I'm developing now would have been fantastic.

Anyway I'll figure out how to extract those X and Y co-ordinates from the gcode line, it's just a matter of time :twisted: If there's one thing I am (which ain't clever), I'm stubborn and will keep on Googling until I figure it out. I get a long way with monkey see, monkey do LOL.

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

Re: New C# Method Request

Postby Robertspark » Fri Aug 11, 2017 10:55 pm

I think the problem with SendKeys is focus.... which form has focus as although the RFH form pops up it "may" not have focus hence my rough "enter" keypress doesn't have focus as focus is still on the screenset where the macro (or button press) runs from.

Not figued out how you work out how you know the names of the forms to call that are active on a screen so that you could toggle between forms and select buttons and key presses accordingly (I guess using the TAB key press would work too...

Easiest solution would just be to have a checkbox or function to skip the button press though (Balazs has been quiet, presume most of Europe is on shut down with the summer holidays, not had a development release for a little while)
Robertspark
 
Posts: 1892
Joined: Sat Sep 03, 2016 4:27 pm

Re: New C# Method Request

Postby beefy » Sat Aug 12, 2017 10:42 am

Hey Rob and Dezsoe,

couldn't help myself, the stubborn side of me got the better of me.

This is my first attempt, just a basic console project in Visual Studio but it's only to prove the coding before I convert it to a macro or plugin. It seems to work good but I haven't got a clue if I've overlooked certain "what ifs". I was supposed to be studying for my truck driver test which is next week so I'll be offline until Thursday I'd say.

I'll also have to check this code works with NET 2.0 because I haven't even checked what version of NET Visual Studio defaults to, but it won't be NET 2.0

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XY_CO_ORDINATES_GRAB
{
    class Program
    {
        static void Main(string[] args)
        {
            string gcodeString = "N0170 G03 X129.3403 Y101.9826 I8.7831 J3.8751 F850.0";
            char[] gcodeBlockArray = gcodeString.ToCharArray();
            int blockLength = gcodeBlockArray.Length;           // No of elements in the array

            bool X_complete = false;                                // Set true when doing X co-ordinate done
            bool Y_complete = false;                                // Set true when doing Y co-ordinate done
            bool allDone = false;

            List<char> co_ordX = new List<char>();                  // List to hold X co-ord numerical characters
            List<char> co_ordY = new List<char>();                  // List to hold Y co-ord numerical characters

            char blockCharacter;
            int blockCharNo = 0;                                // Array index No for gcode block characters


            while (allDone == false)
            {
                blockCharacter = gcodeBlockArray[blockCharNo];
                blockCharNo++;

                if (((blockCharacter == 'X') || (blockCharacter == 'x')) && (X_complete == false))
                {
                    // Get X numerical characters
                    while (((gcodeBlockArray[blockCharNo] >= '0') && (gcodeBlockArray[blockCharNo] <= '9')) || (gcodeBlockArray[blockCharNo] == '.'))
                    {
                        co_ordX.Add(gcodeBlockArray[blockCharNo]);
                        blockCharNo++;
                    }

                    X_complete = true;
                }

                else if (((blockCharacter == 'Y') || (blockCharacter == 'y')) && (Y_complete == false))
                {
                    // Get Y numerical characters
                    while (((gcodeBlockArray[blockCharNo] >= '0') && (gcodeBlockArray[blockCharNo] <= '9')) || (gcodeBlockArray[blockCharNo] == '.'))
                    {
                        co_ordY.Add(gcodeBlockArray[blockCharNo]);
                        blockCharNo++;
                    }

                    Y_complete = true;
                }
               
                // Test for end of block or start of a comment
                else if ((blockCharNo >= (blockLength - 1)) || (blockCharacter == '('))
                {
                    // Messagebox.show ("Cannot find XY values in gcode block");
                    break;
                }

                if ((X_complete == true) && (Y_complete == true))
                {
                    allDone = true;
                }
            }

            String X_co_ord = new string(co_ordX.ToArray());
            String Y_co_ord = new string(co_ordY.ToArray());

            Console.WriteLine("X co-ordinate is " +X_co_ord);
            Console.WriteLine("Y co-ordinate is " +Y_co_ord);
        }
    }
}

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

Re: New C# Method Request

Postby cncdrive » Sat Aug 12, 2017 3:55 pm

Hi Keith,

Visual Studio defaults to it's own .NET framework version when you creating a project and that depends on the version of Visual Studio you using,
so basicly all Visual Studio defaults to the newest .NET framework, I mean what .NET framework version was the newest when that Visual Studio was released.

You can change the .NET framework version in the project properties.

Your code is sure for a newer .NET framework version, not the 2.0. I know because your includes contains the System.Linq which did not exist in the .NET 2.0 yet.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

PreviousNext

Return to Ask a question from support here

Who is online

Users browsing this forum: No registered users and 22 guests