Would some kind person write me a simple macro?

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

Would some kind person write me a simple macro?

Postby Greolt » Thu Sep 14, 2017 2:50 am

This is very basic and I should be able to do it easily.

However I find the best way for me to get started with the concept is to look at an existing macro and see how it is done.

The task is to control my router spindle (VFD) via modbus

The modbus master is set up and communicating with my Hitachi X200 VFD

I can do all of the needed control manually via the modbus master. By manually entering values in the "Variables Table" while the loop is running.

My assumption is that it now needs a macroloop to manipulate those variables when certain actions take place.

The macro needs to do the following.

1. When LED 50 goes active, write a "1" in register zero of the variables table. LED 50 is "SpindleCW"

2. When LED 50 goes inactive, write a zero in register zero of the variables table.

3. Read DRO 2451, divide the value by 6, and then write it in register one of the variables table. This is the speed setting for VFD

4. Read register 2 in the variables table , divide it by 125 and write the value to DRO ??? (DRO number not decided yet. will be a user assigned DRO)

Thanks in advance for any help.
Greolt
 
Posts: 239
Joined: Sun Sep 04, 2016 6:22 am

Re: Would some kind person write me a simple macro?

Postby Greolt » Thu Sep 14, 2017 4:02 am

Felt that I had to at least make an attempt.

Most likely it is all wrong and syntax all over the place.

Code: Select all
//check LED 50 , if it is active then set modbus register zero to one, else set it to zero

bool Spin = AS3.GetLED(50);
if Spin>0{
exec.SetModbusregister(0, 1)}
else{
exec.SetModbusregister(0, 0)}

 
// read field 2541, divide value by 6, write value to modbus register 1
// the value written to the modbus register should be in the range 0 - 4000

string Speed = AS3.Getfield(2451);
Speed = Speed/6;
exec.SetModbusregister(1, Speed);
 
// read modbus register 2, divide value by 125, write value to DRO 3000
// the value read from modbus register will be in the range 0 - 2000

string Amps;
exec.GetModbusregister(2, out Amps);
Amps = Amps/125;
AS3.Setfield(Amps, 3000);
Greolt
 
Posts: 239
Joined: Sun Sep 04, 2016 6:22 am

Re: Would some kind person write me a simple macro?

Postby dezsoe » Thu Sep 14, 2017 9:36 am

Here is your macro with some corrections:

Code: Select all
//check LED 50 , if it is active then set modbus register zero to one, else set it to zero

bool Spin = AS3.GetLED(50);
if (Spin)
  exec.SetModbusregister(0, 1);
else
  exec.SetModbusregister(0, 0);

 
// read field 2541, divide value by 6, write value to modbus register 1
// the value written to the modbus register should be in the range 0 - 4000

double Speed = AS3.Getfielddouble(2451);
Speed = Speed/6;
exec.SetModbusregister(1, (ushort)Convert.ToInt32(Speed));
 
// read modbus register 2, divide value by 125, write value to DRO 3000
// the value read from modbus register will be in the range 0 - 2000

ushort Amps;
if (exec.GetModbusregister(2, out Amps))
  AS3.Setfield(Amps / 125, 3000);
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: Would some kind person write me a simple macro?

Postby Greolt » Thu Sep 14, 2017 10:16 am

Thanks very much dezsoe.

I will try it out.
Greolt
 
Posts: 239
Joined: Sun Sep 04, 2016 6:22 am

Re: Would some kind person write me a simple macro?

Postby A_Camera » Thu Sep 14, 2017 1:18 pm

I did not write a macro for you according to your specifications, but I share what fits my VFD. This is a stripped down version of what I actually use, but it should be pretty easy for you to work with. The parts which I removed handle some VFD parameters, like spindle speed reached and some other monitoring functions. The basic principle is simple, check CW and CCW LEDs and send the matching command to the VFD, as well as the frequency matching the desired spindle RPM, compensated for the SS override and checked for maximum RPM. I allow any RPM between zero to maximum RPM.

Code: Select all
// ----------------------------------------------------------------------------------------------------
//
//    M20305 Seting the spindle speed, runing CW/CCW and reading some VFD and spindle parameters.
//   This is a Modbus interface macro and is running in a macro loop.
//
// When this macro is called it will check the Set Spindle Speed and the Speindle Speed Override DRO
// and will calculate the matching frequency. This is set in Modbus register which is sent to the VFD.
//
// After this step it will check the state of RUN CW/CCW LEDs and will set the necessary VFD commands.
//
// ----------------------------------------------------------------------------------------------------
//
//   Constants
//
ushort RunSpindleCW       = 129;       // Rexroth EFC5610 RUN CW command
ushort RunSpindleCCW       = 133;       // Rexroth EFC5610 RUN CCW command
ushort StopSpindleRun       = 136;      // Rexroth EFC5610 STOP command

