This document describes the UCCNC software macro function calls capability.
The UCCNC software can have different profiles. Each profile can have different machine setup/settings and therefor different macros.
The macro files are located in the installation folder of the UCCNC software /Profile/Macro_name of profile , where the „name of profile” is the profile name the software is loaded with.
The macros are plain text files with a .txt extension and with the file names start with an „M” and after the number of the macro. For example M3.txt.
The user can make and edit new macros simply by creating a new macro file and adding it to the macro folder of the software.
The macros as they are plain text files are editable with the built in notepad.exe in Windows.
By default the macros' programming language is C# (C-sharp). The language is not described in this documentation, but it is very similar to C language and for those who are yet not familiar with C# programming we recommend to study the following Wiki page: http://en.wikipedia.org/wiki/C_Sharp_syntax
There is an option to change any macros or macroloops from C# language to VB (VisualBasic) language compilation with writting the #VB directive into the very first line of the macro.
If the first line of the macro code contains the #VB directive then the software uses the VisualBasic compiler to compile the macro instead of the C# compiler.
When the Visual Badic language is selected in a macro then the whole language have to be written in VB language following the VB syntax.
The UCCNC specific functions are the same for the C# and the VB compilation, but this manual describes all functions in C# syntax only.
The macros are compiled and executed in runtime, so they can be changed any time using a text editor like notepad.
In case the macro contains a syntax error and cannot be compiled the UCCNC software will show a script error notice in the status box.
Also it is possible to create a runtime error, for example with dividing by zero in the macro code, in this case the UCCNC software will also show an error notice in the status box.
We recommend that when writting macros first test them without the machine tool connected for safety reasons.
All macros are compiled into the Macro class. The Macro class has visibility to the following Namespaces and objects:
"exec" is the executer, this is the object in the UCCNC software which makes all motion execution, I/O manipulations etc.
"AS3" is the main screen, this is the object on the screen where all fields, buttons, LEDs are placed, the value of these can be read from the AS3 object.
"AS3jog" is the jog panel object on the screen, all fields, buttons, LEDs values on the jogpanel can be read from the AS3jog object.
The System, System.Windows.Forms, System.Drawing, System.Threading, System.Collections.Generic namespaces.
The macro text typed into the macro file is inside a function of a class and therefor defining other functions and global variables directly inside the macro is not possible.
Defining global variables and functions is possible only at the end of the macro text file with writting the #Events text into the macro, this text will let the UCCNC know that the remaining text of the macro has to be compiled outside of the function, but still inside the macro class.
The following example shows a simple macro which creates a Windows Form and adding a button to it and assigning an event handler to the button's click event.
The example also declares a function which is then called from inside the macro.
Button MyButton = new Button();
MyButton.Size = new System.Drawing.Size(80, 40);
MyButton.Location = new System.Drawing.Point(110, 130);
MyButton.Text = "Press me";
MyButton.Click += new EventHandler(MyButton_Click);
MyForm = new Form();
MyForm.Size = new System.Drawing.Size(300, 300);
MyForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
MyForm.Controls.Add(MyButton);
MyForm.ShowDialog();
MyFunction();
#Events
Form MyForm; //This is a global variable, a Windows Form
void MyButton_Click(object sender, EventArgs e)
{
MessageBox.Show("Mybutton was clicked!");
MyForm.Close();
}
void MyFunction()
{
exec.Code("G0 X10");
}
1. The following list contains the Executer object's functions which are callable from any macros.
Function: bool IsMoving(void)
Description: The function returns true if the software is executing a motion or a function. It returns false if the software is in idle.
Example: while(exec.IsMoving()){}
Function: bool IsMovingTHC(void)
Description: The function is the same as the IsMoving except that this function checks the Idle bit only and does not checks the motion buffer count. This function can be used for example to detect when the motion stopped when the THC control is enabled and because the controller is waiting for the ArcOK signal to go on. In this situation the software may still fill the motion buffer if there are more motion commands in the g-code buffer, but the idle bit will be inactive and because this function depends on the idle bit only, it will work in this scenario.
Example: while(exec.IsMovingTHC()){}
Function: double Get[XYZABC]machpos(void)
Description: The function returns the actual machine position of an axis, this is the abosulte position excluding any offsets.
Example: double Xmachposvariable = exec.GetXmachpos();
Notes: [XYZABC] means a character of X, Y, Z, A, B or C
Function: double Get[XYZABC]pos(void)
Description: The function returns the actual position of an axis including the selected offset and the tool offset.
Example: double Xposvariable = exec.GetXpos();
Notes: [XYZABC] means a character of X, Y, Z, A, B or C
Function: double Get[XYZABC]scale(void)
Description: The function returns the actual G51 scale value of an axis.
Example: double Xposvariable = exec.GetXscale();
Notes: [XYZABC] means a character of X, Y, Z, A, B or C
Function: void StopWithDeccel(void)
Description: The function stops all axis using the set decceleration profile.
Example: exec.StopWithDeccel();
Function: void Stop(void)
Description: The function causing an instant stop on all axis.
Example: exec.Stop();
Function: void Wait(int milliseconds)
Description: The function causing the loop to stop for the set amount of time in milliseconds.
Example: exec.Wait(1000);
Function: void Setofflinemode(bool setoffline)
Description: The functions sets the machine to offline mode or to online mode. In offline mode the outputs of the UC100 gets disconnected from the pins, so the machine can't move, however the functions like movements seems like executing.
Example: exec.Setofflinemode(true);
Function: int Getcurrenttool(void)
Description: The function returns the actually selected tool number. It returns zero if no tool was yet selected.
Example: int Currenttoolvariable = exec.Getcurrenttool();
Function: void Setcurrenttool(int toolnumber)
Description: This function sets the selected tool number in the UCCNC software. Useful when using automatic tool changer. We recommend to set the new tool number at the end of the toolchange macro.
Example: exec.Setcurrenttool(2);
Function: int Getnewtool(void)
Description: This function reads the tool number next to the M6 code, forexample if a code M6 T2 was executed then this function returns the number 2.
Example: int newtoolnumber = exec.Getnewtool();
Function: bool Ismacrostopped(void)
Description: This function checks if a stop was pressed by the user on the UCCNC software GUI.
Example: if(exec.Ismacrostopped){return;}
Function: void Setoutpin(int portnumber, int pinnumber)
Description: This functions sets the selected output pin to high level.
Note: If a pin is called which is configured for a hardware function, for example to act as a step or direction pin will override this function.
Example: exec.Setoutpin(1, 2);
Function: void Clroutpin(int portnumber, int pinnumber)
Description: This functions sets the selected output pin to low level.
Note: If a pin is called which is configured for a hardware function, for example to act as a step or direction pin will override this function.
Example: exec.Clroutpin(1, 2);
Function: void Code(string code)
Description: This function makes it possible to execute one line of G-code from inside a macro. The G-code is sent as a string in the parameter of the function and is interpreted in execution time.
Example: exec.Code(„G0 X10 Y20 Z0”);
Function: void Codelist(List<string> codelist)
Description: This function is similar to the Code function, but it executes not only a single, but multiply lines of g-codes from inside a macro. The g-code lines are sent as a string List in the parameter of the function and are interpreted in execution time. This function differs from calling multiply Code functions, because the Codelist function loads all the code lines the same time into the motion control API, so the lines are optimised by the Constant velocity interpolator while the multiply Code function calls are executed one-by-one separately.
Example:
List<string> codelist = new List<string>();
//Create a new List of strings.
codelist.Add("G0 Z-25"); //Add g-code lines to the List.
codelist.Add("M3");
codelist.Add("G1 X0 Y0 F500");
codelist.Add("#5 = 12.23");
codelist.Add("G1 X#5 Y2");
exec.Codelist(codelist); //Execute the List of g-codes.
Function: void Callbutton(int buttonnumber)
Description: This function calls an internal function of the UCCNC software. The buttonnumber represents an internal function number of the UCCNC software. The buttonnumber list is described in a separate documentation file.
Example: exec.Callbutton(100);
Function: string Readkey(string section, string key, string defaultvalue)
Description: This function reads a key value from the profile (.pro) file. The section and the key parameter defines which key to read from the profile file and the function returns with the defaultvalue parameter if the key does not exist in the profile file. The function returns a string type.
Example: string mykeyvalue = exec.Readkey("axessettingscontrolX", "Axisenabled", "False");
Function: void Writekey(string section, string key, string value)
Description: This function writes a key value into the profile (.pro) file. The section, and the key parameter defines which key to write to the profile file. The value parameter is the new value to write. If the key already exists in the profile file then the function overwrites the key with the new value. If the key does not exist then the function creates the key in the file with the set value.
Example: exec.Writekey("axessettingscontrolX", "Axisenabled", "False");
Function: void Pluginshowup(string Pluginfilename)
Description: This function calls a Plugin file's Showup_event(); function. This is useful when the plugin should do something on a button press event, forexample when it should show it's GUI interface.
Example: exec.Pluginshowup("Plugintest.dll");
Function: void Swapaxis(int axis1, int axis2)
Description: This function swaps the step and direction pin numbers and pin negate settings of one axis with another axis. The axis swapping may be done any times, the software saves the swapping sequences.
The axis number parameter can be in the range of 0 to 5 for the axis X to C axis in order.
Be careful with saving the axis settings when the swapaxis function is in use. If the settings are saved without pressing the Apply settings button first then the swapped pins will be saved for the axis!
Example: exec.Swapaxis(0,1); //Swaps the X-axis with Y-axis.
Function: void Resetswapaxis()
Description: This function resets the swap axis sequence with rolling back all the previously called axis swapping sequences.
Example: exec.Resetswapaxis();
Function: void Slaveaxis(int masteraxis, int slaveaxis)
Description: This function slaves an axis to an axis. The masteraxis can be axis X, Y and Z axis (numbers 0, 1, 2 respectively) and the slave axis can be A, B and C axis (3, 4, 5 respectively). To remove the slave from the master axis use value 0 on the slaveaxis parameter.
Be careful with saving the axis settings when the slaveaxis function is in use. If the settings are saved without pressing the Apply settings button first then the slave parameter will be saved for the master axis!
Example: exec.Slaveaxis(0,3); //Makes A-axis slaving the X-axis.
Function: void Getanaloginput(int channel)
Description: This function returns the actual value of an analog input channel signal. The parameter defines the channel to be read. If the device has no analog input channel with the channel number called then the return value will be -1. The valid return range for the function is 0-65535.
Example: int analogin1 = exec.Getanaloginput(1);
Function: void Getanalogoutput(int channel)
Description: This function returns the actual value of an analog output channe signal. The parameter defines the channel to be read. If the device has no analog output channel with the channel number called then the return value will be -1. The valid return range for the function is 0-65535.
Example: int analogout1 = exec.Getanalogoutput(1);
Function: double Getvar(int varnum)
Description: This function returns the value of an internal variable.
Example: double myvar = exec.Getvar(1);
Function: void Setvar(double value, int varnum)
Description: This function sets the value of an internal variable.
Example: exec.Setvar(1.234, 1);
Function: string TextQuestion(string Questiontext)
Description: This function shows a Question form waiting for a string as the answer. The text of the question shown on the Form is the parameter.
Example: string val = exec.TextQuestion("Stop code execution?");
Function: double Question(string Questiontext)
Description: This function shows a Question form waiting for a double value as the answer. The text of the question shown on the Form is the parameter.
Example: double val = exec.Question("What X position to move?");
Function: void Loadfile(string filename)
Description: This function loads a g-code file. The parameter is a string which is the full path of the file to be loaded.
Example: exec.Loadfile("C:/UCCNC/Example_codes/holders.tap");
Function: bool IsLoading(void)
Description: The function returns true if the software is loading a g-code file and returns false if no file is being loaded.
Example: while(exec.IsLoading()){}
Function: int Showplugin(string pluginfilename)
Description: This function calls the Showup event of a UCCNC plugin installed in the /Plugins directory. The parameter is a string which is the name of the plugin file including the .dll extension.
The possible return values are the following:
0: The plugin started without problems.
1: The plugin is not enabled and can't run.
2: The plugin was not found, there is no plugin installed with this filename.
3.: The plugin does not have the Showup event implemented.
Example: int returnval = exec.Showplugin("Diagnostics.dll");
Function: int Configplugin(string pluginfilename)
Description: This function calls the Config event of a UCCNC plugin installed in the /Plugins directory. The parameter is a string which is the name of the plugin file including the .dll extension.
The possible return values are the following:
0: The plugin started without problems.
1: The plugin is not enabled and can't run.
2: The plugin was not found, there is no plugin installed with this filename.
3.: The plugin does not have the Config event implemented.
Example: int returnval = exec.Configplugin("Diagnostics.dll");
Function: object Informplugin(string Pluginfilename, object Message)
Description: This function sends data to one plugin. The Pluginfilename parameter defines the name of the plugin to send the message to and the parameter is an object and the return value is also an object.
Example:
string teststr = "Hello Plugintest.dll...";
object Returnvalue = exec.Informplugin("Plugintest.dll", (object)teststr);
if (Returnvalue is string)
{
string str = Returnvalue as string;
MessageBox.Show(exec.mainform, "Return message was: " + str);
}
Function: void Informplugins(object Message)
Description: This function sends data to all plugins. The parameter is an object and there is no return value.
Example:
string teststr = "Hello to all plugins...";
exec.Informplugins((object)teststr);
Function: void RemoveRunfromhere()
Description: This function removes the Initial movement Window of the Run from here function to be shown condition after the Run from here button was pressed or the button code was previously called, so the Initial movement Window will not be shown and inital movement will not be made. The function can be used when a plugin or macro changes the g-code line number to be executed and with calling the Run from here button code and if the plugin or macro don't need the initial movement preparation.
Example: exec.RemoveRunfromhere();
Function: void GetRotate(out double Rx, out double Ry, out double Angle)
Description: This function returns the current G68 rotation point and rotation angle.
Example: double Rx, Ry, Angle;
GetRotate(out Rx, out Ry, out Angle);
Function: string Getgcodelinetext(int rownumber)
Description: This function returns one row of text from the loaded g-code file pointed by the rownumber parameter.
Example: string linetext = exec.Getgcodelinetext(0); //Reads the first row of the g-code file.
Function: string Getcurrgcodelinetext(void)
Description: This function returns one row of text from the loaded g-code file pointed by the current line DRO pointer.
Example: string linetext = exec.Getcurrgcodelinetext();
Function: int Getcurrentgcodelinenumber(void)
Description: This function returns the line number of the g-code file pointed by the current line DRO pointer.
Example: int linenumber = exec.Getcurrgcodelinetext();
Function: int Ismacrorunning(int macronumber)
Description: The function returns the number of instances a text-macro is currently running. The function can be used to check if a macro is already running or not. If for example the macro is only allowed to run in one instance then the macro should contain a code to return without the execution of the code in another instance. The function is useful for example when calling text macros via button codes (M20000 to M21999) and when it is unwanted to run the macro in more instances if the user clicks the screen button more than one time while the macro is still running. The valid range for the macronumber parameter is 0 to 99999. The function returns -1 if the parameter is out of range. Note, that the macroloop runs are excluded from this function, those macro instances will not count in the returned value of the function.
Example: if(exec.Ismacrorunning(20000)>1){ return; } //The return value 1 indicates that only this one macro instance is running. If the number is greater means that this is a second or third etc. instance of the macro to be run.
//Do macro functions here...
Function: Plugininterface.Datatypes.Tooltablestruct[] Gettooltabledata(void)
Description: The function returns an array of structures with all tools' tool table parameter values in the detailed tooltable.
Example: Plugininterface.Datatypes.Tooltablestruct[] Tdata = exec.Gettooltabledata();
MessageBox.Show(Tdata[1].Description); //Shows the Description parameter value of Tool#1
Function: List<Plugininterface.Datatypes.Layerdatastruct> Getlayerslist(bool isAS3)
Description: The function returns a List of structures with all screen layers' parameters. If the AS3 parameter is true then the main screen's layers parameters are return otherwise the jog screen layers parameters are returned.
Example: List<Plugininterface.Datatypes.Layerdatastruct> Ldata = exec.Getlayerslist(true);
MessageBox.Show("" + Ldata[1].Isactive); //Shows the Isactive property of the first layer in the List.
2. The following list contains the AS3 and AS3jog object's functions which are callable from any macros.
Function: string Getfield(int fieldnumber)
Description: This function reads the value of a field object and returns the value in a string.
Example: string fieldvalue = AS3.Getfield(100);
Function: void Setfield(double value, int fieldnumber)
Description: This function sets the value of a field object. If the field exists on the screen on any tab pages then it will update it's value. If it does not exist then this function will do nothing.
Note that there are fields like the position DROs and feedrate, spindle speed etc. DROs which are updated in the UCCNC from internal variables in loops, these fields cannot be updated permamently using this method,
because the internal functions will rewrite these fields with the internal variable values. Call the Validatefield after the Setfield function to change the value of these kind of fields.
Example: AS3.Setfield(15.23, 100);
Function: void Validatefield(int fieldnumber)
Description: This function validates the value of a field object. If the field exists on the screen on any tab pages then the function executes. If it does not exist then this function will do nothing.
When this function is called then the field value changed event is called inside the UCCNC core and the software will make the actions nessessary to validate the actual value of the field.
Example: AS3.Setfield(12.34, 97); //Sets the value of the X current coordinate field to 12.34
AS3.Validatefield(97); //Validates the 12.34 valuefor the X current coordinate field with writting the offset coordinates as nessessary.
Function: void Setfieldtext(string value, int fieldnumber)
Description: This function sets the value of a field. If the field exists on the screen on any tab pages then it will update it's value. If it does not exist then this function will do nothing.
Note that there are fields like the position DROs and feedrate, spindle speed etc. DROs which are updated in the UCCNC from internal variables in loops, these fields cannot be updated permamently using this method,
because the internal functions will rewrite these fields with the internal variable values. Call the Validatefield after the Setfield function to change the value of these kind of fields.
Example: AS3.Setfieldtext("This is my field", 100);
Function: bool GetLED(int LEDnumber)
Description: This function returns the logic state of a LED screen object. If the LED is on then the function returns "true" or if the LED is off then this function returns "false". If the LED does not exist on the screen then the return value is "false".
Example: bool stateofmyLED = AS3.GetLED(18);
Function: void SetLED(bool state, int LEDnumber)
Description: This function sets the logic state of a LED screen object. If the LED does not exist on the screen then this funtion will do nothing.
Note: There are LEDs which values are refreshed from internal loops of the UCCNC, these LEDs cannot be set with this function, because the value will update from the UCCNC's internal loop. For example the Idle and run LEDs cannot be set with this function. Basicly this function is to set user LEDs which are not used by the UCCNC core.
Example: AS3.SetLED(true, 1000);
Function: bool Getbutton(int buttonumber)
Description: This function returns true if the button is being pressed on the screen or with an input trigger and returns false if the button is released.
Example: while(!AS3.Getbutton(128)); //Waits for the cycle start button press on the main screen.
Function: bool Getbuttonstate(int buttonumber)
Description: This function works with toggle type buttons and returns true if the button is in it's on state and returns false when the button is in it's off state. The function always returns false for non-toggle type buttons.
Example: bool buttonstate = AS3.Getbuttonstate(114); //Checks if the M3 spindle on/off button is active.
Function: void Switchbutton(bool Ison, int Buttonnumber)
Description: This function works with toggle type buttons and switches the button to on/off states. If the Ison parameter is true switches the button to the on state and false switches to the off state. The function can be used for example in buttons' macros to change the state of the button toggling it's visual state.
Example: AS3.Switchbutton(true, 128);
Function: string Getcomboboxselection(int labelnumber)
Description: This function returns the selected text string of a combobox screen item.
Example: string selectedtext = AS3.Getcomboboxselection(1);
Function: List<string> Getlist(int labelnumber)
Description: This function returns all items of a screen list. The return type is a list of strings.
Example: List<string> mylist = AS3.Getlist(2);
Function: List<string> GetMDIhistory()
Description: This function returns all items previously typed into the MDI control.
Example: List<string> mylist = AS3.GetMDIhistory();
Function: void ClearMDIhistory()
Description: This function clears the MDI history list.
Example: AS3.ClearMDIhistory();
Function: void Sendimageview(Image
img, int Labelnumber)
Description: This functions sends a picture image to an imageviewer.
Example: //This example code sends and rotates a picture image around it's center and displays it in an imageview control
Image img1 = Image.FromFile(Application.StartupPath +
"/a.png");
for (int i = 0; i < 360; i++)
{
Image imgdraw = (Image)img1.Clone();
using (Graphics g = Graphics.FromImage(imgdraw))
{
// Set the rotation point to the center in the matrix
g.TranslateTransform(imgdraw.Width / 2, imgdraw.Height / 2);
// Rotate
g.RotateTransform(i);
// Restore rotation point in the matrix
g.TranslateTransform(-imgdraw.Width / 2, -imgdraw.Height /
2);
// Draw the image on the bitmap
g.DrawImage(imgdraw, new Point(0, 0));
}
AS3.Sendimageview(imgdraw, 1);
imgdraw.Dispose();
Thread.Sleep(30);
if(exec.Ismacrostopped())
{
return;
}
}