modbus maître

Post anything you want to discuss with others about the software.

modbus maître

Postby andyjack38 » Tue Feb 23, 2021 5:13 pm

hello everyone, using uccnc with modbus master I allready have a connection done , can I by a click on a button (ex: button 114) activate a function that would start the VFD if so plz show me*
andyjack38
 
Posts: 30
Joined: Thu Mar 12, 2020 2:27 am

Re: modbus maître

Postby A_Camera » Wed Feb 24, 2021 4:44 pm

You must write a macro, call it m(and a large number).txt and run it in macro loop. My macro is called M20304.txt and I include it here, but you most probably can't just use it as it is, it must be changed to your VFD parameters and your type of use. My macro is quite a bit more than just start/stop, so unless you are familiar with programming in c++ you may have some issues understanding it, but good luck, if you want to use it, change it to your needs. Unfortunately, I don't have time to show every step or assist you deeper. Please read the Modbus manual and I suggest you start with something very simple after you have verified that your VFD really works with the Modbus plugin of UCCNC.

Code: Select all
// ----------------------------------------------------------------------------------------------------
//
//    M20304 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.
//
// Last it will read some VFD parameters and display in UCCNC.
//
// ----------------------------------------------------------------------------------------------------
//
//   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;

int OutputVoltage      = 20010;   // VFD and spindle monitoring parameter field numbers
int OutputCurrent      = 20011;
int OutputPower         = 20012;
int DCBusVoltage      = 20013;
int OutputTorque      = 20014;
int PowerModuleTemp      = 20015;
int ActualSpeed         = 20016;
int SpindleTemp         = 20017;
int SpeedArrival      = 800;

ushort OutputVoltageDRO      = 20010;
ushort OutputCurrentDRO      = 20011;
ushort OutputPowerDRO      = 20012;
ushort DCBusVoltageDRO      = 20013;
ushort OutputTorqueDRO      = 20014;
ushort PowerModuleTempDRO   = 20015;
ushort ActualSpeedDRO      = 20016;
ushort SpindleTempDRO      = 20017;
ushort SpeedArrivalLED      = 800;

ushort SpindleRunReg      = 0;      // Dispayed UCCNC Modbus register list
ushort VFDFrequencyReg       = 1;      
ushort ActualSpeedReg      = 11;
ushort OutputVoltageReg      = 20;
ushort OutputCurrentReg      = 10;
ushort OutputPowerReg      = 22;
ushort DCBusVoltageReg      = 23;
ushort OutputTorqueReg      = 24;
ushort PowerModuleTempReg    = 30;
ushort SpeedArrivalReg      = 40;


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

double Current;
double Power_kW;
double Torque;
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
   }

// ----------------------------------------------------------------------------------------------------
//
// Reading the VFD parameters via Modbus
//
// ----------------------------------------------------------------------------------------------------
//
//
// Get the parameters from the VFD and output to display
//

   exec.GetModbusregister(OutputVoltageReg, out OutputVoltageDRO);
   AS3.Setfield(OutputVoltageDRO, OutputVoltage);

   exec.GetModbusregister(OutputCurrentReg, out OutputCurrentDRO);
   Current = Convert.ToDouble(OutputCurrentDRO * 0.01);
   AS3.Setfield(Current, OutputCurrent);

   exec.GetModbusregister(OutputPowerReg, out OutputPowerDRO);
   Power_kW = Convert.ToDouble(OutputPowerDRO * 0.1);
   AS3.Setfield(Power_kW, OutputPower);

   exec.GetModbusregister(DCBusVoltageReg, out DCBusVoltageDRO);
   AS3.Setfield(DCBusVoltageDRO, DCBusVoltage);

   exec.GetModbusregister(OutputTorqueReg, out OutputTorqueDRO);
   Torque = Convert.ToDouble(OutputTorqueDRO) * 0.1;
   AS3.Setfield(Torque, OutputTorque);

   exec.GetModbusregister(PowerModuleTempReg, out PowerModuleTempDRO);
   AS3.Setfield(PowerModuleTempDRO, PowerModuleTemp);
   exec.GetModbusregister(ActualSpeedReg, out ActualSpeedDRO);
   AS3.Setfield(ActualSpeedDRO, ActualSpeed);
   AS3.Setfield(ActualSpeedDRO, SactDRO);

   exec.GetModbusregister(PowerModuleTempReg, out SpindleTempDRO);
   AS3.Setfield(SpindleTempDRO, SpindleTemp);            // Temorarily set the power module temp here

   exec.GetModbusregister(SpeedArrivalReg, out SpeedArrivalLED);
   
   if (SpeedArrivalLED == 1)
   {
      AS3.SetLED(true, SpeedArrival);
   }   
   else
   {
      AS3.SetLED(false, SpeedArrival);
   
   }

   
   if (AS3.Getbuttonstate(144) == true)   //Check if the Reset button is active.
   {
      exec.Clroutpin(3, 17);      // Turn off the fan
      AS3.SetLED(false, 801);      // Turn off the LED
   }   


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


Good luck, I hope it helps you out somehow.
A_Camera
 
Posts: 639
Joined: Tue Sep 20, 2016 11:37 am

Re: modbus maître

Postby Ruslan » Fri Mar 22, 2024 6:11 am

A-camera, why did you used variables for declaring constants and not used #define operator?
Ruslan
 
Posts: 28
Joined: Wed Jan 25, 2023 11:05 am


Return to General discussion about the UCCNC software

Who is online

Users browsing this forum: Google [Bot] and 11 guests