ushort SSetDRO          = 869;
ushort SactDRO          = 870;
ushort SSOverriddenDRO      = 2451;
ushort MaxSpindleSpeedDRO   = 178;
double MaximumRPM       = 24000;

ushort SpindleRunReg      = 0;      // Displayed UCCNC Modbus register list
ushort VFDFrequencyReg       = 1;      

//
//   Variables
//
string SspeedOverride;
int IndexOfPercentSign;
string SSpeedOverride;

double SSpeedHz;

//
//   Program starts here
//
//-------------- Set spindle speed value firtst ---------------------------------------------------------------
//
//
   MaximumRPM = AS3.Getfielddouble(MaxSpindleSpeedDRO);
   SSpeedHz = ( AS3.Getfielddouble(SSOverriddenDRO));
   if (SSpeedHz > MaximumRPM)
   {
      SSpeedHz = MaximumRPM;   // Force maximum RPM to prevent exception
   }
//
// Calculate the matching RPM frequency and send the value to Modbus register.
//
   exec.SetModbusregister(VFDFrequencyReg, (ushort) Convert.ToUInt16(SSpeedHz / 0.6)); 
//
//-------------- Send start/stop command for the spindle --------------------------------------------------------
//
//   Check the CW and CCW LEDs and convert the state to spindle control commands.
//   The command is set in the Modbus register which is sent to VFD using the UCCNC Modbus internal handler.
//
//   Check CW and CCW LEDs, start or stop the spindle based on LED states.
//   After exiting this macro the Modbus register is set up for CW, CCW or Stop
//
   if ( AS3.GetLED(50) == true )  // If the RUN CW LED is active
   {
        exec.SetModbusregister(SpindleRunReg, RunSpindleCW);   //Turn spindle on in CW rotation if LED is on
   }
   else

   if ( AS3.GetLED(51) == true )  // If the RUN CCW LED is active
   {
          exec.SetModbusregister(SpindleRunReg, RunSpindleCCW);   //Turn spindle on in CCW rotation if LED is on
   }
   else // CW and CCW LEDs are off, send turn spindle OFF commnad
   {
          exec.SetModbusregister(SpindleRunReg, StopSpindleRun);    // Send Rexroth EFC5610 STOP command to VFD
   }

//
// ------------------------------------------------------------------------------------------------------
//
//
//------------------------------------------------------------------------------------------------------
//
//   End of program


Of course, Modbus master plugin must be enabled, configured and run as well.
A_Camera
 
Posts: 639
Joined: Tue Sep 20, 2016 11:37 am

Re: Would some kind person write me a simple macro?

Postby Greolt » Thu Sep 14, 2017 9:25 pm

dezsoe

I have your corrected macro running. Thanks again.

A_camera

Thanks for your example. I will spend some time altering it to my needs. It will help me learn a little.

On my Milling Machine I occasionally use spindle reverse but this is for a router and I never use reverse.

What number range is recommended for user DROs and user macros?

Thanks very much both for taking the time.
Greolt
 
Posts: 239
Joined: Sun Sep 04, 2016 6:22 am

Re: Would some kind person write me a simple macro?

Postby ger21 » Thu Sep 14, 2017 9:34 pm

Macros need to be between 20000 and 20999.
I use the same range for everything.
Gerry
UCCNC 2022 Screenset - http://www.thecncwoodworker.com/2022.html
ger21
 
Posts: 2714
Joined: Sat Sep 03, 2016 2:17 am

Re: Would some kind person write me a simple macro?

Postby Greolt » Thu Sep 14, 2017 11:23 pm

Thanks ger21

Why so high numbers?

"Everything"......does that mean DROs, Labels, Macros, Textfields, etc.
Greolt
 
Posts: 239
Joined: Sun Sep 04, 2016 6:22 am

Re: Would some kind person write me a simple macro?

Postby cncdrive » Thu Sep 14, 2017 11:31 pm

You can use any positive numbers, except the built in functions, like M10, M11 etc.
The range 20000 to 21999 is the range for macro call button codes. Those numbers can be used to call macros with button presses.
When you use that range and place the same buttonnumber button on the screen then pressing that button will call the same number of macro, but it has to be in the mentioned range.
cncdrive
Site Admin
 
Posts: 4887
Joined: Tue Aug 12, 2014 11:17 pm

Re: Would some kind person write me a simple macro?

Postby Greolt » Thu Sep 14, 2017 11:41 pm

OK got that

Thanks
Greolt
 
Posts: 239
Joined: Sun Sep 04, 2016 6:22 am

Next

Return to Macros

Who is online

Users browsing this forum: No registered users and 5 guests